Ceph-Rados

 view release on metacpan or  search on metacpan

XS/IO.xs  view on Meta::CPAN

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  CODE:
    buf = (const char *)SvPV(data, len);
    err = rados_append(io, oid, buf, len);
    if (err < 0)
        croak("cannot append to object '%s': %s", oid, strerror(-err));
    RETVAL = err == 0;
  OUTPUT:
    RETVAL
 
void
_stat(io, oid)
    rados_ioctx_t    io
    const char *     oid
  PREINIT:
    size_t           size;
    time_t           mtime;
    int              err;
  PPCODE:
    err = rados_stat(io, oid, &size, &mtime);
    if (err < 0)
        croak("cannot stat object '%s': %s", oid, strerror(-err));
    XPUSHs(sv_2mortal(newSVuv(size)));
    XPUSHs(sv_2mortal(newSVuv(mtime)));
 
 
SV *
_read(io, oid, len, off = 0)
    rados_ioctx_t    io
    const char *     oid

XS/IO.xs  view on Meta::CPAN

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  size_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) || debug) {
      // stat and determine read length
      err = rados_stat(ioctx, oid, &psize, &pmtime);
      if (err < 0)
          croak("cannot stat object '%s': %s", oid, strerror(-err));
  }
  if (0 == len)
      len = psize-off;
  if (debug)
      printf("preparing to write from %s to FH, %zu bytes\n", oid, len);
  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;

lib/Ceph/Rados.pm  view on Meta::CPAN

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  use Ceph::Rados;
 
  my $cluster = Ceph::Rados->new('admin');
  $cluster->set_config_file;
  $cluster->set_config_option( keyring => '/etc/ceph/ceph.client.admin.keyring');
  $cluster->connect;
 
  my $io = $cluster->io('testing_pool');
  $io->write('greeting', 'hello');
  my $stored_data = $io->read('greeting',10);
  my ($len, $mtime) = $io->stat('greeting');
  $io->delete('greeting');
 
  my $list = $io->list;
  while (my $entry = $list->next) {
      print "Found $entry\n";
  }
 
=head1 DESCRIPTION
 
This module provides a very limited subset of the librados API,

lib/Ceph/Rados/IO.pm  view on Meta::CPAN

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
}
 
sub read_handle_perl {
    my ($self, $oid, $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($oid);
    }
    my $count = 0;
    #
    for (my $pos = $off; $pos <= $len+$off; $pos += $DEFAULT_OSD_MAX_WRITE) {
        my $chunk;
        if ($pos + $DEFAULT_OSD_MAX_WRITE > $len) {
            $chunk = $len % $DEFAULT_OSD_MAX_WRITE;
        } else {
            $chunk = $DEFAULT_OSD_MAX_WRITE;
        }

lib/Ceph/Rados/IO.pm  view on Meta::CPAN

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
    } else {
        Carp::confess "Called with neither an open filehandle equivalent nor an object with a \`write\` method";
    }
}
 
 
sub read {
    my ($self, $oid, $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($oid);
    }
    $off ||= 0;
    $self->_read($oid, $len, $off);
}
 
sub stat {
    my ($self, $oid) = @_;
    $self->_stat($oid);
}
 
sub pool_required_alignment {
    my ($self) = @_;
    return $self->_pool_required_alignment();
}
 
sub mtime {
    my ($self, $oid) = @_;
    my (undef, $mtime) = $self->stat($oid);
    $mtime;
}
 
sub size {
    my ($self, $oid) = @_;
    my ($size, undef) = $self->stat($oid);
    $size;
}
 
# Autoload methods go after =cut, and are processed by the autosplit program.
 
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
 
=head1 NAME

lib/Ceph/Rados/IO.pm  view on Meta::CPAN

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
=head2 write_data(oid, data)
 
=head2 write_handle(oid, handle)
 
As L<write_data()>, but explicitly declaring the source type.
 
=head2 append(oid, data)
 
Wraps C<rados_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(oid)
 
Wraps C<rados_stat()>.  Returns a 2-element list of (filesize, mtime) for the ceph object with the supplied ID.
 
=head2 read(oid, len=filesize, offset=0)
 
Wraps C<rados_read()>.  Read data from the ceph object with the supplied ID, and return the data read.  Croaks on failure.
 
=head2 read_handle(oid, handle)
 
As C<read()>, but writes the data directly to the supplied handle instead of returning it.
 
=head2 remove(oid)

t/100_raw_api_crud.t  view on Meta::CPAN

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
ok( $io->write($filename, $content), "Write object" );
ok( $io->mtime($filename), "Get file mod time" );
my $length;
ok( $length = $io->size($filename), "Get file size" );
is( $length, length($content), "Get correct size" );
$length = length($content); # just to be sure following tests don't fail if above does
ok( my $stored_data = $io->read($filename, $length), "Read $length bytes from object" );
is( $stored_data, $content, "Get back content ok" );
ok( my $stored_data2 = $io->read($filename), "Read unknown bytes from object" );
is( $stored_data2, $content, "Get back content ok without read size" );
ok( my ($stat_size, $stat_mtime) = $io->stat($filename), "Stat object" );
is( $stat_size, $length, "Stat size is same as content length" );
ok( $list = $io->list, "Opened list context" );
my $match = 0;
while (my $entry = $list->next) {
    #diag "Found $entry";
    $match = 1 if $entry eq $filename;
}
ok( $match, "List contains written file" );
ok( $io->remove($filename), "Remove object" );
lives_ok { undef $list } "Closed list context";



( run in 1.361 second using v1.01-cache-2.11-cpan-49f99fa48dc )