Ignore:
Timestamp:
2008-08-29T13:10:39+12:00 (16 years ago)
Author:
davidb
Message:

Introduction of new GDBM alternative for archives.inf as step towards full incremental building. Information traditionally stored in archives.inf PLUS additional information that will help with working out what files have changed since last build, and what doc-id they hashed to is stored in two GDBM databases. For now these databases aren't read, but in the future ArchivesInfPlugin will be upgraded to use these to support these.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/GDBMUtils.pm

    r15890 r17087  
    66my $debug = 0;
    77
    8 # /** Global variable to hold a string containing the last collection a gdbmGet
    9 #  *  was performed on.
     8# /** Global variables to hold a strings containing:
     9#  *    the last collection, oid and value
     10#  *  a gdbmCachedCollectionGet() was performed on.
    1011#  */
    1112my $gdbmget_previous_collection = "";
    12 # /** Global variable to hold a string containing the last oid a gdbmGet was
    13 #  *  performed on.
    14 #  */
    1513my $gdbmget_previous_oid = "";
    16 # /** Global variable to hold a string containing the resulting value of the
    17 #  *  last gdbmGet request.
    18 #  */
    1914my $gdbmget_previous_value = "";
     15
     16
     17
     18sub gdbmDatabaseGet
     19  {
     20    my ($database, $oid) = @_;
     21
     22    # Are we in windows? Do we need .exe?
     23    my $exe = &util::get_os_exe();
     24
     25    # Retrieve the raw document content
     26    print STDERR "#Get document\ncmd: gdbmget$exe \"$database\" \"$oid\"\n" if $debug;
     27    my $value = `gdbmget$exe "$database" "$oid"`;
     28
     29    # Done
     30    return $value;
     31  }
     32
     33sub gdbmDatabaseAppend
     34  {
     35    my ($database, $oid, $value) = @_;
     36
     37    # Are we in windows? Do we need .exe?
     38    my $exe = &util::get_os_exe();
     39
     40    # Escape any speech marks in the value
     41    $value =~ s/\"/\\\"/g;
     42    # Set the document content
     43    print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\" \"$value\" append\n" if $debug;
     44    `gdbmset$exe "$database" "$oid" "$value" append`;
     45}
     46
     47
     48sub gdbmDatabaseSet
     49  {
     50    my ($database, $oid, $value) = @_;
     51
     52    # Are we in windows? Do we need .exe?
     53    my $exe = &util::get_os_exe();
     54
     55    # Escape any speech marks in the value
     56    $value =~ s/\"/\\\"/g;
     57    # Set the document content
     58    print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\" \"$value\"\n" if $debug;
     59    `gdbmset$exe "$database" "$oid" "$value"`;
     60}
     61
     62
     63sub gdbmDatabaseRemove
     64  {
     65    my ($database, $oid) = @_;
     66
     67    # Are we in windows? Do we need .exe?
     68    my $exe = &util::get_os_exe();
     69
     70    # Remove the document from the database
     71    print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\"\n" if $debug;
     72
     73    # Think it would be clearer if this funcctionality was done
     74    # by a separate executable, e.g. gdbmremove
     75    `gdbmset$exe "$database" "$oid"`;
     76}
     77
     78
    2079
    2180# /** This wraps John T's gdbmget executable to get the gdbm database entry for
     
    2988#  *  @author John Thompson, DL Consulting Ltd.
    3089#  */
    31 sub gdbmGet()
     90sub gdbmCachedCollectionGet
    3291  {
    3392    my ($collection, $oid) = @_;
     
    42101        return $gdbmget_previous_value;
    43102      }
     103
    44104    # Where's the database?
    45     my $database = &getDatabasePath($collection);
    46     # Are we in windows? Do we need .exe?
    47     my $exe = "";
    48     $exe = ".exe" if $ENV{'GSDLOS'} =~ /^windows$/i;
    49     # Retrieve the raw document content
    50     print STDERR "#Get document\ncmd: gdbmget$exe \"$database\" \"$oid\"\n" if $debug;
    51     my $value = `gdbmget$exe "$database" "$oid"`;
     105    my $database = _getDatabasePath($collection);
     106
     107    my $value = gdbmDatbaseGet($database,$oid);
     108
    52109    # Tidy up the ever growing number of newlines at the end of the value
    53110    $value =~ s/(\r?\n)+/$1/g;
     111    # Why do we need the above line?  At the very least it would seem
     112    # better that the data going in to the database through 'set' is
     113    # monitored for superfluous \r\n which are then removed before being
     114    # saved in GDBM
     115
    54116    # Cache this result
    55117    $gdbmget_previous_collection = $collection;
    56118    $gdbmget_previous_oid = $oid;
    57119    $gdbmget_previous_value = $value;
     120
    58121    # Done
    59122    return $value;
    60123  }
    61 # /** gdbmGet() **/
     124# /** gdbmCachedCollectionGet **/
    62125
    63126# /** This wraps John T's gdbmset executable to set the gdbm database entry for
     
    70133#  *  @author John Rowe, DL Consulting Ltd.
    71134#  */
    72 sub gdbmSet()
     135sub gdbmCachedCollectionSet
    73136  {
    74137    my ($collection, $oid, $value) = @_;
     138
    75139    # Where's the database?
    76     my $database = &getDatabasePath($collection);
    77     # Are we in windows? Do we need .exe?
    78     my $exe = &util::get_os_exe();
     140    my $database = _getDatabasePath($collection);
     141
     142
    79143    # Check whether value is set
    80144    if (defined($value))
    81145      {
    82         # Escape any speech marks in the value
    83         $value =~ s/\"/\\\"/g;
    84         # Set the document content
    85         print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\" \"$value\"\n" if $debug;
    86         `gdbmset$exe "$database" "$oid" "$value"`;
     146      gdbmDatabaseSet($database,$oid,$value);
    87147      }
    88148    else
    89149      {
    90         # Remove the document from the database
    91         print STDERR "#Set document\ncmd: gdbmset$exe \"$database\" \"$oid\"\n" if $debug;
    92         `gdbmset$exe "$database" "$oid"`;
     150      gdbmDtabaseRemove($database,$oid);
    93151      }
     152
    94153    # Empty any cached values, as they may now be invalid
     154
    95155    # Cache this result
    96156    $gdbmget_previous_collection = "";
     
    98158    $gdbmget_previous_value = 0;
    99159  }
    100 # /** gdbmSet() **/
     160# /** gdbmCollectionSet **/
    101161
    102162# /** This works out the database path and returns it to the calling
     
    107167#  *  @author John Rowe, DL Consulting Ltd.
    108168#  */
    109 sub getDatabasePath()
     169
     170sub _getDatabasePath
    110171  {
    111172    my $collection = shift(@_);
     173
    112174    # Find out the database extension
    113     my $ext = ".bdb";
    114     $ext = ".ldb" if &util::is_little_endian();
     175    my $ext = &util::is_little_endian() ? ".ldb" : ".bdb";
     176
    115177    # Now return the full filename of the database
     178
    116179    return &util::filename_cat($ENV{'GSDLHOME'}, "collect", $collection, "index", "text", $collection.$ext);
    117180  }
    118 # /** getDatabasePath() **/
     181# /** getDatabasePath **/
    119182
    1201831;
Note: See TracChangeset for help on using the changeset viewer.