diff --git a/include/rocksdb/utilities/backupable_db.h b/include/rocksdb/utilities/backupable_db.h index bf3f919ae..57a8accdf 100644 --- a/include/rocksdb/utilities/backupable_db.h +++ b/include/rocksdb/utilities/backupable_db.h @@ -130,9 +130,41 @@ struct BackupInfo { int64_t timestamp; uint64_t size; + uint32_t number_files; + BackupInfo() {} - BackupInfo(BackupID _backup_id, int64_t _timestamp, uint64_t _size) - : backup_id(_backup_id), timestamp(_timestamp), size(_size) {} + + BackupInfo(BackupID _backup_id, int64_t _timestamp, uint64_t _size, + uint32_t _number_files) + : backup_id(_backup_id), timestamp(_timestamp), size(_size), + number_files(_number_files) {} +}; + +class BackupStatistics { + public: + BackupStatistics() { + number_success_backup = 0; + number_fail_backup = 0; + } + + BackupStatistics(uint32_t _number_success_backup, + uint32_t _number_fail_backup) + : number_success_backup(_number_success_backup), + number_fail_backup(_number_fail_backup) {} + + ~BackupStatistics() {} + + void IncrementNumberSuccessBackup(); + void IncrementNumberFailBackup(); + + uint32_t GetNumberSuccessBackup() const; + uint32_t GetNumberFailBackup() const; + + std::string ToString() const; + + private: + uint32_t number_success_backup; + uint32_t number_fail_backup; }; class BackupEngineReadOnly { diff --git a/utilities/backupable/backupable_db.cc b/utilities/backupable/backupable_db.cc index 4d1a9b76b..71248b47c 100644 --- a/utilities/backupable/backupable_db.cc +++ b/utilities/backupable/backupable_db.cc @@ -72,6 +72,27 @@ class BackupRateLimiter { }; } // namespace +void BackupStatistics::IncrementNumberSuccessBackup() { + number_success_backup++; +} +void BackupStatistics::IncrementNumberFailBackup() { + number_fail_backup++; +} + +uint32_t BackupStatistics::GetNumberSuccessBackup() const { + return number_success_backup; +} +uint32_t BackupStatistics::GetNumberFailBackup() const { + return number_fail_backup; +} + +std::string BackupStatistics::ToString() const { + char result[50]; + snprintf(result, sizeof(result), "# success backup: %u, # fail backup: %u", + GetNumberSuccessBackup(), GetNumberFailBackup()); + return result; +} + void BackupableDBOptions::Dump(Logger* logger) const { Log(logger, " Options.backup_dir: %s", backup_dir.c_str()); Log(logger, " Options.backup_env: %p", backup_env); @@ -144,6 +165,9 @@ class BackupEngineImpl : public BackupEngine { uint64_t GetSize() const { return size_; } + uint32_t GetNumberFiles() { + return files_.size(); + } void SetSequenceNumber(uint64_t sequence_number) { sequence_number_ = sequence_number; } @@ -288,6 +312,7 @@ class BackupEngineImpl : public BackupEngine { static const size_t kDefaultCopyFileBufferSize = 5 * 1024 * 1024LL; // 5MB size_t copy_file_buffer_size_; bool read_only_; + BackupStatistics backup_statistics_; }; BackupEngine* BackupEngine::NewBackupEngine( @@ -443,6 +468,8 @@ Status BackupEngineImpl::CreateNewBackup(DB* db, bool flush_before_backup) { new_backup.RecordTimestamp(); new_backup.SetSequenceNumber(sequence_number); + auto start_backup = backup_env_-> NowMicros(); + Log(options_.info_log, "Started the backup process -- creating backup %u", new_backup_id); @@ -507,6 +534,8 @@ Status BackupEngineImpl::CreateNewBackup(DB* db, bool flush_before_backup) { GetAbsolutePath(GetPrivateFileRel(new_backup_id, false))); } + auto backup_time = backup_env_->NowMicros() - start_backup; + if (s.ok()) { // persist the backup metadata on the disk s = new_backup.StoreToFile(options_.sync); @@ -537,9 +566,15 @@ Status BackupEngineImpl::CreateNewBackup(DB* db, bool flush_before_backup) { } } + if (s.ok()) { + backup_statistics_.IncrementNumberSuccessBackup(); + } if (!s.ok()) { + backup_statistics_.IncrementNumberFailBackup(); // clean all the files we might have created Log(options_.info_log, "Backup failed -- %s", s.ToString().c_str()); + Log(options_.info_log, "Backup Statistics %s\n", + backup_statistics_.ToString().c_str()); backups_.erase(new_backup_id); GarbageCollection(true); return s; @@ -549,6 +584,16 @@ Status BackupEngineImpl::CreateNewBackup(DB* db, bool flush_before_backup) { // in the LATEST_BACKUP file latest_backup_id_ = new_backup_id; Log(options_.info_log, "Backup DONE. All is good"); + + // backup_speed is in byte/second + double backup_speed = new_backup.GetSize() / (1.048576 * backup_time); + Log(options_.info_log, "Backup number of files: %u", + new_backup.GetNumberFiles()); + Log(options_.info_log, "Backup size: %lu bytes", new_backup.GetSize()); + Log(options_.info_log, "Backup time: %lu microseconds", backup_time); + Log(options_.info_log, "Backup speed: %.3f MB/s", backup_speed); + Log(options_.info_log, "Backup Statistics %s", + backup_statistics_.ToString().c_str()); return s; } @@ -584,8 +629,9 @@ void BackupEngineImpl::GetBackupInfo(std::vector* backup_info) { backup_info->reserve(backups_.size()); for (auto& backup : backups_) { if (!backup.second.Empty()) { - backup_info->push_back(BackupInfo( - backup.first, backup.second.GetTimestamp(), backup.second.GetSize())); + backup_info->push_back(BackupInfo( + backup.first, backup.second.GetTimestamp(), backup.second.GetSize(), + backup.second.GetNumberFiles())); } } }