From cf7498fa5018b49c93362fb866b83e352071622b Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 22 Jan 2024 14:40:23 +0800 Subject: [PATCH] optimize plugin fuction Signed-off-by: mazhao --- .../interfaces/include/kv_store_nb_delegate.h | 2 +- .../interfaces/include/runtime_config.h | 20 ++++++++++++++++++- .../src/kv_store_delegate_manager.cpp | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h index f33bb86655b..ab63a3297eb 100644 --- a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h +++ b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h @@ -55,7 +55,7 @@ public: uint8_t compressionRate = 100; // Valid in [1, 100]. bool syncDualTupleMode = false; // communicator label use dualTuple hash or not bool localOnly = false; // active sync module - std::string storageEngineType = SQLITE; // use gaussdb_rd as storage engine + mutable std::string storageEngineType = SQLITE; // use gaussdb_rd as storage engine Rdconfig rdconfig; }; diff --git a/frameworks/libs/distributeddb/interfaces/include/runtime_config.h b/frameworks/libs/distributeddb/interfaces/include/runtime_config.h index f98fe90247b..3827ea9a99a 100644 --- a/frameworks/libs/distributeddb/interfaces/include/runtime_config.h +++ b/frameworks/libs/distributeddb/interfaces/include/runtime_config.h @@ -16,12 +16,13 @@ #ifndef RUNTIME_CONFIG_H #define RUNTIME_CONFIG_H +#include #include #include #include "auto_launch_export.h" -#include "db_info_handle.h" #include "cloud/icloud_data_translate.h" +#include "db_info_handle.h" #include "iprocess_communicator.h" #include "iprocess_system_api_adapter.h" #include "ithread_pool.h" @@ -31,6 +32,8 @@ enum class DBType { DB_KV, DB_RELATION, }; +static bool isFindRDLibrary; +static bool isAleadyFindOnce; class RuntimeConfig final { public: @@ -76,6 +79,21 @@ public: DB_API static void SetThreadPool(const std::shared_ptr &threadPool); DB_API static void SetCloudTranslate(const std::shared_ptr &dataTranslate); + + DB_API static bool isRDLibraryExist() + { + if (isAleadyFindOnce) { + return isFindRDLibrary; + } + void *libraryTmp = dlopen("/system/lib64/libgaussdb_rd.z.so", RTLD_LAZY); + if (!libraryTmp) { + isFindRDLibrary = false; + } else { + isFindRDLibrary = true; + } + isAleadyFindOnce = true; + return isFindRDLibrary; + } private: static std::mutex communicatorMutex_; static std::mutex multiUserMutex_; diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp index 9b2233f5dcf..c477bcca52f 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp @@ -303,6 +303,9 @@ bool KvStoreDelegateManager::GetKvStoreParamCheck(const std::string &storeId, co void KvStoreDelegateManager::GetKvStore(const std::string &storeId, const KvStoreNbDelegate::Option &option, const std::function &callback) { + if (!RuntimeConfig::isRDLibraryExist()) { + option.storageEngineType = SQLITE; // if cant find RD library, then do Sqlite process. + } if (!GetKvStoreParamCheck(storeId, option, callback)) { return; } -- Gitee