Ceph-Rados-Striper
view release on metacpan or search on metacpan
CODE:
buf = (const char *)SvPV(data, len);
err = rados_striper_append(striper, soid, buf, len);
if (err < 0)
croak("cannot append to striped object '%s': %s", soid, strerror(-err));
RETVAL = err == 0;
OUTPUT:
RETVAL
void
_stat(striper, soid)
rados_striper_t striper
const char * soid
PREINIT:
size_t psize;
time_t pmtime;
int err;
PPCODE:
err = rados_striper_stat(striper, soid, &psize, &pmtime);
if (err < 0)
croak("cannot stat object '%s': %s", soid, strerror(-err));
XPUSHs(sv_2mortal(newSVuv(psize)));
XPUSHs(sv_2mortal(newSVuv(pmtime)));
SV *
_read(striper, soid, len, off = 0)
rados_striper_t striper
const char * soid
size_t len
uint64_t psize;
time_t pmtime;
int err;
INIT:
PerlIO * io = IoOFP(sv_2io(fh));
int chk_sz = 1024 * 1024;
Newx(buf, chk_sz, char);
CODE:
if (0 == len) {
// stat and determine read length
err = rados_striper_stat(striper, soid, &psize, &pmtime);
if (err < 0)
croak("cannot stat object '%s': %s", soid, strerror(-err));
len = psize-off;
}
if (debug)
printf("preparing to write from %s to FH, %" PRIu64 " bytes\n", soid, psize);
for (bufpos=off; bufpos<len+off; bufpos+=chk_sz) {
// logic is 'will bufpos move past ien+off next cycle'
buflen = len+off < bufpos+chk_sz ? len % chk_sz : chk_sz;
if (debug)
lib/Ceph/Rados/Striper.pm view on Meta::CPAN
}
sub read_handle_perl {
my ($self, $soid, $handle, $len, $off) = @_;
my $is_filehandle = openhandle($handle);
my $is_writable_object = blessed($handle) and $handle->can('write');
Carp::confess "Called with neither an open filehandle equivalent nor an object with a \`write\` method"
unless $is_filehandle or $is_writable_object;
$off //= 0;
if (!$len) {
($len, undef) = $self->_stat($soid);
}
my $count = 0;
#
for (my $pos = $off; $pos <= $len+$off; $pos += $CHUNK_SIZE) {
my $chunk;
if ($pos + $CHUNK_SIZE > $len) {
$chunk = $len % $CHUNK_SIZE;
} else {
$chunk = $CHUNK_SIZE;
}
lib/Ceph/Rados/Striper.pm view on Meta::CPAN
$self->_read_to_fh($soid, $handle, $len||0, $off||0);
} else {
Carp::confess "Called with neither an open filehandle equivalent nor an object with a \`write\` method";
}
}
sub read {
my ($self, $soid, $len, $off) = @_;
# if undefined is passed as len, we stat the obj first to get the correct len
if (!defined($len)) {
($len, undef) = $self->stat($soid);
}
$off ||= 0;
$self->_read($soid, $len, $off);
}
sub stat {
my ($self, $soid) = @_;
$self->_stat($soid);
}
sub mtime {
my ($self, $soid) = @_;
my (undef, $mtime) = $self->stat($soid);
$mtime;
}
sub size {
my ($self, $soid) = @_;
my ($size, undef) = $self->stat($soid);
$size;
}
sub remove {
my ($self, $soid) = @_;
$self->object_layout();
$self->_remove($soid);
}
# Items to export into callers namespace by default. Note: do not export
lib/Ceph/Rados/Striper.pm view on Meta::CPAN
=head2 write_data(soid, data)
=head2 write_handle(soid, handle)
As L<write_data()>, but explicitly declaring the source type.
=head2 append(soid, data)
Wraps C<rados_striper_append()>. Appends data to the ceph object with the supplied ID. Data must be a perl scalar, not a handle. Returns 1 on success. Croaks on failure.
=head2 stat(soid)
Wraps C<rados_striper_stat()>. Returns a 2-element list of (filesize, mtime) for the ceph object with the supplied ID.
=head2 read(soid, len=filesize, offset=0)
Wraps C<rados_striper_read()>. Read data from the ceph object with the supplied ID, and return the data read. Croaks on failure.
=head2 read_handle(soid, handle)
As C<read()>, but writes the data directly to the supplied handle instead of returning it.
=head2 remove(soid)
( run in 1.386 second using v1.01-cache-2.11-cpan-49f99fa48dc )