diff --git a/src/storage/io/virtual_store.cpp b/src/storage/io/virtual_store.cpp index e26e4b367a..1bfadaabf2 100644 --- a/src/storage/io/virtual_store.cpp +++ b/src/storage/io/virtual_store.cpp @@ -116,70 +116,6 @@ String ToString(StorageType storage_type) { } } -Status RemoteStore::Init(StorageType storage_type, Map &config) { - // Init remote filesystem and local disk cache - storage_type_ = storage_type; - switch (storage_type) { - case StorageType::kMinio: { - auto iter = config.find("url"); - if (iter == config.end()) { - return Status::InvalidConfig("Missing MINIO 'URL'"); - } - String url = iter->second; - - iter = config.find("access_key"); - if (iter == config.end()) { - return Status::InvalidConfig("Missing MINIO 'access_key'"); - } - String access_key = iter->second; - - iter = config.find("secret_key"); - if (iter == config.end()) { - return Status::InvalidConfig("Missing MINIO 'secret_key'"); - } - String secret_key = iter->second; - - iter = config.find("enable_https"); - if (iter == config.end()) { - return Status::InvalidConfig("Missing MINIO 'enable_https'"); - } - String enable_https_str = iter->second; - bool enable_https{false}; - if (enable_https_str == "true") { - enable_https = true; - } else if (enable_https_str == "false") { - enable_https = false; - } else { - return Status::InvalidConfig(fmt::format("Invalid MINIO 'enable_https' value: {}", enable_https_str)); - } - - minio_base_url_ = MakeUnique(url, enable_https); - minio_provider_ = MakeUnique(access_key, secret_key); - minio_client_ = MakeUnique(*minio_base_url_, minio_provider_.get()); - break; - } - default: { - return Status::NotSupport(fmt::format("{} isn't support in virtual filesystem", ToString(storage_type))); - } - } - return Status::OK(); -} - -Status RemoteStore::UnInit() { - switch (storage_type_) { - case StorageType::kMinio: { - minio_base_url_.reset(); - minio_provider_.reset(); - minio_client_.reset(); - break; - } - default: { - return Status::NotSupport(fmt::format("{} isn't support in virtual filesystem", ToString(storage_type_))); - } - } - return Status::OK(); -} - Tuple, Status> VirtualStore::Open(const String &path, FileAccessMode access_mode) { i32 fd = -1; switch (access_mode) { @@ -485,7 +421,7 @@ i32 VirtualStore::MunmapFile(const String &file_path) { } // Remote storage -StorageType VirtualStore::storage_type_ = StorageType::kMinio; +StorageType VirtualStore::storage_type_ = StorageType::kInvalid; String VirtualStore::bucket_ = "infinity_bucket"; UniquePtr VirtualStore::s3_client_ = nullptr; @@ -497,6 +433,7 @@ Status VirtualStore::InitRemoteStore(StorageType storage_type, const String &bucket) { switch (storage_type) { case StorageType::kMinio: { + storage_type_ = StorageType::kMinio; s3_client_ = MakeUnique(URL, HTTPS, access_key, secret_key); } default: { @@ -507,6 +444,16 @@ Status VirtualStore::InitRemoteStore(StorageType storage_type, return Status::OK(); } +Status VirtualStore::UnInitRemoteStore() { + VirtualStore::storage_type_ = StorageType::kInvalid; + s3_client_.reset(); + return Status::OK(); +} + +bool VirtualStore::IsInit() { + return s3_client_.get() != nullptr; +} + Status VirtualStore::DownloadObject(const String &file_path, const String &object_name) { if (VirtualStore::storage_type_ == StorageType::kLocal) { return Status::OK(); diff --git a/src/storage/io/virtual_store.cppm b/src/storage/io/virtual_store.cppm index 84b83f8917..341dada829 100644 --- a/src/storage/io/virtual_store.cppm +++ b/src/storage/io/virtual_store.cppm @@ -49,21 +49,6 @@ export struct MmapInfo { SizeT rc_{}; }; -// Only one instance; -export class RemoteStore { -public: - Status Init(StorageType storage_type, Map &config); - Status UnInit(); - -private: - // Using by minio - StorageType storage_type_{StorageType::kLocal}; - - UniquePtr minio_base_url_{}; - UniquePtr minio_provider_{}; - UniquePtr minio_client_{}; -}; - export class VirtualStore { public: static Tuple, Status> Open(const String &path, FileAccessMode access_mode); @@ -92,6 +77,9 @@ public: const String &secret_key = "minioadmin", const String &bucket = "infinity_bucket"); + static Status UnInitRemoteStore(); + + static bool IsInit(); static Status DownloadObject(const String &file_dir, const String& object_name); static Status UploadObject(const String &file_dir, const String& object_name); static Status RemoveObject(const String &object_name); diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index ce8a9b31d0..cbba51deda 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -103,12 +103,13 @@ void Storage::SetStorageMode(StorageMode target_mode) { break; } case StorageType::kMinio: { - if (remote_store_ != nullptr) { + if (VirtualStore::IsInit()) { UnrecoverableError("remote storage system was initialized before."); } - Map configs; - configs.emplace("url", config_ptr_->ObjectStorageUrl()); - remote_store_->Init(StorageType::kMinio, configs); + Status status = VirtualStore::InitRemoteStore(StorageType::kMinio, config_ptr_->ObjectStorageUrl()); + if (!status.ok()) { + UnrecoverableError(status.message()); + } break; } default: { @@ -255,8 +256,7 @@ void Storage::SetStorageMode(StorageMode target_mode) { break; } case StorageType::kMinio: { - remote_store_->UnInit(); - remote_store_.reset(); + VirtualStore::UnInitRemoteStore(); break; } default: { @@ -340,8 +340,7 @@ void Storage::SetStorageMode(StorageMode target_mode) { break; } case StorageType::kMinio: { - remote_store_->UnInit(); - remote_store_.reset(); + VirtualStore::UnInitRemoteStore(); break; } default: { diff --git a/src/storage/storage.cppm b/src/storage/storage.cppm index 756cc856ac..3cd7c7d07e 100644 --- a/src/storage/storage.cppm +++ b/src/storage/storage.cppm @@ -50,8 +50,6 @@ public: [[nodiscard]] inline PersistenceManager *persistence_manager() noexcept { return persistence_manager_.get(); } - [[nodiscard]] inline RemoteStore *remote_store() noexcept { return remote_store_.get(); } - [[nodiscard]] inline BGTaskProcessor *bg_processor() const noexcept { return bg_processor_.get(); } [[nodiscard]] inline PeriodicTriggerThread *periodic_trigger_thread() const noexcept { return periodic_trigger_thread_.get(); } @@ -77,7 +75,6 @@ private: UniquePtr txn_mgr_{}; UniquePtr wal_mgr_{}; UniquePtr persistence_manager_{}; - UniquePtr remote_store_{}; UniquePtr bg_processor_{}; UniquePtr compact_processor_{}; UniquePtr periodic_trigger_thread_{};