add check locked bbdd in merge process pandora_enterprise#9201
This commit is contained in:
parent
56196b12c7
commit
638d073967
|
@ -1543,14 +1543,20 @@ sub db_insert_get_values ($) {
|
|||
########################################################################
|
||||
## Try to obtain the given lock.
|
||||
########################################################################
|
||||
sub db_get_lock($$;$) {
|
||||
my ($dbh, $lock_name, $lock_timeout) = @_;
|
||||
sub db_get_lock($$;$$) {
|
||||
my ($dbh, $lock_name, $lock_timeout, $do_not_wait_lock) = @_;
|
||||
|
||||
# Only supported in MySQL.
|
||||
return 1 unless ($RDBMS eq 'mysql');
|
||||
|
||||
# Set a default lock timeout of 1 second
|
||||
$lock_timeout = 1 if (! defined ($lock_timeout));
|
||||
|
||||
if ($do_not_wait_lock) {
|
||||
if (!db_is_free_lock($dbh, $lock_name)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
# Attempt to get the lock!
|
||||
my $sth = $dbh->prepare('SELECT GET_LOCK(?, ?)');
|
||||
|
@ -1563,6 +1569,26 @@ sub db_get_lock($$;$) {
|
|||
return $lock;
|
||||
}
|
||||
|
||||
########################################################################
|
||||
## Check is lock is free.
|
||||
########################################################################
|
||||
sub db_is_free_lock($$) {
|
||||
my ($dbh, $lock_name) = @_;
|
||||
|
||||
# Only supported in MySQL.
|
||||
return 1 unless ($RDBMS eq 'mysql');
|
||||
|
||||
# Attempt to get the lock!
|
||||
my $sth = $dbh->prepare('SELECT IS_FREE_LOCK(?)');
|
||||
$sth->execute($lock_name);
|
||||
my ($lock) = $sth->fetchrow;
|
||||
|
||||
# Something went wrong
|
||||
return 0 if (! defined ($lock));
|
||||
|
||||
return $lock;
|
||||
}
|
||||
|
||||
########################################################################
|
||||
## Release the given lock.
|
||||
########################################################################
|
||||
|
|
|
@ -1193,6 +1193,20 @@ if ($conf{'_force'} == 1) {
|
|||
db_release_pandora_lock($dbh, $lock_name, $LOCK_TIMEOUT);
|
||||
}
|
||||
|
||||
# Get a lock merging.
|
||||
my $lock_merge = db_get_lock ($dbh, 'merge-working', $LOCK_TIMEOUT, 1);
|
||||
if ($lock_merge == 0) {
|
||||
log_message ('', " [*] Merge is running.\n\n");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Get a lock on merging events.
|
||||
my $lock_merge_events = db_get_lock ($dbh, 'merging-events', $LOCK_TIMEOUT, 1);
|
||||
if ($lock_merge_events == 0) {
|
||||
log_message ('', " [*] Merge events is running.\n\n");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Get a lock on dbname.
|
||||
my $lock = db_get_pandora_lock ($dbh, $lock_name, $LOCK_TIMEOUT);
|
||||
if ($lock == 0) {
|
||||
|
|
Loading…
Reference in New Issue