Last active
September 18, 2015 14:41
-
-
Save fgabolde/f223f51fa260e74c7cac to your computer and use it in GitHub Desktop.
Blobs containing NUL bytes are truncated when written to ZooKeeper nodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use 5.012; | |
use Carp; | |
use autodie; | |
use utf8; | |
use Devel::Peek; | |
use ZooKeeper; | |
use Sereal::Encoder; | |
use Sereal::Decoder; | |
use Test::More; | |
my $encoder = Sereal::Encoder->new({ snappy => 1 }); | |
my $decoder = Sereal::Decoder->new({ snappy => 1 }); | |
my $object = { foo => 'bar', | |
baz => 0, | |
quux => { | |
a => 8998, | |
b => 93890 } }; | |
my $blob = $encoder->encode($object); | |
is_deeply($decoder->decode($blob), $object, | |
q{... can roundtrip with Sereal encoding/decoding}); | |
diag('Before being written: '); | |
Dump($blob); | |
my $zk = ZooKeeper->new(hosts => 'localhost:2181/zksereal'); | |
eval { $zk->create('/') }; # ensure the vroot node exists | |
eval { $zk->delete('/sereal') }; | |
$zk->create('/sereal', value => $blob); | |
my $data = $zk->get('/sereal'); | |
diag('After being written: '); | |
Dump($data); | |
# this actually dies because $data is not valid Sereal | |
is_deeply($decoder->decode($data), $object, | |
q{... can roundtrip sereal -> ZooKeeper -> sereal }); | |
done_testing; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[zk: localhost:2181(CONNECTED) 5] get /zksereal/sereal | |
=�rl | |
cZxid = 0xe9e92b | |
ctime = Fri Sep 18 16:34:27 CEST 2015 | |
mZxid = 0xe9e92b | |
mtime = Fri Sep 18 16:34:27 CEST 2015 | |
pZxid = 0xe9e92b | |
cversion = 0 | |
dataVersion = 0 | |
aclVersion = 0 | |
ephemeralOwner = 0x0 | |
dataLength = 5 | |
numChildren = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment