Fix db_id and db_session_id nullptr warning by clang analyzer (#7063)

Summary:
GetFileDbIdentities requires either db_id non-null or db_session_id non-null.
Passing nullptr for db_id or db_session_id in CopyOrCreateFile indicates the caller does not want to obtain the value for db_id or db_session_id.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7063

Test Plan:
USE_CLANG=1 make analyze
backupable_db_test

Reviewed By: pdillinger

Differential Revision: D22338497

Pulled By: gg814

fbshipit-source-id: 2aa2dcc14d156b0f99b07d6cf3c731ee088272cd
main
Zitan Chen 5 years ago committed by Facebook GitHub Bot
parent 5edfe3a3d8
commit b5bae48c8a
  1. 10
      utilities/backupable/backupable_db.cc

@ -1469,7 +1469,7 @@ Status BackupEngineImpl::CopyOrCreateFile(
// the restored file // the restored file
if (!src.empty()) { if (!src.empty()) {
// copying // copying
if (IsSstFile(src)) { if (IsSstFile(src) && (db_id != nullptr || db_session_id != nullptr)) {
// SST file // SST file
// Ignore the returned status // Ignore the returned status
// In the failed cases, db_id and db_session_id will be empty // In the failed cases, db_id and db_session_id will be empty
@ -1688,6 +1688,7 @@ Status BackupEngineImpl::GetFileDbIdentities(Env* src_env,
const std::string& file_path, const std::string& file_path,
std::string* db_id, std::string* db_id,
std::string* db_session_id) { std::string* db_session_id) {
assert(db_id != nullptr || db_session_id != nullptr);
// // Prepare the full_path of file_path under src_env for SstFileDumper // // Prepare the full_path of file_path under src_env for SstFileDumper
std::string full_path; std::string full_path;
src_env->GetAbsolutePath(file_path, &full_path); src_env->GetAbsolutePath(file_path, &full_path);
@ -1716,10 +1717,15 @@ Status BackupEngineImpl::GetFileDbIdentities(Env* src_env,
} }
if (table_properties != nullptr) { if (table_properties != nullptr) {
if (db_id != nullptr) {
db_id->assign(table_properties->db_id); db_id->assign(table_properties->db_id);
}
if (db_session_id != nullptr) {
db_session_id->assign(table_properties->db_session_id); db_session_id->assign(table_properties->db_session_id);
if (db_session_id->empty()) { if (db_session_id->empty()) {
return Status::NotFound("DB session identity not found in " + file_path); return Status::NotFound("DB session identity not found in " +
file_path);
}
} }
return Status::OK(); return Status::OK();
} else { } else {

Loading…
Cancel
Save