* Fixed a bug with caching database handles in the recent database updates causing Database->write to stop working.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent fe33fbb239
commit 51c9d2952d
  1. 7
      Anvil/Tools/Account.pm
  2. 37
      Anvil/Tools/Database.pm
  3. 2
      Anvil/Tools/System.pm
  4. 10
      cgi-bin/striker
  5. 3
      share/words.xml

@ -306,6 +306,7 @@ AND
# Test the passed-in password.
my $test_password_answer = $anvil->Account->encrypt_password({
debug => 2,
password => $anvil->data->{cgi}{password}{value},
salt => $user_salt,
algorithm => $user_algorithm,
@ -345,7 +346,7 @@ WHERE
user_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($user_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
$anvil->Database->write({debug => $debug, query => $query, source => $THIS_FILE, line => __LINE__});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0183", variables => { user => $anvil->data->{cgi}{username}{value} }});
$anvil->Account->_write_cookies({
@ -404,9 +405,9 @@ WHERE
user_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{cookie}{anvil_user_uuid})."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
$anvil->Database->write({debug => $debug, query => $query, source => $THIS_FILE, line => __LINE__});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0183", variables => { user => $anvil->data->{cgi}{username}{value} }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0198", variables => { user => $anvil->data->{cgi}{username}{value} }});
}
# Log that they're out

@ -954,7 +954,7 @@ sub connect
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid},
"cache::db_fh::$uuid" => $anvil->data->{cache}{database_handle}{$uuid},
"cache::database_handle::${uuid}" => $anvil->data->{cache}{database_handle}{$uuid},
}});
# Set the first ID to be the one I read from later. Alternatively, if this host is
@ -977,7 +977,7 @@ sub connect
# Get a time stamp for this run, if not yet gotten.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"cache::db_fh::$uuid" => $anvil->data->{cache}{database_handle}{$uuid},
"cache::database_handle::${uuid}" => $anvil->data->{cache}{database_handle}{$uuid},
"sys::database::timestamp" => $anvil->data->{sys}{database}{timestamp},
}});
@ -4431,7 +4431,7 @@ sub query
$anvil->Database->_test_access({debug => $debug, uuid => $uuid});
# If I am still alive check if any locks need to be renewed.
$anvil->Database->check_lock_age;
$anvil->Database->check_lock_age({debug => $debug});
# Do I need to log the transaction?
if ($anvil->data->{sys}{database}{log_transactions})
@ -4650,7 +4650,7 @@ sub resync_databases
}
# Now read in the data from the different databases.
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{db_fh}})
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{
# ...
$anvil->data->{db_resync}{$uuid}{public}{sql} = [];
@ -4768,7 +4768,7 @@ sub resync_databases
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { row_uuid => $row_uuid }});
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{db_fh}})
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid => $uuid }});
@ -4916,7 +4916,7 @@ sub resync_databases
delete $anvil->data->{db_data};
# Do the INSERTs now and then release the memory.
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{db_fh}})
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{
# Merge the queries for both schemas into one array, with public schema
# queries being first, then delete the arrays holding them to free memory
@ -4967,7 +4967,6 @@ sub write
my $reenter = $parameter->{reenter} ? $parameter->{reenter} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
"cache::database_handle::${uuid}" => $anvil->data->{cache}{database_handle}{$uuid},
line => $line,
query => ((not $secure) or (($secure) && (not $anvil->Log->secure))) ? $query : $anvil->Words->string({key => "log_0186"}),
secure => $secure,
@ -4975,10 +4974,21 @@ sub write
reenter => $reenter,
}});
if ($uuid)
{
$anvil->data->{cache}{database_handle}{$uuid} = "" if not defined $anvil->data->{cache}{database_handle}{$uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"cache::database_handle::${uuid}" => $anvil->data->{cache}{database_handle}{$uuid},
}});
}
# Make logging code a little cleaner
my $database_name = defined $anvil->data->{database}{$uuid}{name} ? $anvil->data->{database}{$uuid}{name} : $anvil->data->{sys}{database}{name};
my $say_server = $uuid eq "" ? "#!string!log_0129!#" : $anvil->data->{database}{$uuid}{host}.":".$anvil->data->{database}{$uuid}{port}." -> ".$database_name;
#print "uuid: [$uuid], say_server: [$say_server]\n";
my $say_server = $uuid eq "" ? $anvil->Words->string({key => "log_0129"}) : $anvil->data->{database}{$uuid}{host}.":".$anvil->data->{database}{$uuid}{port}." -> ".$database_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
database_name => $database_name,
say_server => $say_server,
}});
# We don't check if ID is set here because not being set simply means to write to all available DBs.
if (not $query)
@ -4989,7 +4999,7 @@ sub write
}
# If I am still alive check if any locks need to be renewed.
$anvil->Database->check_lock_age;
$anvil->Database->check_lock_age({debug => $debug});
# This array will hold either just the passed DB ID or all of them, if no ID was specified.
my @db_uuids;
@ -5000,7 +5010,7 @@ sub write
}
else
{
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{db_fh}})
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid => $uuid }});
push @db_uuids, $uuid;
@ -5082,7 +5092,12 @@ sub write
else
{
push @{$query_set}, $query;
my $query_set_count = @{$query_set};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query_set_count => $query_set_count }});
}
my $db_uuids_count = @db_uuids;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { db_uuids_count => $db_uuids_count }});
foreach my $uuid (@db_uuids)
{
# Test access to the DB before we do the actual query

@ -947,7 +947,7 @@ sub maintenance_mode
if ($maintenance_mode eq "")
{
$maintenance_mode = 1;
$maintenance_mode = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { maintenance_mode => $maintenance_mode }});
}

