/[Sack]/trunk/lib/Sack/From.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Sack/From.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 131 - (show annotations)
Wed Oct 7 17:17:52 2009 UTC (14 years, 9 months ago) by dpavlin
File size: 1165 byte(s)
write shard locally on lorry to speed up cloud bringup and re-seed nodes on restart
1 package Sack::From;
2
3 use warnings;
4 use strict;
5
6 use Data::Dump qw(dump);
7
8 use lib "/srv/webpac2/lib/";
9 use WebPAC::Input::ISI;
10
11 $WebPAC::Input::ISI::subfields = undef; # disable parsing of subfields
12
13 use Storable;
14
15 sub new {
16 my $class = shift;
17 my $self = bless {@_}, $class;
18
19 warn "from ",dump( @_ );
20
21 $self->{input} = WebPAC::Input::ISI->new( @_ );
22 warn "got ", $self->size, " records for ", dump @_;
23
24 $self->{pos} = 1;
25 $self->{shard} = 0;
26
27 return $self;
28 }
29
30 sub input { $_[0]->{input} }
31 sub size { $_[0]->{input}->size }
32
33 sub shard {
34 my ($self,$limit) = @_;
35
36 my $path = "/tmp/sack.shard.$self->{shard}.$limit";
37
38 if ( -e $path ) {
39 warn "retrive $path ", -s $path, " bytes";
40 return retrieve $path;
41 }
42
43 my $start_pos = $self->{pos};
44 $self->{shard}++;
45 my $data;
46
47 foreach my $pos ( 1 .. $limit ) {
48 push @$data, $self->input->fetch_rec( $self->{pos}++ );
49 }
50
51 my $end_pos = $self->{pos} - 1;
52 my $r_len = length $self->size;
53
54 my $range = sprintf "%${r_len}d-%${r_len}d", $start_pos, $end_pos;
55
56 warn "shard $self->{shard} range: $range / $self->size\n";
57
58 store $data, $path;
59 warn "store $path ", -s $path, " bytes";
60
61 return $data;
62 }
63
64 1;

  ViewVC Help
Powered by ViewVC 1.1.26