version 1.5, 2006/08/03 17:27:48
|
version 1.6, 2006/08/03 17:53:47
|
Line 38 use Apache::lonnet;
|
Line 38 use Apache::lonnet;
|
|
|
# |
# |
# Options |
# Options |
my ($help,$debug,$test,$p_is_s); |
my ($help,$debug,$test,$test_db,$p_is_s); |
GetOptions("help" => \$help, |
GetOptions("help" => \$help, |
"debug" => \$debug, |
"debug" => \$debug, |
"test" => \$test, |
"test" => \$test, |
"p_is_s" => \$p_is_s); |
"create_test_db" => \$test_db, |
|
"p_is_s" => \$p_is_s); |
|
|
if (! defined($debug)) { $debug = 0; } |
if (! defined($debug)) { $debug = 0; } |
if (! defined($test)) { $test = 0; } |
if (! defined($test)) { $test = 0; } |
Line 57 Options:
|
Line 58 Options:
|
-debug Output debugging code (not much is output yet) |
-debug Output debugging code (not much is output yet) |
-test Verify the given *.hist file will reconstruct the current db file |
-test Verify the given *.hist file will reconstruct the current db file |
Sends error messages to STDERR. |
Sends error messages to STDERR. |
|
-create_test_db |
|
when testing also create a *.db.test db of the testing info |
-p_is_s Treat 'P' lines as 'S' lines. |
-p_is_s Treat 'P' lines as 'S' lines. |
Examples: |
Examples: |
rebuild_db_from_hist.pl -t $file.hist # Perform a test rebuild |
rebuild_db_from_hist.pl -t $file.hist # Perform a test rebuild |
Line 76 while (my $fname = shift) {
|
Line 79 while (my $fname = shift) {
|
my $db_filename = $fname; |
my $db_filename = $fname; |
$db_filename =~ s/\.hist$/\.db/; |
$db_filename =~ s/\.hist$/\.db/; |
if (-e $db_filename && ! $test) { |
if (-e $db_filename && ! $test) { |
print "Aborting: The target file $db_filename exists.".$/; |
print STDERR "Aborting: The target file $db_filename exists.".$/; |
next; |
next; |
} |
} |
my ($error,$constructed_hash) = &process_file($fname,$db_filename,$debug); |
my ($error,$constructed_hash) = &process_file($fname,$db_filename,$debug); |
Line 86 while (my $fname = shift) {
|
Line 89 while (my $fname = shift) {
|
if (! defined($error) || ! $test) { |
if (! defined($error) || ! $test) { |
$error = &write_hash($db_filename,$constructed_hash); |
$error = &write_hash($db_filename,$constructed_hash); |
} |
} |
if ($test) { |
if ($test && $test_db) { |
$error = &write_hash($db_filename.'.test',$constructed_hash); |
$error = &write_hash($db_filename.'.test',$constructed_hash); |
} |
} |
if ($test) { |
if ($test) { |
my $error = &test_hash($db_filename,$constructed_hash); |
my $error = &test_hash($db_filename,$constructed_hash); |
if (defined($error)) { |
if (defined($error)) { |
print "Error processing ".$fname.$/; |
print "Error processing ".$fname.$/; |
print $error; |
print STDERR $error; |
} else { |
} else { |
print "Everything looks good for ".$fname.$/; |
print "Everything looks good for ".$fname.$/; |
} |
} |
Line 121 sub process_file {
|
Line 124 sub process_file {
|
# S:store |
# S:store |
# D:delete |
# D:delete |
# N:new put (only adds tha values if they are all new values) |
# N:new put (only adds tha values if they are all new values) |
|
# M:modify the values for a previous S |
my ($action,$time,$concatenated_data) = split(':',$command,3); |
my ($action,$time,$concatenated_data) = split(':',$command,3); |
if ($fname eq 'roles.hist' && $concatenated_data =~ /^.*:.*:/) { |
if ($fname eq 'roles.hist' && $concatenated_data =~ /^.*:.*:/) { |
(undef,undef,$concatenated_data) = split(':',$concatenated_data,3); |
(undef,undef,$concatenated_data) = split(':',$concatenated_data,3); |
} |
} |
next if (! defined($action)); |
next if (! defined($action)); |
if ($action eq 'P' && $p_is_s) { $action = 'S'; } |
if ($action eq 'P' && $p_is_s) { $action = 'S'; } |
my ($rid,$allkeys,$version); |
my ($rid,@allkeys,$version); |
if ($action eq 'S') { |
if ($action eq 'S') { |
($rid,$concatenated_data) = split(':',$concatenated_data,2); |
($rid,$concatenated_data) = split(':',$concatenated_data,2); |
$version = ++$db_to_store{"version:$rid"}; |
$version = ++$db_to_store{"version:$rid"}; |
#print $version.$/; |
#print $version.$/; |
} |
} |
|
if ($action eq 'M') { |
|
($rid,$version,$concatenated_data) = |
|
split(':',$concatenated_data,3); |
|
} |
next if (! defined($concatenated_data)); |
next if (! defined($concatenated_data)); |
my $add_new_data = 1; |
my $add_new_data = 1; |
my @data = split('&',$concatenated_data); |
my @data = split('&',$concatenated_data); |
Line 144 sub process_file {
|
Line 152 sub process_file {
|
} else { |
} else { |
$no_action_count++; |
$no_action_count++; |
} |
} |
} elsif ($action eq 'S') { |
} elsif ($action eq 'S' || $action eq 'M') { |
# Versioning of data, so we update the old ata |
# Versioning of data, so we update the old ata |
$allkeys.=$key.':'; |
push(@allkeys,$key); |
$db_to_store{"$version:$rid:$key"}=$value; |
$db_to_store{"$version:$rid:$key"}=$value; |
} elsif ($action eq 'N') { |
} elsif ($action eq 'N') { |
if (exists($db_to_store{$key})) { |
if (exists($db_to_store{$key})) { |
Line 159 sub process_file {
|
Line 167 sub process_file {
|
$error = "Unable to understand action '".$action."'"; |
$error = "Unable to understand action '".$action."'"; |
} |
} |
} |
} |
|
|
if ($action eq 'N' && $add_new_data) { |
if ($action eq 'N' && $add_new_data) { |
foreach my $k_v_pair (@data) { |
foreach my $k_v_pair (@data) { |
my ($key,$value) = split('=',$k_v_pair,2); |
my ($key,$value) = split('=',$k_v_pair,2); |
$db_to_store{$key}=$value; |
$db_to_store{$key}=$value; |
} |
} |
} |
} |
if ($action eq 'S') { |
if ($action eq 'S') { |
$db_to_store{"$version:$rid:timestamp"}=$time; |
$db_to_store{"$version:$rid:timestamp"}=$time; |
$allkeys.='timestamp'; |
push(@allkeys,'timestamp'); |
$db_to_store{"$version:keys:$rid"}=$allkeys; |
} |
|
if ($action eq 'S' || $action eq 'M') { |
|
$db_to_store{"$version:keys:$rid"}=join(':',@allkeys); |
} |
} |
if (defined($error)) { |
if (defined($error)) { |
return ('Error:'.$error.$/,undef); |
return ('Error:'.$error.$/,undef); |