You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-09-16 09:06:18 +02:00
Cleaned up some time functions.
This commit is contained in:
@@ -219,7 +219,7 @@ sub backup_thread_complete
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Sleep before trying again
|
# Sleep before trying again
|
||||||
sleep(.1);
|
hsleep(.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
&log(DEBUG, 'all threads exited');
|
&log(DEBUG, 'all threads exited');
|
||||||
|
@@ -8,16 +8,10 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use Carp;
|
use Carp;
|
||||||
|
|
||||||
# use Scalar::Util;
|
|
||||||
# use Net::OpenSSH;
|
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
# use POSIX ':sys_wait_h';
|
|
||||||
# use Scalar::Util 'blessed';
|
|
||||||
#
|
|
||||||
use lib dirname($0) . '/../lib';
|
use lib dirname($0) . '/../lib';
|
||||||
# use BackRest::Exception;
|
|
||||||
use BackRest::Utility;
|
use BackRest::Utility;
|
||||||
# use BackRest::ProcessAsync;
|
|
||||||
|
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
# CONSTRUCTOR
|
# CONSTRUCTOR
|
||||||
@@ -73,7 +67,7 @@ sub complete
|
|||||||
# Rejoin the threads
|
# Rejoin the threads
|
||||||
while ($iThreadComplete < $self->{iThreadTotal})
|
while ($iThreadComplete < $self->{iThreadTotal})
|
||||||
{
|
{
|
||||||
sleep(.1);
|
hsleep(.1);
|
||||||
|
|
||||||
# If a timeout has been defined, make sure we have not been running longer than that
|
# If a timeout has been defined, make sure we have not been running longer than that
|
||||||
if (defined($iTimeout))
|
if (defined($iTimeout))
|
||||||
|
@@ -10,6 +10,7 @@ use Carp qw(confess longmess);
|
|||||||
|
|
||||||
use Fcntl qw(:DEFAULT :flock);
|
use Fcntl qw(:DEFAULT :flock);
|
||||||
use File::Path qw(remove_tree);
|
use File::Path qw(remove_tree);
|
||||||
|
use Time::HiRes qw(usleep);
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ use Exporter qw(import);
|
|||||||
our @EXPORT = qw(version_get
|
our @EXPORT = qw(version_get
|
||||||
data_hash_build trim common_prefix wait_for_file file_size_format execute
|
data_hash_build trim common_prefix wait_for_file file_size_format execute
|
||||||
log log_file_set log_level_set test_set test_get test_check
|
log log_file_set log_level_set test_set test_get test_check
|
||||||
lock_file_create lock_file_remove
|
lock_file_create lock_file_remove hsleep
|
||||||
ini_save ini_load timestamp_string_get timestamp_file_string_get
|
ini_save ini_load timestamp_string_get timestamp_file_string_get
|
||||||
TRACE DEBUG ERROR ASSERT WARN INFO OFF true false
|
TRACE DEBUG ERROR ASSERT WARN INFO OFF true false
|
||||||
TEST TEST_ENCLOSE TEST_MANIFEST_BUILD TEST_BACKUP_RESUME TEST_BACKUP_NORESUME);
|
TEST TEST_ENCLOSE TEST_MANIFEST_BUILD TEST_BACKUP_RESUME TEST_BACKUP_NORESUME);
|
||||||
@@ -75,7 +76,7 @@ use constant
|
|||||||
|
|
||||||
# Test global variables
|
# Test global variables
|
||||||
my $bTest = false;
|
my $bTest = false;
|
||||||
my $iTestDelay;
|
my $fTestDelay;
|
||||||
|
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
# VERSION_GET
|
# VERSION_GET
|
||||||
@@ -212,6 +213,16 @@ sub trim
|
|||||||
return $strBuffer;
|
return $strBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
####################################################################################################################################
|
||||||
|
# hsleep - wrapper for usleep that takes seconds in fractions and returns time slept in ms
|
||||||
|
####################################################################################################################################
|
||||||
|
sub hsleep
|
||||||
|
{
|
||||||
|
my $fSecond = shift;
|
||||||
|
|
||||||
|
return usleep($fSecond * 1000000);
|
||||||
|
}
|
||||||
|
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
# WAIT_FOR_FILE
|
# WAIT_FOR_FILE
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
@@ -237,7 +248,7 @@ sub wait_for_file
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(1);
|
hsleep(.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
confess &log(ERROR, "could not find $strDir/$strRegEx after ${iSeconds} second(s)");
|
confess &log(ERROR, "could not find $strDir/$strRegEx after ${iSeconds} second(s)");
|
||||||
@@ -359,20 +370,20 @@ sub log_file_set
|
|||||||
sub test_set
|
sub test_set
|
||||||
{
|
{
|
||||||
my $bTestParam = shift;
|
my $bTestParam = shift;
|
||||||
my $iTestDelayParam = shift;
|
my $fTestDelayParam = shift;
|
||||||
|
|
||||||
# Set defaults
|
# Set defaults
|
||||||
$bTest = defined($bTestParam) ? $bTestParam : false;
|
$bTest = defined($bTestParam) ? $bTestParam : false;
|
||||||
$iTestDelay = defined($bTestParam) ? $iTestDelayParam : $iTestDelay;
|
$fTestDelay = defined($bTestParam) ? $fTestDelayParam : $fTestDelay;
|
||||||
|
|
||||||
# Make sure that a delay is specified in test mode
|
# Make sure that a delay is specified in test mode
|
||||||
if ($bTest && !defined($iTestDelay))
|
if ($bTest && !defined($fTestDelay))
|
||||||
{
|
{
|
||||||
confess &log(ASSERT, 'iTestDelay must be provided when bTest is true');
|
confess &log(ASSERT, 'iTestDelay must be provided when bTest is true');
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test delay should be between 1 and 600 seconds
|
# Test delay should be between 1 and 600 seconds
|
||||||
if (!($iTestDelay >= 0 && $iTestDelay <= 600))
|
if (!($fTestDelay >= 0 && $fTestDelay <= 600))
|
||||||
{
|
{
|
||||||
confess &log(ERROR, 'test-delay must be between 1 and 600 seconds');
|
confess &log(ERROR, 'test-delay must be between 1 and 600 seconds');
|
||||||
}
|
}
|
||||||
@@ -498,9 +509,9 @@ sub log
|
|||||||
{
|
{
|
||||||
*STDOUT->flush();
|
*STDOUT->flush();
|
||||||
|
|
||||||
if ($iTestDelay > 0)
|
if ($fTestDelay > 0)
|
||||||
{
|
{
|
||||||
sleep($iTestDelay);
|
hsleep($fTestDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,8 +15,8 @@ use File::Basename;
|
|||||||
use File::Copy 'cp';
|
use File::Copy 'cp';
|
||||||
use File::stat;
|
use File::stat;
|
||||||
use Fcntl ':mode';
|
use Fcntl ':mode';
|
||||||
|
use Time::HiRes qw(gettimeofday);
|
||||||
use DBI;
|
use DBI;
|
||||||
use Time::HiRes qw(gettimeofday usleep);
|
|
||||||
|
|
||||||
use lib dirname($0) . '/../lib';
|
use lib dirname($0) . '/../lib';
|
||||||
use BackRest::Exception;
|
use BackRest::Exception;
|
||||||
@@ -999,7 +999,7 @@ sub BackRestTestBackup_Test
|
|||||||
|
|
||||||
if (!$oFile->exists(PATH_BACKUP_ARCHIVE, $strArchiveCheck))
|
if (!$oFile->exists(PATH_BACKUP_ARCHIVE, $strArchiveCheck))
|
||||||
{
|
{
|
||||||
sleep(1);
|
hsleep(1);
|
||||||
|
|
||||||
if (!$oFile->exists(PATH_BACKUP_ARCHIVE, $strArchiveCheck))
|
if (!$oFile->exists(PATH_BACKUP_ARCHIVE, $strArchiveCheck))
|
||||||
{
|
{
|
||||||
@@ -1644,7 +1644,7 @@ sub BackRestTestBackup_Test
|
|||||||
# Sleep .5 seconds to give a reasonable amount of time for the file to be copied after the manifest was generated
|
# Sleep .5 seconds to give a reasonable amount of time for the file to be copied after the manifest was generated
|
||||||
# Sleep for a while to show there is a large window where this can happen
|
# Sleep for a while to show there is a large window where this can happen
|
||||||
&log(INFO, 'time ' . gettimeofday());
|
&log(INFO, 'time ' . gettimeofday());
|
||||||
usleep(.5 * 1000000);
|
hsleep(.5);
|
||||||
&log(INFO, 'time ' . gettimeofday());
|
&log(INFO, 'time ' . gettimeofday());
|
||||||
|
|
||||||
# Insert another row
|
# Insert another row
|
||||||
@@ -1736,7 +1736,7 @@ sub BackRestTestBackup_Test
|
|||||||
|
|
||||||
# Sleep for a while to show there is a large window where this can happen
|
# Sleep for a while to show there is a large window where this can happen
|
||||||
&log(INFO, 'time ' . gettimeofday());
|
&log(INFO, 'time ' . gettimeofday());
|
||||||
usleep(.5 * 1000000);
|
hsleep(.5);
|
||||||
&log(INFO, 'time ' . gettimeofday());
|
&log(INFO, 'time ' . gettimeofday());
|
||||||
|
|
||||||
# Modify the test file within the same second
|
# Modify the test file within the same second
|
||||||
|
Reference in New Issue
Block a user