26
26
27
27
namespace rocksdb {
28
28
29
- // -------- BackupEngine class ---------
30
- class BackupEngine {
29
+ // -------- BackupEngineImpl class ---------
30
+ class BackupEngineImpl : public BackupEngine {
31
31
public:
32
- BackupEngine (Env* db_env, const BackupableDBOptions& options);
33
- ~BackupEngine ();
32
+ BackupEngineImpl (Env* db_env, const BackupableDBOptions& options);
33
+ ~BackupEngineImpl ();
34
34
Status CreateNewBackup (DB* db, bool flush_before_backup = false );
35
35
Status PurgeOldBackups (uint32_t num_backups_to_keep);
36
36
Status DeleteBackup (BackupID backup_id);
@@ -188,7 +188,13 @@ class BackupEngine {
188
188
static const size_t copy_file_buffer_size_ = 5 * 1024 * 1024LL ; // 5MB
189
189
};
190
190
191
- BackupEngine::BackupEngine (Env* db_env, const BackupableDBOptions& options)
191
+ BackupEngine* CreateNewBackupEngine (Env* db_env,
192
+ const BackupableDBOptions& options) {
193
+ return new BackupEngineImpl (db_env, options);
194
+ }
195
+
196
+ BackupEngineImpl::BackupEngineImpl (Env* db_env,
197
+ const BackupableDBOptions& options)
192
198
: stop_backup_(false ),
193
199
options_ (options),
194
200
db_env_(db_env),
@@ -271,11 +277,9 @@ BackupEngine::BackupEngine(Env* db_env, const BackupableDBOptions& options)
271
277
latest_backup_id_);
272
278
}
273
279
274
- BackupEngine::~BackupEngine () {
275
- LogFlush (options_.info_log );
276
- }
280
+ BackupEngineImpl::~BackupEngineImpl () { LogFlush (options_.info_log ); }
277
281
278
- void BackupEngine ::DeleteBackupsNewerThan (uint64_t sequence_number) {
282
+ void BackupEngineImpl ::DeleteBackupsNewerThan (uint64_t sequence_number) {
279
283
for (auto backup : backups_) {
280
284
if (backup.second .GetSequenceNumber () > sequence_number) {
281
285
Log (options_.info_log ,
@@ -295,7 +299,7 @@ void BackupEngine::DeleteBackupsNewerThan(uint64_t sequence_number) {
295
299
GarbageCollection (false );
296
300
}
297
301
298
- Status BackupEngine ::CreateNewBackup (DB* db, bool flush_before_backup) {
302
+ Status BackupEngineImpl ::CreateNewBackup (DB* db, bool flush_before_backup) {
299
303
Status s;
300
304
std::vector<std::string> live_files;
301
305
VectorLogPtr live_wal_files;
@@ -405,7 +409,7 @@ Status BackupEngine::CreateNewBackup(DB* db, bool flush_before_backup) {
405
409
return s;
406
410
}
407
411
408
- Status BackupEngine ::PurgeOldBackups (uint32_t num_backups_to_keep) {
412
+ Status BackupEngineImpl ::PurgeOldBackups (uint32_t num_backups_to_keep) {
409
413
Log (options_.info_log , " Purging old backups, keeping %u" ,
410
414
num_backups_to_keep);
411
415
while (num_backups_to_keep < backups_.size ()) {
@@ -418,7 +422,7 @@ Status BackupEngine::PurgeOldBackups(uint32_t num_backups_to_keep) {
418
422
return Status::OK ();
419
423
}
420
424
421
- Status BackupEngine ::DeleteBackup (BackupID backup_id) {
425
+ Status BackupEngineImpl ::DeleteBackup (BackupID backup_id) {
422
426
Log (options_.info_log , " Deleting backup %u" , backup_id);
423
427
auto backup = backups_.find (backup_id);
424
428
if (backup == backups_.end ()) {
@@ -431,7 +435,7 @@ Status BackupEngine::DeleteBackup(BackupID backup_id) {
431
435
return Status::OK ();
432
436
}
433
437
434
- void BackupEngine ::GetBackupInfo (std::vector<BackupInfo>* backup_info) {
438
+ void BackupEngineImpl ::GetBackupInfo (std::vector<BackupInfo>* backup_info) {
435
439
backup_info->reserve (backups_.size ());
436
440
for (auto & backup : backups_) {
437
441
if (!backup.second .Empty ()) {
@@ -441,9 +445,9 @@ void BackupEngine::GetBackupInfo(std::vector<BackupInfo>* backup_info) {
441
445
}
442
446
}
443
447
444
- Status BackupEngine ::RestoreDBFromBackup (BackupID backup_id,
445
- const std::string & db_dir,
446
- const std::string & wal_dir) {
448
+ Status BackupEngineImpl ::RestoreDBFromBackup (BackupID backup_id,
449
+ const std::string& db_dir,
450
+ const std::string& wal_dir) {
447
451
auto backup_itr = backups_.find (backup_id);
448
452
if (backup_itr == backups_.end ()) {
449
453
return Status::NotFound (" Backup not found" );
@@ -517,7 +521,7 @@ Status BackupEngine::RestoreDBFromBackup(BackupID backup_id,
517
521
}
518
522
519
523
// latest backup id is an ASCII representation of latest backup id
520
- Status BackupEngine ::GetLatestBackupFileContents (uint32_t * latest_backup) {
524
+ Status BackupEngineImpl ::GetLatestBackupFileContents (uint32_t * latest_backup) {
521
525
Status s;
522
526
unique_ptr<SequentialFile> file;
523
527
s = backup_env_->NewSequentialFile (GetLatestBackupFile (),
@@ -547,7 +551,7 @@ Status BackupEngine::GetLatestBackupFileContents(uint32_t* latest_backup) {
547
551
// writing 4 bytes to the file is atomic alright, but we should *never*
548
552
// do something like 1. delete file, 2. write new file
549
553
// We write to a tmp file and then atomically rename
550
- Status BackupEngine ::PutLatestBackupFileContents (uint32_t latest_backup) {
554
+ Status BackupEngineImpl ::PutLatestBackupFileContents (uint32_t latest_backup) {
551
555
Status s;
552
556
unique_ptr<WritableFile> file;
553
557
EnvOptions env_options;
@@ -577,14 +581,11 @@ Status BackupEngine::PutLatestBackupFileContents(uint32_t latest_backup) {
577
581
return s;
578
582
}
579
583
580
- Status BackupEngine::CopyFile (const std::string& src,
581
- const std::string& dst,
582
- Env* src_env,
583
- Env* dst_env,
584
- bool sync,
585
- uint64_t * size,
586
- uint32_t * checksum_value,
587
- uint64_t size_limit) {
584
+ Status BackupEngineImpl::CopyFile (const std::string& src,
585
+ const std::string& dst, Env* src_env,
586
+ Env* dst_env, bool sync, uint64_t * size,
587
+ uint32_t * checksum_value,
588
+ uint64_t size_limit) {
588
589
Status s;
589
590
unique_ptr<WritableFile> dst_file;
590
591
unique_ptr<SequentialFile> src_file;
@@ -644,12 +645,10 @@ Status BackupEngine::CopyFile(const std::string& src,
644
645
}
645
646
646
647
// src_fname will always start with "/"
647
- Status BackupEngine::BackupFile (BackupID backup_id,
648
- BackupMeta* backup,
649
- bool shared,
650
- const std::string& src_dir,
651
- const std::string& src_fname,
652
- uint64_t size_limit) {
648
+ Status BackupEngineImpl::BackupFile (BackupID backup_id, BackupMeta* backup,
649
+ bool shared, const std::string& src_dir,
650
+ const std::string& src_fname,
651
+ uint64_t size_limit) {
653
652
654
653
assert (src_fname.size () > 0 && src_fname[0 ] == ' /' );
655
654
std::string dst_relative = src_fname.substr (1 );
@@ -697,10 +696,9 @@ Status BackupEngine::BackupFile(BackupID backup_id,
697
696
return s;
698
697
}
699
698
700
- Status BackupEngine::CalculateChecksum (const std::string& src,
701
- Env* src_env,
702
- uint64_t size_limit,
703
- uint32_t * checksum_value) {
699
+ Status BackupEngineImpl::CalculateChecksum (const std::string& src, Env* src_env,
700
+ uint64_t size_limit,
701
+ uint32_t * checksum_value) {
704
702
*checksum_value = 0 ;
705
703
if (size_limit == 0 ) {
706
704
size_limit = std::numeric_limits<uint64_t >::max ();
@@ -737,7 +735,7 @@ Status BackupEngine::CalculateChecksum(const std::string& src,
737
735
return s;
738
736
}
739
737
740
- void BackupEngine ::GarbageCollection (bool full_scan) {
738
+ void BackupEngineImpl ::GarbageCollection (bool full_scan) {
741
739
Log (options_.info_log , " Starting garbage collection" );
742
740
std::vector<std::string> to_delete;
743
741
for (auto & itr : backuped_file_infos_) {
@@ -817,7 +815,7 @@ void BackupEngine::GarbageCollection(bool full_scan) {
817
815
818
816
// ------- BackupMeta class --------
819
817
820
- Status BackupEngine ::BackupMeta::AddFile (const FileInfo& file_info) {
818
+ Status BackupEngineImpl ::BackupMeta::AddFile (const FileInfo& file_info) {
821
819
size_ += file_info.size ;
822
820
files_.push_back (file_info.filename );
823
821
@@ -840,7 +838,7 @@ Status BackupEngine::BackupMeta::AddFile(const FileInfo& file_info) {
840
838
return Status::OK ();
841
839
}
842
840
843
- void BackupEngine ::BackupMeta::Delete () {
841
+ void BackupEngineImpl ::BackupMeta::Delete () {
844
842
for (const auto & file : files_) {
845
843
auto itr = file_infos_->find (file);
846
844
assert (itr != file_infos_->end ());
@@ -860,7 +858,8 @@ void BackupEngine::BackupMeta::Delete() {
860
858
// <file2> <crc32(literal string)> <crc32_value>
861
859
// ...
862
860
// TODO: maybe add checksum?
863
- Status BackupEngine::BackupMeta::LoadFromFile (const std::string& backup_dir) {
861
+ Status BackupEngineImpl::BackupMeta::LoadFromFile (
862
+ const std::string& backup_dir) {
864
863
assert (Empty ());
865
864
Status s;
866
865
unique_ptr<SequentialFile> backup_meta_file;
@@ -927,7 +926,7 @@ Status BackupEngine::BackupMeta::LoadFromFile(const std::string& backup_dir) {
927
926
return s;
928
927
}
929
928
930
- Status BackupEngine ::BackupMeta::StoreToFile (bool sync) {
929
+ Status BackupEngineImpl ::BackupMeta::StoreToFile (bool sync) {
931
930
Status s;
932
931
unique_ptr<WritableFile> backup_meta_file;
933
932
EnvOptions env_options;
@@ -969,7 +968,8 @@ Status BackupEngine::BackupMeta::StoreToFile(bool sync) {
969
968
// --- BackupableDB methods --------
970
969
971
970
BackupableDB::BackupableDB (DB* db, const BackupableDBOptions& options)
972
- : StackableDB(db), backup_engine_(new BackupEngine(db->GetEnv (), options)) {
971
+ : StackableDB(db),
972
+ backup_engine_ (new BackupEngineImpl(db->GetEnv (), options)) {
973
973
if (options.share_table_files ) {
974
974
backup_engine_->DeleteBackupsNewerThan (GetLatestSequenceNumber ());
975
975
}
@@ -1003,7 +1003,7 @@ void BackupableDB::StopBackup() {
1003
1003
1004
1004
RestoreBackupableDB::RestoreBackupableDB (Env* db_env,
1005
1005
const BackupableDBOptions& options)
1006
- : backup_engine_(new BackupEngine (db_env, options)) {}
1006
+ : backup_engine_(new BackupEngineImpl (db_env, options)) {}
1007
1007
1008
1008
RestoreBackupableDB::~RestoreBackupableDB () {
1009
1009
delete backup_engine_;
0 commit comments