|
|
|
@ -17533,6 +17533,15 @@ sub query |
|
|
|
|
}}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
### TODO: Remove this before pr/660 is released. |
|
|
|
|
# Trying to see how the handle changes if/when the handle is lost. |
|
|
|
|
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}}) |
|
|
|
|
{ |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { |
|
|
|
|
"cache::database_handle::${uuid}" => $anvil->data->{cache}{database_handle}{$uuid}, |
|
|
|
|
}}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Do the query. |
|
|
|
|
local $@; |
|
|
|
|
my $DBreq = eval { $anvil->data->{cache}{database_handle}{$uuid}->prepare($query) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0075", variables => { |
|
|
|
@ -17540,10 +17549,35 @@ sub query |
|
|
|
|
server => $say_server, |
|
|
|
|
db_error => $DBI::errstr, |
|
|
|
|
}}); }; |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'eval_error' => $@ }}); |
|
|
|
|
if ($@) |
|
|
|
|
{ |
|
|
|
|
### TODO: Report back somehow that the handle is dead. |
|
|
|
|
$anvil->Database->disconnect({debug => $debug}); |
|
|
|
|
my $connections = $anvil->Database->reconnect({debug => $debug}); |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { connections => $connections }}); |
|
|
|
|
if ($connections) |
|
|
|
|
{ |
|
|
|
|
# Try the prepare again |
|
|
|
|
$DBreq = eval { $anvil->data->{cache}{database_handle}{$uuid}->prepare($query) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0075", variables => { |
|
|
|
|
query => (not $secure) ? $query : $anvil->Log->is_secure($query), |
|
|
|
|
server => $say_server, |
|
|
|
|
db_error => $DBI::errstr, |
|
|
|
|
}}); }; |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'eval_error' => $@ }}); |
|
|
|
|
if ($@) |
|
|
|
|
{ |
|
|
|
|
# No luck, we're dead |
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0675", variables => { |
|
|
|
|
query => (not $secure) ? $query : $anvil->Log->is_secure($query), |
|
|
|
|
server => $say_server, |
|
|
|
|
eval_error => $@, |
|
|
|
|
}}); |
|
|
|
|
return("!!error!!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
# No luck, we're dead |
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0675", variables => { |
|
|
|
|
query => (not $secure) ? $query : $anvil->Log->is_secure($query), |
|
|
|
|
server => $say_server, |
|
|
|
@ -17551,6 +17585,7 @@ sub query |
|
|
|
|
}}); |
|
|
|
|
return("!!error!!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { |
|
|
|
|
uuid => $uuid, |
|
|
|
|
query => (not $secure) ? $query : $anvil->Log->is_secure($query), |
|
|
|
@ -17935,6 +17970,41 @@ AND |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=head2 reconnect |
|
|
|
|
|
|
|
|
|
This method disconnects from any connected databases, re-reads the config, and then tries to reconnect to any databases again. The number of connected datbaases is returned. |
|
|
|
|
|
|
|
|
|
This method takes no parameters. |
|
|
|
|
|
|
|
|
|
=cut |
|
|
|
|
sub reconnect |
|
|
|
|
{ |
|
|
|
|
my $self = shift; |
|
|
|
|
my $parameter = shift; |
|
|
|
|
my $anvil = $self->parent; |
|
|
|
|
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; |
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->resync_databases()" }}); |
|
|
|
|
|
|
|
|
|
# Close our own connection. |
|
|
|
|
$anvil->Database->locking({debug => $debug, release => 1}); |
|
|
|
|
|
|
|
|
|
# Disconnect from all databases and then stop the daemon, then reconnect. |
|
|
|
|
$anvil->Database->disconnect({debug => $debug}); |
|
|
|
|
|
|
|
|
|
# Refresh configs. |
|
|
|
|
$anvil->refresh(); |
|
|
|
|
|
|
|
|
|
# Reconnect. |
|
|
|
|
$anvil->Database->connect({debug => $debug}); |
|
|
|
|
|
|
|
|
|
# Log our connection count. |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { |
|
|
|
|
"sys::database::connections" => $anvil->data->{sys}{database}{connections}, |
|
|
|
|
}}); |
|
|
|
|
return($anvil->data->{sys}{database}{connections}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=head2 refresh_timestamp |
|
|
|
|
|
|
|
|
|
This refreshes C<< sys::database::timestamp >>. It returns C<< sys::database::timestamp >> as well. |
|
|
|
|