@ -13,6 +13,8 @@
# include <algorithm>
# include <array>
# include <cstddef>
# include <cstdint>
# include <limits>
# include <random>
# include <string>
@ -2622,6 +2624,174 @@ TEST_P(BackupEngineRateLimitingTestWithParam, RateLimiting) {
AssertBackupConsistency ( 0 , 0 , 100000 , 100010 ) ;
}
TEST_P ( BackupEngineRateLimitingTestWithParam , RateLimitingVerifyBackup ) {
const std : : size_t kMicrosPerSec = 1000 * 1000LL ;
std : : shared_ptr < RateLimiter > backupThrottler ( NewGenericRateLimiter (
1 , 100 * 1000 /* refill_period_us */ , 10 /* fairness */ ,
RateLimiter : : Mode : : kAllIo /* mode */ ) ) ;
bool makeThrottler = std : : get < 0 > ( GetParam ( ) ) ;
if ( makeThrottler ) {
backupable_options_ - > backup_rate_limiter = backupThrottler ;
}
bool is_single_threaded = std : : get < 1 > ( GetParam ( ) ) = = 0 ? true : false ;
backupable_options_ - > max_background_operations = is_single_threaded ? 1 : 10 ;
const std : : uint64_t backup_rate_limiter_limit = std : : get < 2 > ( GetParam ( ) ) . first ;
if ( makeThrottler ) {
backupable_options_ - > backup_rate_limiter - > SetBytesPerSecond (
backup_rate_limiter_limit ) ;
} else {
backupable_options_ - > backup_rate_limit = backup_rate_limiter_limit ;
}
DestroyDB ( dbname_ , Options ( ) ) ;
OpenDBAndBackupEngine ( true /* destroy_old_data */ ) ;
FillDB ( db_ . get ( ) , 0 , 100000 ) ;
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ,
false /* flush_before_backup */ ) ) ;
std : : vector < BackupInfo > backup_infos ;
BackupInfo backup_info ;
backup_engine_ - > GetBackupInfo ( & backup_infos ) ;
ASSERT_EQ ( 1 , backup_infos . size ( ) ) ;
const int backup_id = 1 ;
ASSERT_EQ ( backup_id , backup_infos [ 0 ] . backup_id ) ;
ASSERT_OK ( backup_engine_ - > GetBackupInfo ( backup_id , & backup_info ,
true /* include_file_details */ ) ) ;
std : : uint64_t bytes_read_during_verify_backup = 0 ;
for ( BackupFileInfo backup_file_info : backup_info . file_details ) {
bytes_read_during_verify_backup + = backup_file_info . size ;
}
auto start_verify_backup = db_chroot_env_ - > NowMicros ( ) ;
ASSERT_OK (
backup_engine_ - > VerifyBackup ( backup_id , true /* verify_with_checksum */ ) ) ;
auto verify_backup_time = db_chroot_env_ - > NowMicros ( ) - start_verify_backup ;
auto rate_limited_verify_backup_time =
( bytes_read_during_verify_backup * kMicrosPerSec ) /
backup_rate_limiter_limit ;
if ( makeThrottler ) {
EXPECT_GE ( verify_backup_time , 0.8 * rate_limited_verify_backup_time ) ;
}
CloseDBAndBackupEngine ( ) ;
AssertBackupConsistency ( backup_id , 0 , 100000 , 100010 ) ;
DestroyDB ( dbname_ , Options ( ) ) ;
}
TEST_P ( BackupEngineRateLimitingTestWithParam , RateLimitingChargeReadInBackup ) {
bool is_single_threaded = std : : get < 1 > ( GetParam ( ) ) = = 0 ? true : false ;
backupable_options_ - > max_background_operations = is_single_threaded ? 1 : 10 ;
const std : : uint64_t backup_rate_limiter_limit = std : : get < 2 > ( GetParam ( ) ) . first ;
std : : shared_ptr < RateLimiter > backup_rate_limiter ( NewGenericRateLimiter (
backup_rate_limiter_limit , 100 * 1000 /* refill_period_us */ ,
10 /* fairness */ , RateLimiter : : Mode : : kWritesOnly /* mode */ ) ) ;
backupable_options_ - > backup_rate_limiter = backup_rate_limiter ;
DestroyDB ( dbname_ , Options ( ) ) ;
OpenDBAndBackupEngine ( true /* destroy_old_data */ , false /* dummy */ ,
kShareWithChecksum /* shared_option */ ) ;
FillDB ( db_ . get ( ) , 0 , 10 ) ;
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ,
false /* flush_before_backup */ ) ) ;
std : : int64_t total_bytes_through_with_no_read_charged =
backup_rate_limiter - > GetTotalBytesThrough ( ) ;
CloseBackupEngine ( ) ;
backup_rate_limiter . reset ( NewGenericRateLimiter (
backup_rate_limiter_limit , 100 * 1000 /* refill_period_us */ ,
10 /* fairness */ , RateLimiter : : Mode : : kAllIo /* mode */ ) ) ;
backupable_options_ - > backup_rate_limiter = backup_rate_limiter ;
OpenBackupEngine ( true ) ;
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ,
false /* flush_before_backup */ ) ) ;
std : : int64_t total_bytes_through_with_read_charged =
backup_rate_limiter - > GetTotalBytesThrough ( ) ;
EXPECT_GT ( total_bytes_through_with_read_charged ,
total_bytes_through_with_no_read_charged ) ;
CloseDBAndBackupEngine ( ) ;
AssertBackupConsistency ( 1 , 0 , 10 , 20 ) ;
DestroyDB ( dbname_ , Options ( ) ) ;
}
TEST_P ( BackupEngineRateLimitingTestWithParam , RateLimitingChargeReadInRestore ) {
bool is_single_threaded = std : : get < 1 > ( GetParam ( ) ) = = 0 ? true : false ;
backupable_options_ - > max_background_operations = is_single_threaded ? 1 : 10 ;
const std : : uint64_t restore_rate_limiter_limit =
std : : get < 2 > ( GetParam ( ) ) . second ;
std : : shared_ptr < RateLimiter > restore_rate_limiter ( NewGenericRateLimiter (
restore_rate_limiter_limit , 100 * 1000 /* refill_period_us */ ,
10 /* fairness */ , RateLimiter : : Mode : : kWritesOnly /* mode */ ) ) ;
backupable_options_ - > restore_rate_limiter = restore_rate_limiter ;
DestroyDB ( dbname_ , Options ( ) ) ;
OpenDBAndBackupEngine ( true /* destroy_old_data */ ) ;
FillDB ( db_ . get ( ) , 0 , 10 ) ;
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ,
false /* flush_before_backup */ ) ) ;
CloseDBAndBackupEngine ( ) ;
DestroyDB ( dbname_ , Options ( ) ) ;
OpenBackupEngine ( false /* destroy_old_data */ ) ;
ASSERT_OK ( backup_engine_ - > RestoreDBFromLatestBackup ( dbname_ , dbname_ ) ) ;
std : : int64_t total_bytes_through_with_no_read_charged =
restore_rate_limiter - > GetTotalBytesThrough ( ) ;
CloseBackupEngine ( ) ;
DestroyDB ( dbname_ , Options ( ) ) ;
restore_rate_limiter . reset ( NewGenericRateLimiter (
restore_rate_limiter_limit , 100 * 1000 /* refill_period_us */ ,
10 /* fairness */ , RateLimiter : : Mode : : kAllIo /* mode */ ) ) ;
backupable_options_ - > restore_rate_limiter = restore_rate_limiter ;
OpenBackupEngine ( false /* destroy_old_data */ ) ;
ASSERT_OK ( backup_engine_ - > RestoreDBFromLatestBackup ( dbname_ , dbname_ ) ) ;
std : : int64_t total_bytes_through_with_read_charged =
restore_rate_limiter - > GetTotalBytesThrough ( ) ;
EXPECT_EQ ( total_bytes_through_with_read_charged ,
total_bytes_through_with_no_read_charged * 2 ) ;
CloseBackupEngine ( ) ;
AssertBackupConsistency ( 1 , 0 , 10 , 20 ) ;
DestroyDB ( dbname_ , Options ( ) ) ;
}
TEST_P ( BackupEngineRateLimitingTestWithParam ,
RateLimitingChargeReadInInitialize ) {
bool is_single_threaded = std : : get < 1 > ( GetParam ( ) ) = = 0 ? true : false ;
backupable_options_ - > max_background_operations = is_single_threaded ? 1 : 10 ;
const std : : uint64_t backup_rate_limiter_limit = std : : get < 2 > ( GetParam ( ) ) . first ;
std : : shared_ptr < RateLimiter > backup_rate_limiter ( NewGenericRateLimiter (
backup_rate_limiter_limit , 100 * 1000 /* refill_period_us */ ,
10 /* fairness */ , RateLimiter : : Mode : : kAllIo /* mode */ ) ) ;
backupable_options_ - > backup_rate_limiter = backup_rate_limiter ;
DestroyDB ( dbname_ , Options ( ) ) ;
OpenDBAndBackupEngine ( true /* destroy_old_data */ ) ;
FillDB ( db_ . get ( ) , 0 , 10 ) ;
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ,
false /* flush_before_backup */ ) ) ;
CloseDBAndBackupEngine ( ) ;
AssertBackupConsistency ( 1 , 0 , 10 , 20 ) ;
std : : int64_t total_bytes_through_before_initialize =
backupable_options_ - > backup_rate_limiter - > GetTotalBytesThrough ( ) ;
OpenDBAndBackupEngine ( false /* destroy_old_data */ ) ;
// We charge read in BackupEngineImpl::BackupMeta::LoadFromFile,
// which is called in BackupEngineImpl::Initialize() during
// OpenBackupEngine(false)
EXPECT_GT ( backupable_options_ - > backup_rate_limiter - > GetTotalBytesThrough ( ) ,
total_bytes_through_before_initialize ) ;
CloseDBAndBackupEngine ( ) ;
DestroyDB ( dbname_ , Options ( ) ) ;
}
# endif // !defined(ROCKSDB_VALGRIND_RUN) || defined(ROCKSDB_FULL_VALGRIND_RUN)
TEST_F ( BackupEngineTest , ReadOnlyBackupEngine ) {