You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-15 01:04:37 +02:00
Revert "Abortive attempt at cleaning up some thread issues - I realized the issue is in mixing threads and objects too liberally. Trying another approach but want to keep this code for historical and reference purposes."
This reverts commit e95631f82a
.
This commit is contained in:
@ -4,61 +4,28 @@
|
||||
package BackRest::ThreadGroup;
|
||||
|
||||
use threads;
|
||||
use threads::shared;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
|
||||
use File::Basename;
|
||||
use Time::HiRes qw(gettimeofday usleep);
|
||||
|
||||
use lib dirname($0) . '/../lib';
|
||||
use BackRest::Utility;
|
||||
|
||||
####################################################################################################################################
|
||||
# Shared for all objects
|
||||
####################################################################################################################################
|
||||
my %oThreadGroupHash :shared; # Stores active thread groups
|
||||
|
||||
####################################################################################################################################
|
||||
# CONSTRUCTOR
|
||||
####################################################################################################################################
|
||||
sub new
|
||||
{
|
||||
my $strClass = shift; # Class name
|
||||
my $strDescription = shift; # Description of the group
|
||||
|
||||
# strDescription must be defined
|
||||
if (!defined($strDescription))
|
||||
{
|
||||
confess &log(ASSERT, 'strDescription is not defined');
|
||||
}
|
||||
|
||||
# Create the label based on time and description
|
||||
hsleep(.001);
|
||||
my $strLabel = '[' . gettimeofday() . '] ' . $strDescription;
|
||||
my $class = shift; # Class name
|
||||
|
||||
# Create the class hash
|
||||
my $self = {};
|
||||
bless $self, $strClass;
|
||||
|
||||
&log(TRACE, ref($self) . " create [$self] '${strLabel}'");
|
||||
bless $self, $class;
|
||||
|
||||
# Initialize variables
|
||||
$self->{iThreadTotal} = 0;
|
||||
$self->{iThreadId} = threads->tid();
|
||||
|
||||
# Lock the group has so that mods are synchronized
|
||||
lock(%oThreadGroupHash);
|
||||
|
||||
# Add the time to the description and store it as the label, making sure there are no collisions
|
||||
if (defined($oThreadGroupHash{$strLabel}))
|
||||
{
|
||||
confess &log(ASSERT, "collision detected in thread group '${strLabel}'");
|
||||
}
|
||||
|
||||
$self->{strLabel} = shared_clone($strLabel);
|
||||
$oThreadGroupHash{$self->{strLabel}} = true;
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -73,8 +40,6 @@ sub add
|
||||
my $self = shift;
|
||||
my $oThread = shift;
|
||||
|
||||
&log(TRACE, ref($self) . " add [$self], thread [$oThread]");
|
||||
|
||||
$self->{oyThread}[$self->{iThreadTotal}] = $oThread;
|
||||
$self->{iThreadTotal}++;
|
||||
|
||||
@ -102,9 +67,7 @@ sub complete
|
||||
# Rejoin the threads
|
||||
while ($iThreadComplete < $self->{iThreadTotal})
|
||||
{
|
||||
# hsleep(.1);
|
||||
hsleep(1);
|
||||
&log(TRACE, 'waiting for threads to exit');
|
||||
hsleep(.1);
|
||||
|
||||
# If a timeout has been defined, make sure we have not been running longer than that
|
||||
if (defined($iTimeout))
|
||||
@ -125,7 +88,7 @@ sub complete
|
||||
{
|
||||
if (defined($self->{oyThread}[$iThreadIdx]->error()))
|
||||
{
|
||||
# $self->kill();
|
||||
$self->kill();
|
||||
|
||||
if ($bConfessOnError)
|
||||
{
|
||||
@ -177,7 +140,7 @@ sub kill
|
||||
$self->{oyThread}[$iThreadIdx]->join();
|
||||
}
|
||||
|
||||
$self->{oyThread}[$iThreadIdx] = undef;
|
||||
undef($self->{oyThread}[$iThreadIdx]);
|
||||
$iTotal++;
|
||||
}
|
||||
}
|
||||
@ -188,43 +151,11 @@ sub kill
|
||||
####################################################################################################################################
|
||||
# DESTRUCTOR
|
||||
####################################################################################################################################
|
||||
sub DESTROY
|
||||
sub DEMOLISH
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
if ($self->{iThreadId} != threads->tid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
&log(TRACE, "BackRest::ThreadGroup destroy [$self] '$self->{strLabel}'");
|
||||
|
||||
$self->kill();
|
||||
|
||||
# Lock the group hash and delete the current group
|
||||
lock(%oThreadGroupHash);
|
||||
|
||||
if (!defined($oThreadGroupHash{$self->{strLabel}}))
|
||||
{
|
||||
confess &log(ASSERT, "BackRest::ThreadGroup [$self] '$self->{strLabel}' has already been destroyed");
|
||||
}
|
||||
|
||||
delete($oThreadGroupHash{$self->{strLabel}});
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# print
|
||||
####################################################################################################################################
|
||||
sub print
|
||||
{
|
||||
# Lock the group hash
|
||||
lock(%oThreadGroupHash);
|
||||
|
||||
# print all active groups
|
||||
foreach my $strLabel (sort(keys %oThreadGroupHash))
|
||||
{
|
||||
&log(TRACE, "BackRest::ThreadGroup active '${strLabel}'");
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
Reference in New Issue
Block a user