diff --git a/src/replica/replica_disk_migrator.cpp b/src/replica/replica_disk_migrator.cpp index 0cd8a12ccc..3dd56b16d9 100644 --- a/src/replica/replica_disk_migrator.cpp +++ b/src/replica/replica_disk_migrator.cpp @@ -251,7 +251,7 @@ bool replica_disk_migrator::migrate_replica_app_info(const replica_disk_migrate_ return false; }); replica_init_info init_info = _replica->get_app()->init_info(); - const auto &store_init_info_err = init_info.store(_target_replica_dir); + const auto &store_init_info_err = init_info.store(_target_replica_dir, dsn::utils::FileDataType::kSensitive); if (store_init_info_err != ERR_OK) { LOG_ERROR_PREFIX("disk migration(origin={}, target={}) stores app init info failed({})", req.origin_disk, diff --git a/src/replica/replication_app_base.cpp b/src/replica/replication_app_base.cpp index 6085bffc18..2eb8b9aeab 100644 --- a/src/replica/replication_app_base.cpp +++ b/src/replica/replication_app_base.cpp @@ -67,13 +67,13 @@ namespace replication { const std::string replica_init_info::kInitInfo = ".init-info"; namespace { -error_code write_blob_to_file(const std::string &fname, const blob &data) +error_code write_blob_to_file(const std::string &fname, const blob &data, const dsn::utils::FileDataType fileDataType) { // TODO(yingchun): consider not encrypt the meta files. std::string tmp_fname = fname + ".tmp"; auto cleanup = defer([tmp_fname]() { utils::filesystem::remove_path(tmp_fname); }); auto s = - rocksdb::WriteStringToFile(dsn::utils::PegasusEnv(dsn::utils::FileDataType::kSensitive), + rocksdb::WriteStringToFile(dsn::utils::PegasusEnv(fileDataType), rocksdb::Slice(data.data(), data.length()), tmp_fname, /* should_sync */ true); @@ -89,7 +89,7 @@ error_code write_blob_to_file(const std::string &fname, const blob &data) } } // namespace -error_code replica_init_info::load(const std::string &dir) +error_code replica_init_info::load(const std::string &dir, const dsn::utils::FileDataType fileDataType) { std::string info_path = utils::filesystem::path_combine(dir, kInitInfo); LOG_AND_RETURN_NOT_TRUE(ERROR, @@ -98,17 +98,17 @@ error_code replica_init_info::load(const std::string &dir) "file({}) not exist", info_path); LOG_AND_RETURN_NOT_OK( - ERROR, load_json(info_path), "load replica_init_info from {} failed", info_path); + ERROR, load_json(info_path, fileDataType), "load replica_init_info from {} failed", info_path); LOG_INFO("load replica_init_info from {} succeed: {}", info_path, to_string()); return ERR_OK; } -error_code replica_init_info::store(const std::string &dir) +error_code replica_init_info::store(const std::string &dir, const dsn::utils::FileDataType fileDataType) { uint64_t start = dsn_now_ns(); std::string info_path = utils::filesystem::path_combine(dir, kInitInfo); LOG_AND_RETURN_NOT_OK(ERROR, - store_json(info_path), + store_json(info_path, fileDataType), "store replica_init_info to {} failed, time_used_ns = {}", info_path, dsn_now_ns() - start); @@ -119,11 +119,11 @@ error_code replica_init_info::store(const std::string &dir) return ERR_OK; } -error_code replica_init_info::load_json(const std::string &fname) +error_code replica_init_info::load_json(const std::string &fname, const dsn::utils::FileDataType fileDataType) { std::string data; auto s = rocksdb::ReadFileToString( - dsn::utils::PegasusEnv(dsn::utils::FileDataType::kSensitive), fname, &data); + dsn::utils::PegasusEnv(fileDataType), fname, &data); LOG_AND_RETURN_NOT_TRUE(ERROR, s.ok(), ERR_FILE_OPERATION_FAILED, "read file {} failed", fname); LOG_AND_RETURN_NOT_TRUE(ERROR, json::json_forwarder::decode( @@ -134,9 +134,9 @@ error_code replica_init_info::load_json(const std::string &fname) return ERR_OK; } -error_code replica_init_info::store_json(const std::string &fname) +error_code replica_init_info::store_json(const std::string &fname, const dsn::utils::FileDataType fileDataType) { - return write_blob_to_file(fname, json::json_forwarder::encode(*this)); + return write_blob_to_file(fname, json::json_forwarder::encode(*this), fileDataType); } std::string replica_init_info::to_string() @@ -149,11 +149,11 @@ std::string replica_init_info::to_string() return oss.str(); } -error_code replica_app_info::load(const std::string &fname) +error_code replica_app_info::load(const std::string &fname, const dsn::utils::FileDataType fileDataType) { std::string data; auto s = rocksdb::ReadFileToString( - dsn::utils::PegasusEnv(dsn::utils::FileDataType::kSensitive), fname, &data); + dsn::utils::PegasusEnv(fileDataType), fname, &data); LOG_AND_RETURN_NOT_TRUE(ERROR, s.ok(), ERR_FILE_OPERATION_FAILED, "read file {} failed", fname); binary_reader reader(blob::create_from_bytes(std::move(data))); int magic = 0; @@ -164,7 +164,7 @@ error_code replica_app_info::load(const std::string &fname) return ERR_OK; } -error_code replica_app_info::store(const std::string &fname) +error_code replica_app_info::store(const std::string &fname, const dsn::utils::FileDataType fileDataType) { binary_writer writer; int magic = 0xdeadbeef; @@ -184,7 +184,7 @@ error_code replica_app_info::store(const std::string &fname) marshall(writer, tmp, DSF_THRIFT_JSON); } - return write_blob_to_file(fname, writer.get_buffer()); + return write_blob_to_file(fname, writer.get_buffer(), fileDataType); } /*static*/ diff --git a/src/replica/replication_app_base.h b/src/replica/replication_app_base.h index 5ae162a1bb..ffe211a688 100644 --- a/src/replica/replication_app_base.h +++ b/src/replica/replication_app_base.h @@ -71,13 +71,13 @@ class replica_init_info public: replica_init_info() { memset((void *)this, 0, sizeof(*this)); } - error_code load(const std::string &dir) WARN_UNUSED_RESULT; - error_code store(const std::string &dir); + error_code load(const std::string &dir, const dsn::utils::FileDataType fileDataType) WARN_UNUSED_RESULT; + error_code store(const std::string &dir, const dsn::utils::FileDataType fileDataType); std::string to_string(); private: - error_code load_json(const std::string &fname); - error_code store_json(const std::string &fname); + error_code load_json(const std::string &fname, const dsn::utils::FileDataType fileDataType); + error_code store_json(const std::string &fname, const dsn::utils::FileDataType fileDataType); }; class replica_app_info @@ -87,8 +87,8 @@ class replica_app_info public: replica_app_info(app_info *app) { _app = app; } - error_code load(const std::string &fname); - error_code store(const std::string &fname); + error_code load(const std::string &fname, const dsn::utils::FileDataType fileDataType); + error_code store(const std::string &fname, const dsn::utils::FileDataType fileDataType); }; /// The store engine interface of Pegasus. diff --git a/src/replica/test/replica_test.cpp b/src/replica/test/replica_test.cpp index 1da5b0060a..4a57d28ac1 100644 --- a/src/replica/test/replica_test.cpp +++ b/src/replica/test/replica_test.cpp @@ -239,7 +239,7 @@ class replica_test : public replica_test_base std::cout << "the path of .app-info file is " << path << std::endl; // load new max_replica_count from file - auto err = replica_info.load(path); + auto err = replica_info.load(path, dsn::utils::FileDataType::kSensitive); ASSERT_EQ(ERR_OK, err); ASSERT_EQ(info, _mock_replica->_app_info); std::cout << "the loaded new app_info is " << info << std::endl; @@ -249,7 +249,7 @@ class replica_test : public replica_test_base _app_info.max_replica_count = reserved_max_replica_count; // load original max_replica_count from file - err = replica_info.load(path); + err = replica_info.load(path, dsn::utils::FileDataType::kSensitive); ASSERT_EQ(err, ERR_OK); ASSERT_EQ(info, _mock_replica->_app_info); std::cout << "the loaded original app_info is " << info << std::endl;