~ubuntu-branches/ubuntu/vivid/apt-cacher/vivid-proposed

« back to all changes in this revision

Viewing changes to test/db.pl

  • Committer: Package Import Robot
  • Author(s): Mark Hindley
  • Date: 2011-11-27 08:39:23 UTC
  • mfrom: (4.2.8 sid)
  • Revision ID: package-import@ubuntu.com-20111127083923-bgg2i3seunmxdeqx
Tags: 1.7.2
* Clear SysV semaphore block on install.
* Brazilian Portuguese debconf translation. Thanks to Marco Juliano e
  Silva (closes: #649499).
* When refreshing Release files internally, use Cache-Control: no-cache
* Add support for "status" action to init.d script. Patch from Peter
  Eisentraut (closes: #647984).
* Allow source files to be xv compressed. Patch from Ansgar Burghardt
  (closes: #648470).
* Support setting IO priority to reduce load in apt-cacher-cleanup.pl.
* Move library files to lib/ subdir.
* Document support for incoming request Cache-Control headers.
* Remove deprecated/* from source tarball.
* Workaround features missing in perl versions less than 5.10. 
* Improve child process management using process groups.
* Fix reading checksums from patched index files when using pdiff option
  to apt-cacher-cleanup.pl.
* New option concurrent_import_limit to control simultaneous reading of
  checksums from new index files. Default is the number of virtual CPU
  cores as parsed from /proc/cpuinfo (where possible).  
* Replace cron.daily script with more flexible cron.d fragment.
* Precompile regexps where possible.
* Don't try to checksum installer files.
* Fix libcurl low speed timeout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
 
 
7
use BerkeleyDB;
 
8
 
 
9
our $cfg;
 
10
my $count=2;
 
11
 
 
12
sub sig_handler {
 
13
    warn "Got SIG@_. Exiting gracefully!\n" if $cfg->{debug};
 
14
    exit 1;
 
15
}
 
16
 
 
17
sub db {
 
18
    for ('INT', 'TERM', 'PIPE', 'QUIT', 'HUP', 'SEGV') {
 
19
        $SIG{$_} = \&sig_handler unless $SIG{$_};
 
20
    }
 
21
 
 
22
    my $env = new BerkeleyDB::Env
 
23
      -Home   => '/tmp',
 
24
        -Flags => DB_CREATE | DB_INIT_MPOOL | DB_INIT_CDB,
 
25
          -ErrFile => *STDERR,
 
26
            -ThreadCount => 64,
 
27
              -ErrPrefix => "[$$]:"
 
28
                or die $BerkeleyDB::Error;
 
29
 
 
30
    $env->set_isalive();
 
31
    if ($env->failchk == DB_RUNRECOVERY) {
 
32
        warn "Failed thread detected.\n";
 
33
    }
 
34
 
 
35
    $SIG{ALRM} = sub {
 
36
        $env->failchk;
 
37
        alarm 1;
 
38
    };
 
39
    alarm 1;
 
40
 
 
41
    my $dbh = new BerkeleyDB::Btree
 
42
      -Filename => '/tmp/test.db',
 
43
        -Flags => DB_CREATE,
 
44
          -Env => $env
 
45
            or die $BerkeleyDB::Error;
 
46
    undef $env;
 
47
    return $dbh;
 
48
}
 
49
 
 
50
sub fetch_store {
 
51
    my $cpid;
 
52
    my $dbh=db();
 
53
    warn "[$$]: Init DB in fetch_store\n";
 
54
 
 
55
    $dbh->db_put('test', 0) && die $!;
 
56
    $dbh->db_get('child', $cpid) && die $!;
 
57
    return 1;
 
58
}
 
59
 
 
60
 
 
61
sub return_file {
 
62
            my $dbh=$_[0];
 
63
            warn "[$$]: Init DB in return_file\n";
 
64
            $dbh->db_put('child', $$) && die $!;
 
65
            return 1;
 
66
}
 
67
 
 
68
while ($count--) {
 
69
    my $pid = fork;
 
70
    die $! unless defined $pid;
 
71
    if ($pid == 0) {
 
72
        fetch_store();
 
73
        exit(0);
 
74
    }
 
75
    # use %db here
 
76
    warn "[$$]: Child fetcher process $pid\n";
 
77
    if (return_file(db())) {
 
78
        sleep 1;
 
79
    }
 
80
}