* Fixed a problem in the resync code where differing time zones on two DB servers caused their time stamps to appear different.

* Fixed a pronlem where I entered into the check for missing records before reading the data from all the DBs.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 1d1258e8b5
commit e68ebe31a0
  1. 37
      AN/Tools/Database.pm

@ -2488,9 +2488,7 @@ AND
=head2 resync_databases
NOTE: Not implemented yet.
This will resync the database data on this and peer database(s) if needed.
This will resync the database data on this and peer database(s) if needed. It takes no arguments and will immediately return unless C<< sys::database::resync_needed >> was set.
=cut
sub resync_databases
@ -2517,7 +2515,7 @@ sub resync_databases
# column, the resync will be restricted to entries from this host uuid.
my $schema = $an->data->{sys}{database}{table}{$table}{schema};
my $host_column = $an->data->{sys}{database}{table}{$table}{host_column};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
table => $table,
schema => $schema,
host_column => $host_column,
@ -2580,7 +2578,7 @@ sub resync_databases
$an->data->{db_resync}{$id}{history}{sql} = [];
# Read in the data, modified_date first as we'll need that for all entries we record.
my $query = "SELECT modified_date, $uuid_column, ";
my $query = "SELECT modified_date AT time zone 'UTC', $uuid_column, ";
my $read_columns = [];
push @{$read_columns}, "modified_date";
push @{$read_columns}, $uuid_column;
@ -2604,7 +2602,7 @@ sub resync_databases
{
$query .= " WHERE ".$host_column." = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid});
}
$query .= ";";
$query .= " ORDER BY modified_date DESC;";
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0074", variables => { id => $id, query => $query }});
my $results = $an->Database->query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__});
@ -2666,18 +2664,9 @@ sub resync_databases
die $THIS_FILE." ".__LINE__."; This row's modified_date wasn't the first column returned in query: [$query]\n" if not $modified_date;
die $THIS_FILE." ".__LINE__."; This row's UUID column: [$uuid_column] wasn't the second column returned in query: [$query]\n" if not $row_uuid;
# Record this in the unified and local hashes. Note that we'll handle
# the 'hosts' table in a special way, then the rest depending on
# whether we have a host column or not.
if ($host_column)
{
# We habe a host column
}
else
{
# This table isn't restricted to given hosts.
# Record this in the unified and local hashes. # This table isn't restricted to given hosts.
$an->data->{db_data}{unified}{$table}{modified_date}{$modified_date}{$uuid_column}{$row_uuid}{$column_name} = $column_value;
$an->data->{db_data}{$id}{hosts}{modified_date}{$modified_date}{$uuid_column}{$row_uuid}{$column_name} = $column_value;
$an->data->{db_data}{$id}{$table}{modified_date}{$modified_date}{$uuid_column}{$row_uuid}{$column_name} = $column_value;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"db_data::unified::${table}::modified_date::${modified_date}::${uuid_column}::${row_uuid}::${column_name}" => $an->data->{db_data}{unified}{$table}{modified_date}{$modified_date}{$uuid_column}{$row_uuid}{$column_name},
"db_data::${id}::${table}::modified_date::${modified_date}::${uuid_column}::${row_uuid}::${column_name}" => $an->data->{db_data}{$id}{$table}{modified_date}{$modified_date}{$uuid_column}{$row_uuid}{$column_name},
@ -2743,7 +2732,7 @@ sub resync_databases
$query .= "$column_name = ".$an->data->{sys}{use_db_fh}->quote().", ";
}
$query .= "modified_date = ".$an->data->{sys}{use_db_fh}->quote($modified_date)." WHERE $uuid_column = ".$an->data->{sys}{use_db_fh}->quote($row_uuid).";";
$query .= "modified_date = ".$an->data->{sys}{use_db_fh}->quote($modified_date)."::timestamp AT TIME ZONE 'UTC' WHERE $uuid_column = ".$an->data->{sys}{use_db_fh}->quote($row_uuid).";";
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0074", variables => { id => $id, query => $query }});
# Now record the query in the array
@ -2774,7 +2763,7 @@ sub resync_databases
'values' => $values,
}});
my $query = "INSERT INTO public.$table (".$uuid_column.", ".$columns."modified_date) VALUES (".$an->data->{sys}{use_db_fh}->quote($row_uuid).", ".$values.$an->data->{sys}{use_db_fh}->quote($modified_date).");";
my $query = "INSERT INTO public.$table (".$uuid_column.", ".$columns."modified_date) VALUES (".$an->data->{sys}{use_db_fh}->quote($row_uuid).", ".$values.$an->data->{sys}{use_db_fh}->quote($modified_date)."::timestamp AT TIME ZONE 'UTC');";
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0074", variables => { id => $id, query => $query }});
# Now record the query in the array
@ -2817,7 +2806,7 @@ sub resync_databases
'values' => $values,
}});
my $query = "INSERT INTO history.$table (".$uuid_column.", ".$columns."modified_date) VALUES (".$an->data->{sys}{use_db_fh}->quote($row_uuid).", ".$values.$an->data->{sys}{use_db_fh}->quote($modified_date).");";
my $query = "INSERT INTO history.$table (".$uuid_column.", ".$columns."modified_date) VALUES (".$an->data->{sys}{use_db_fh}->quote($row_uuid).", ".$values.$an->data->{sys}{use_db_fh}->quote($modified_date)."::timestamp AT TIME ZONE 'UTC');";
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0074", variables => { id => $id, query => $query }});
# Now record the query in the array
@ -2842,6 +2831,9 @@ sub resync_databases
undef $an->data->{db_resync}{$id}{public}{sql};
undef $an->data->{db_resync}{$id}{history}{sql};
#print "Unified for: [$id]\n";
#print Dumper $merged;
if (@{$merged} > 0)
{
$an->Database->write({id => $id, query => $merged, source => $THIS_FILE, line => __LINE__});
@ -2850,8 +2842,9 @@ sub resync_databases
}
die;
}
}
} # foreach my $table
die;
# Show tables;
# SELECT table_schema, table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema') ORDER BY table_name ASC, table_schema DESC;

Loading…
Cancel
Save