@ -772,12 +772,18 @@ sub check_availability
{
my ($anvil) = @_;
my $debug = 2;
my $debug = 3;
my $available = 1;
# Set maintenance mode.
$available = $anvil->System->maintenance_mode({debug => $debug});
my $maintenance_mode = $anvil->System->maintenance_mode({debug => $debug});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { maintenance_mode => $maintenance_mode }});
if ($maintenance_mode)
{
$available = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { available => $available }});
}
# TODO: Phase this out
if ($available)

@ -227,7 +227,7 @@ The database connection error was:
<key name="log_0126">Exiting method: [#!variable!method!#]</key>
<key name="log_0127">Firewalld was not running, re-enabling it. If you do not want this behaviour, please set 'sys::daemons::restart_firewalld = 0' in the configuration file for this program (or in 'tools.conf').</key>
<key name="log_0128">Firewalld was not running, and 'sys::daemons::restart_firewalld = 0' is set. NOT starting it.</key>
<key name="log_0129">all</key> <!-- Used when logging DB writes to all DBs -->
<key name="log_0129"><![CDATA[<all>]]></key> <!-- Used when logging DB writes to all DBs -->
<key name="log_0130"><![CDATA[[ Error ] - The method: [#!variable!method!#] was called and the parameter: [#!variable!parameter!#] was passed an invalid UUID: [#!variable!uuid!#].]]></key>
<key name="log_0131">Entering function: [#!variable!function!#]</key>
<key name="log_0132">Connected to: [#!data!sys::database::connections!#] database(s).</key>
@ -296,6 +296,7 @@ The database connection error was:
<key name="log_0195">Ready to try to reconnect to: [#!variable!server!#], but delaying for: [#!variable!delay!#] seconds to give the database a chance to come back online in case this is a transient issue.</key>
<key name="log_0196">Failed to reconnect to the database, and now no connections remail. Exiting.</key>
<key name="log_0197"><![CDATA[System->maintenance_mode() was passed an invalid 'set' value: [#!variable!set!#]. No action taken.]]></key>
<key name="log_0198">The user: [#!variable!user!#] logged out successfully.</key>
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
<key name="t_0000">Test</key>

Loading…
Cancel
Save