|
|
@ -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. |
|
|
|
# Do the query. |
|
|
|
local $@; |
|
|
|
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 => { |
|
|
|
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,16 +17549,42 @@ sub query |
|
|
|
server => $say_server, |
|
|
|
server => $say_server, |
|
|
|
db_error => $DBI::errstr, |
|
|
|
db_error => $DBI::errstr, |
|
|
|
}}); }; |
|
|
|
}}); }; |
|
|
|
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'eval_error' => $@ }}); |
|
|
|
if ($@) |
|
|
|
if ($@) |
|
|
|
{ |
|
|
|
{ |
|
|
|
### TODO: Report back somehow that the handle is dead. |
|
|
|
### TODO: Report back somehow that the handle is dead. |
|
|
|
$anvil->Database->disconnect({debug => $debug}); |
|
|
|
my $connections = $anvil->Database->reconnect({debug => $debug}); |
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0675", variables => { |
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { connections => $connections }}); |
|
|
|
query => (not $secure) ? $query : $anvil->Log->is_secure($query), |
|
|
|
if ($connections) |
|
|
|
server => $say_server, |
|
|
|
{ |
|
|
|
eval_error => $@, |
|
|
|
# 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 => { |
|
|
|
return("!!error!!"); |
|
|
|
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, |
|
|
|
|
|
|
|
eval_error => $@, |
|
|
|
|
|
|
|
}}); |
|
|
|
|
|
|
|
return("!!error!!"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { |
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { |
|
|
|
uuid => $uuid, |
|
|
|
uuid => $uuid, |
|
|
@ -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 |
|
|
|
=head2 refresh_timestamp |
|
|
|
|
|
|
|
|
|
|
|
This refreshes C<< sys::database::timestamp >>. It returns C<< sys::database::timestamp >> as well. |
|
|
|
This refreshes C<< sys::database::timestamp >>. It returns C<< sys::database::timestamp >> as well. |
|
|
|