diff --git a/frameworks/libs/distributeddb/distributeddb.gni b/frameworks/libs/distributeddb/distributeddb.gni index 620289b4b697a85b4533d18e24467136c696f92e..44d3df1b1c1aefa9f50e55e04a78cf85fc40f588 100755 --- a/frameworks/libs/distributeddb/distributeddb.gni +++ b/frameworks/libs/distributeddb/distributeddb.gni @@ -278,10 +278,10 @@ distributeddb_src_rd = [ "${distributeddb_path}/gaussdb_rd/src/executor/kv/grd_kv_api.cpp", "${distributeddb_path}/gaussdb_rd/src/executor/kv/grd_kv_api_inner.cpp", "${distributeddb_path}/gaussdb_rd/src/interface/src/collection.cpp", - "${distributeddb_path}/gaussdb_rd/src/interface/src/doc_errno.cpp", + "${distributeddb_path}/gaussdb_rd/src/interface/src/grd_store_errno.cpp", "${distributeddb_path}/gaussdb_rd/src/interface/src/document_key.cpp", - "${distributeddb_path}/gaussdb_rd/src/interface/src/document_store.cpp", - "${distributeddb_path}/gaussdb_rd/src/interface/src/document_store_manager.cpp", + "${distributeddb_path}/gaussdb_rd/src/interface/src/grd_store.cpp", + "${distributeddb_path}/gaussdb_rd/src/interface/src/grd_store_manager.cpp", "${distributeddb_path}/gaussdb_rd/src/interface/src/projection_tree.cpp", "${distributeddb_path}/gaussdb_rd/src/interface/src/result_set.cpp", "${distributeddb_path}/gaussdb_rd/src/interface/src/result_set_common.cpp", diff --git a/frameworks/libs/distributeddb/gaussdb_rd/BUILD.gn b/frameworks/libs/distributeddb/gaussdb_rd/BUILD.gn index 96499b75b064272d388b7ad38f4c775ef3e3118e..b6568598cc1c0c850598d157873d34db2eba3327 100755 --- a/frameworks/libs/distributeddb/gaussdb_rd/BUILD.gn +++ b/frameworks/libs/distributeddb/gaussdb_rd/BUILD.gn @@ -76,10 +76,10 @@ ohos_static_library("gaussdb_rd") { "src/executor/kv/grd_kv_api.cpp", "src/executor/kv/grd_kv_api_inner.cpp", "src/interface/src/collection.cpp", - "src/interface/src/doc_errno.cpp", + "src/interface/src/grd_store_errno.cpp", "src/interface/src/document_key.cpp", - "src/interface/src/document_store.cpp", - "src/interface/src/document_store_manager.cpp", + "src/interface/src/grd_store.cpp", + "src/interface/src/grd_store_manager.cpp", "src/interface/src/projection_tree.cpp", "src/interface/src/result_set.cpp", "src/interface/src/result_set_common.cpp", diff --git a/frameworks/libs/distributeddb/gaussdb_rd/include/grd_base/grd_db_api.h b/frameworks/libs/distributeddb/gaussdb_rd/include/grd_base/grd_db_api.h index 066581ef753914000751bfd8b53d421abd566abf..0f8af90f39c7823525a674ef36fd79363af95bc0 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/include/grd_base/grd_db_api.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/include/grd_base/grd_db_api.h @@ -34,6 +34,11 @@ GRD_API int32_t GRD_DBRestore(const char *dbFile, const char *backupDbFile, uint GRD_API int32_t GRD_IndexPreload(GRD_DB *db, const char *collectionName); GRD_API int32_t GRD_Flush(GRD_DB *db, uint32_t flags); + +GRD_API int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags); + +GRD_API int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags); + #ifdef __cplusplus } #endif // __cplusplus diff --git a/frameworks/libs/distributeddb/gaussdb_rd/include/grd_base/grd_type_export.h b/frameworks/libs/distributeddb/gaussdb_rd/include/grd_base/grd_type_export.h index b67478955ad11f242d5cbdbb6402a6de4cf01e17..00f4f7536bf77012554e7c015702c4cd52c3c823 100755 --- a/frameworks/libs/distributeddb/gaussdb_rd/include/grd_base/grd_type_export.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/include/grd_base/grd_type_export.h @@ -67,6 +67,7 @@ typedef enum KvScanMode { KV_SCAN_EQUAL_OR_LESS_KEY = 1, KV_SCAN_EQUAL_OR_GREATER_KEY = 2, KV_SCAN_RANGE = 3, + KV_SCAN_ALL = 4, KV_SCAN_BUTT } GRD_KvScanModeE; @@ -93,6 +94,36 @@ typedef struct GRD_KVBatch GRD_KVBatchT; #define GRD_DOC_APPEND 0 #define GRD_DOC_REPLACE 1 +typedef enum { + GRD_CONFIG_USER_VERSION, + GRD_CONFIG_DATA_VERSION, + GRD_CONFIG_BOTTOM, +} GRD_ConfigTypeE; + +typedef enum { + GRD_DB_DATATYPE_INTEGER = 0, + GRD_DB_DATATYPE_FLOAT, + GRD_DB_DATATYPE_TEXT, + GRD_DB_DATATYPE_BLOB, + GRD_DB_DATATYPE_FLOATVECTOR, + GRD_DB_DATATYPE_NULL, +} GRD_DbDataTypeE; + +typedef struct GRD_DbValueT { + GRD_DbDataTypeE type; + union { + int64_t longValue; + double doubleValue; + struct { + union { + const void *strAddr; + void *freeAddr; + }; + uint32_t length; + }; + } value; +} GRD_DbValueT; + #ifdef __cplusplus } #endif // __cplusplus diff --git a/frameworks/libs/distributeddb/gaussdb_rd/include/grd_document/grd_document_api.h b/frameworks/libs/distributeddb/gaussdb_rd/include/grd_document/grd_document_api.h index d01d54e56795f895c5cd6d7360042ab1de418774..68b807e0bf655a8934d6e8426ebe092be8087a9d 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/include/grd_document/grd_document_api.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/include/grd_document/grd_document_api.h @@ -25,10 +25,6 @@ extern "C" { #endif -GRD_API int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags); - -GRD_API int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags); - GRD_API int32_t GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, uint32_t flags); GRD_API int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_t flags, diff --git a/frameworks/libs/distributeddb/gaussdb_rd/include/grd_kv/grd_kv_api.h b/frameworks/libs/distributeddb/gaussdb_rd/include/grd_kv/grd_kv_api.h index 584b398a9106eeca6b21a0dad6ba0c16b9337d95..5c51fa957d7b94dfca53b6f464e4e0db4edb738a 100755 --- a/frameworks/libs/distributeddb/gaussdb_rd/include/grd_kv/grd_kv_api.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/include/grd_kv/grd_kv_api.h @@ -52,6 +52,8 @@ GRD_API int32_t GRD_KVBatchPut(GRD_DB *db, const char *collectionName, GRD_KVBat GRD_API int32_t GRD_KVBatchDel(GRD_DB *db, const char *collectionName, GRD_KVBatchT *batch); GRD_API int32_t GRD_KVBatchDestroy(GRD_KVBatchT *batch); + +GRD_API GRD_DbValueT GRD_GetConfig(GRD_DB *db, GRD_ConfigTypeE type); #ifdef __cplusplus } #endif diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/collection_option.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/collection_option.h index ddb4cf3cdfd36c067de436519e1ab3bb61edaf35..fa0360cd748add0bab2c58146ed987c94e0303ec 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/collection_option.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/collection_option.h @@ -17,8 +17,20 @@ #define COLLECTION_OPTION_H #include +#include "rd_json_object.h" + +namespace GRDDB { +enum CollectionType { + GRD_COLLECTION_DOCUMENT, + GRD_COLLECTION_KV, + GRD_COLLECTION_UNDEFINED +}; + +enum IndexType { + GRD_INDEX_BTREE, + GRD_INDEX_HASH +}; -namespace DocumentDB { class CollectionOption final { public: static CollectionOption ReadOption(const std::string &optStr, int &errCode); @@ -28,8 +40,13 @@ private: CollectionOption(const CollectionOption &collectionOption) = default; bool operator==(const CollectionOption &targetOption) const; bool operator!=(const CollectionOption &targetOption) const; + static CollectionOption GetValidOption(JsonObject collOpt, int &errCode); + static int GetValidOptionInner(JsonObject collOpt, const std::string &field, ValueObject value, + CollectionOption &option); std::string option_ = "{}"; uint32_t maxDoc_ = UINT32_MAX; + uint32_t collectionType_ = GRD_COLLECTION_DOCUMENT; + uint32_t indexType_ = GRD_INDEX_BTREE; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // COLLECTION_OPTION_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/db_config.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/db_config.h index cf74b253e513094f4fc55d30bb7fa215a263be46..3e88b3291779eca5384d4d951aadf8cadcc816d2 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/db_config.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/db_config.h @@ -18,7 +18,7 @@ #include -namespace DocumentDB { +namespace GRDDB { class DBConfig final { public: static DBConfig ReadConfig(const std::string &confStr, int &errCode); @@ -46,6 +46,7 @@ private: uint32_t bufferPoolSize_ = 1024; // 100: default 1024k pool size uint32_t crcCheckEnable_ = 1; uint32_t shareModeEnable_ = 0; + uint32_t metaInfoBak_ = 0; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // DB_CONFIG_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/doc_limit.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/doc_limit.h index fc2515f323e0e25c6af78f73b3e57930d62b60db..849129ef998f963d449089d59d19393bc1c00c86 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/doc_limit.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/doc_limit.h @@ -16,7 +16,7 @@ #ifndef DOC_LIMIT_H #define DOC_LIMIT_H -namespace DocumentDB { +namespace GRDDB { constexpr int MAX_DB_CONFIG_LEN = 1024 * 1024; // 1024 * 1024: 1024k length -} // namespace DocumentDB +} // namespace GRDDB #endif // DOC_LIMIT_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/document_type.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/document_type.h index 0c767b9aed79fd14136cfdbea0e9c33f38e475c3..a48a15ad09f292e6741053935a8c2ce334316877 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/document_type.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/document_type.h @@ -20,7 +20,7 @@ #include "projection_tree.h" -namespace DocumentDB { +namespace GRDDB { struct QueryContext { std::string collectionName; std::string filter; @@ -30,5 +30,5 @@ struct QueryContext { bool viewType = false; bool isIdExist = false; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // DOCUMENT_TYPE_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/grd_api_manager.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/grd_api_manager.h index 7acb79c248fffae3705fcb84d8d4d1330be1e402..1f82e89968dde8df807d472dc994df89a0257477 100755 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/grd_api_manager.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/grd_api_manager.h @@ -18,7 +18,7 @@ #include "grd_base/grd_type_export.h" -namespace DocumentDB { +namespace GRDDB { typedef int32_t (*DBOpen)(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db); typedef int32_t (*DBClose)(GRD_DB *db, uint32_t flags); typedef int32_t (*DBBackup)(GRD_DB *db, const char *backupDbFile, GRD_CipherInfoT *cipherInfo); @@ -57,6 +57,9 @@ typedef int32_t (*KVBatchPushback)(const void *key, uint32_t keyLen, const void typedef int32_t (*KVBatchPut)(GRD_DB *db, const char *collectionName, GRD_KVBatchT *batch); typedef int32_t (*KVBatchDel)(GRD_DB *db, const char *collectionName, GRD_KVBatchT *batch); typedef int32_t (*KVBatchDestory)(GRD_KVBatchT *batch); +typedef GRD_DbValueT (*GetConfig)(GRD_DB *db, GRD_ConfigTypeE type); +typedef int32_t (*DBRepair)(const char *dbFile, const char *configStr); + struct GRD_APIInfo { DBOpen DBOpenApi = nullptr; DBClose DBCloseApi = nullptr; @@ -90,8 +93,10 @@ struct GRD_APIInfo { KVBatchDel KVBatchPutApi = nullptr; KVBatchDel KVBatchDelApi = nullptr; KVBatchDestory KVBatchDestoryApi = nullptr; + GetConfig GetConfigApi = nullptr; + DBRepair DBRepairApi = nullptr; }; GRD_APIInfo GetApiInfoInstance(); void InitApiInfo(const char *configStr); -} // namespace DocumentDB +} // namespace GRDDB #endif // __cplusplus diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/json_common.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/json_common.h index b02231e7ea7941028e8850b54fd139cc4096eaa9..66a68a36378f8d0b9ccd981f679bebe0e6cb70e7 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/json_common.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/json_common.h @@ -23,7 +23,7 @@ #include "rd_json_object.h" -namespace DocumentDB { +namespace GRDDB { class JsonCommon { public: static ValueObject GetValueInSameLevel(JsonObject &node, const std::string &field); @@ -49,5 +49,5 @@ private: static bool IsObjectItemMatch(const JsonObject &srcItem, const JsonObject &item, int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag); }; -} // namespace DocumentDB +} // namespace GRDDB #endif // JSON_COMMON_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/os_api.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/os_api.h index 01f661c1b1aa3a3d1f9c16e6754fcbc72409a318..b05e45e344d9dcb91e802f094c7c29be86c835b6 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/os_api.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/os_api.h @@ -17,7 +17,7 @@ #include -namespace DocumentDB { +namespace GRDDB { namespace OSAPI { bool CheckPathPermission(const std::string &filePath); @@ -27,5 +27,5 @@ int GetRealPath(const std::string &inOriPath, std::string &outRealPath); void SplitFilePath(const std::string &filePath, std::string &fieldir, std::string &fileName); } // namespace OSAPI -} // namespace DocumentDB +} // namespace GRDDB #endif // OS_API_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_db_constant.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_db_constant.h index f2c1972d6889c5500a8126565bdadd0ac28f1a38..9fd36af09cbbc512aec4f3f9fa9b0e9f1e7d3d83 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_db_constant.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_db_constant.h @@ -18,10 +18,10 @@ #include -namespace DocumentDB { +namespace GRDDB { class RdDBConstant final { public: static constexpr const char *COLL_PREFIX = "GRD_COLL_"; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // DB_CONSTANT_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_log_print.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_log_print.h index 3e092f7ee06c8611c51a0c5b86b9f8d56273bf07..8eae62e55c0db4a13a0a55350a93fa26b0b41102 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_log_print.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_log_print.h @@ -18,7 +18,7 @@ #include -namespace DocumentDB { +namespace GRDDB { constexpr const char *LOG_TAG_DOC = "GAUSSDB_RD"; class RdLogPrint { @@ -33,7 +33,7 @@ public: static void Log(Level level, const char *tag, const char *format, ...); }; -} // namespace DocumentDB +} // namespace GRDDB #define NO_LOG(...) // No log in normal and release. Used for the convenience when deep debugging #define GLOGD(...) RdLogPrint::Log(RdLogPrint::Level::LEVEL_DEBUG, LOG_TAG_DOC, __VA_ARGS__) diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/collection_option.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/collection_option.cpp index 851b3f20e08ca4355948532e9477ab13e9677b20..bca85db44fad3b0647207889bdb7215076a8ab6e 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/collection_option.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/collection_option.cpp @@ -18,15 +18,19 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "rd_json_object.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { namespace { constexpr const char *OPT_MAX_DOC = "maxdoc"; constexpr const char *OPT_COLLECTION_MODE = "mode"; constexpr const char *KV_COLLECTION_MODE = "kv"; +constexpr const char *DOC_COLLECTION_MODE = "document"; +constexpr const char *OPT_INDEX_TYPE = "indextype"; +constexpr const char *INDEX_TYPE_HASH = "hash"; +constexpr const char *INDEX_TYPE_BTREE = "btree"; int CFG_IsValid(const JsonObject &config) { @@ -34,23 +38,97 @@ int CFG_IsValid(const JsonObject &config) while (!child.IsNull()) { std::string fieldName = child.GetItemField(); if (strcmp(OPT_COLLECTION_MODE, fieldName.c_str()) == 0) { - if (strcmp(child.GetItemValue().GetStringValue().c_str(), KV_COLLECTION_MODE) == 0) { // The value of mode - return -E_NOT_SUPPORT; - } else { + if (strcmp(child.GetItemValue().GetStringValue().c_str(), KV_COLLECTION_MODE) == 0 || + strcmp(child.GetItemValue().GetStringValue().c_str(), DOC_COLLECTION_MODE) == 0) { child = child.GetNext(); continue; + } else { + GLOGE("Create collection failed, config err, mode: %s", child.GetItemValue().GetStringValue().c_str()); + return -E_NOT_SUPPORT; } } if (strcmp(OPT_MAX_DOC, fieldName.c_str()) != 0) { GLOGE("Invalid collection config."); return -E_INVALID_CONFIG_VALUE; } + if (strcmp(OPT_INDEX_TYPE, fieldName.c_str()) == 0) { + if (strcmp(child.GetItemValue().GetStringValue().c_str(), INDEX_TYPE_BTREE) == 0 || + strcmp(child.GetItemValue().GetStringValue().c_str(), INDEX_TYPE_HASH) == 0) { + child = child.GetNext(); + continue; + } else { + GLOGE("Create collection failed, config err, idx: %s", child.GetItemValue().GetStringValue().c_str()); + return -E_NOT_SUPPORT; + } + } child = child.GetNext(); } return E_OK; } } // namespace +int CollectionOption::GetValidOptionInner(JsonObject collOpt, const std::string &field, ValueObject value, + CollectionOption &option) +{ + if (field == OPT_MAX_DOC) { + if (value.GetValueType() != ValueObject::ValueType::VALUE_NUMBER) { + GLOGE("Check collection option failed, the field type of maxDoc is not NUMBER."); + return -E_INVALID_CONFIG_VALUE; + } + if (value.GetIntValue() <= 0 || static_cast(value.GetIntValue()) > UINT32_MAX) { + GLOGE("Check collection option failed, invalid maxDoc value."); + return -E_INVALID_CONFIG_VALUE; + } + option.maxDoc_ = static_cast(value.GetIntValue()); + } + + if (field == OPT_COLLECTION_MODE) { + if (value.GetValueType() != ValueObject::ValueType::VALUE_STRING) { + GLOGE("Check collection option failed, the field type of mode is not STRING."); + return -E_INVALID_CONFIG_VALUE; + } + if (value.GetStringValue() != "document" || value.GetStringValue() != "kv") { + GLOGE("Check collection option failed, invalid mode value."); + return -E_INVALID_CONFIG_VALUE; + } + option.collectionType_ = value.GetStringValue() == "document" ? GRD_COLLECTION_DOCUMENT : GRD_COLLECTION_KV; + } + + if (field == OPT_INDEX_TYPE) { + if (value.GetValueType() != ValueObject::ValueType::VALUE_STRING) { + GLOGE("Check collection option failed, the field type of idx is not STRING."); + return -E_INVALID_CONFIG_VALUE; + } + if (value.GetStringValue() != "btree" || value.GetStringValue() != "hash") { + GLOGE("Check collection option failed, invalid mode value."); + return -E_INVALID_CONFIG_VALUE; + } + option.indexType_ = value.GetStringValue() == "btree" ? GRD_INDEX_BTREE : GRD_INDEX_HASH; + } + return E_OK; +} + +CollectionOption CollectionOption::GetValidOption(JsonObject collOpt, int &errCode) +{ + CollectionOption option; + static const JsonFieldPath collCigFields = { OPT_MAX_DOC, OPT_COLLECTION_MODE, OPT_INDEX_TYPE}; + for(const auto &field : collCigFields) { + const JsonFieldPath singleField = { field }; + if (collOpt.IsFieldExists(singleField)) { + ValueObject value = collOpt.GetObjectByPath(singleField, errCode); + if (errCode != E_OK) { + GLOGE("Read collection option %s failed. %d", field.c_str(), errCode); + return {}; + } + int errCode = GetValidOptionInner(collOpt, field, value, option); + if (errCode != E_OK) { + return {}; + } + } + } + return option; +} + CollectionOption CollectionOption::ReadOption(const std::string &optStr, int &errCode) { if (optStr.empty()) { @@ -73,33 +151,8 @@ CollectionOption CollectionOption::ReadOption(const std::string &optStr, int &er GLOGE("Check collection option, not support config item. %d", errCode); return {}; } - - static const JsonFieldPath maxDocField = { OPT_MAX_DOC }; - if (!collOpt.IsFieldExists(maxDocField)) { - return {}; - } - - ValueObject maxDocValue = collOpt.GetObjectByPath(maxDocField, errCode); - if (errCode != E_OK) { - GLOGE("Read collection option failed. %d", errCode); - return {}; - } - - if (maxDocValue.GetValueType() != ValueObject::ValueType::VALUE_NUMBER) { - GLOGE("Check collection option failed, the field type of maxDoc is not NUMBER."); - errCode = -E_INVALID_CONFIG_VALUE; - return {}; - } - - if (maxDocValue.GetIntValue() <= 0 || static_cast(maxDocValue.GetIntValue()) > UINT32_MAX) { - GLOGE("Check collection option failed, invalid maxDoc value."); - errCode = -E_INVALID_CONFIG_VALUE; - return {}; - } - - CollectionOption option; - option.maxDoc_ = static_cast(maxDocValue.GetIntValue()); + CollectionOption option = GetValidOption(collOpt, errCode); option.option_ = optStr; return option; } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/db_config.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/db_config.cpp index 8055d2856f5efe25086de43d7f9857474327c762..0ca331f3b65092c1ffb02fd7c7e2711412046799 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/db_config.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/db_config.cpp @@ -20,12 +20,12 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "doc_limit.h" #include "rd_json_object.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { namespace { constexpr int MIN_REDO_BUFFER_SIZE = 256; constexpr int MAX_REDO_BUFFER_SIZE = 16384; @@ -42,6 +42,7 @@ constexpr const char *DB_CONFIG_BUFFER_POOL_SIZE = "bufferpoolsize"; constexpr const char *DB_CONFIG_CRC_CHECK_ENABLE = "crccheckenable"; constexpr const char *DB_CONFIG_BUFFPOOL_POLICY = "bufferpoolpolicy"; constexpr const char *DB_CONFIG_SHARED_MODE = "sharedmodeenable"; +constexpr const char *DB_CONFIG_META_INFO_BAK = "metainfobak"; constexpr const char *DB_CONFIG[] = { DB_CONFIG_PAGESIZE, DB_CONFIG_REDO_FLUSH_BY_TRX, DB_CONFIG_REDO_PUB_BUFF_SIZE, DB_CONFIG_MAX_CONN_NUM, DB_CONFIG_BUFFER_POOL_SIZE, DB_CONFIG_CRC_CHECK_ENABLE, @@ -135,6 +136,14 @@ bool CheckShareModeConfig(const JsonObject &config, uint32_t &shareModeCheckEnab return CheckAndGetDBConfig(config, DB_CONFIG_SHARED_MODE, checkFunction, shareModeCheckEnable); } +bool CheckMetaInfoBakConfig(const JsonObject &config, uint32_t &metaInfoBak) +{ + std::function checkFunction = [](uint32_t val) { + return val == 0 || val == 1; + }; + return CheckAndGetDBConfig(config, DB_CONFIG_META_INFO_BAK, checkFunction, metaInfoBak); +} + int IsDbconfigValid(const JsonObject &config) { JsonObject child = config.GetChild(); @@ -216,6 +225,13 @@ DBConfig DBConfig::GetDBConfigFromJsonStr(const std::string &confStr, int &errCo return {}; } + if (!CheckMetaInfoBakConfig(dbConfig, conf.metaInfoBak_)) { + GLOGE("Check DB config 'MetaInfoBak' failed."); + errCode = -E_INVALID_CONFIG_VALUE; + return {}; + } + + conf.configStr_ = confStr; return conf; } @@ -254,7 +270,8 @@ bool DBConfig::operator==(const DBConfig &targetConfig) const { return pageSize_ == targetConfig.pageSize_ && redoFlushByTrx_ == targetConfig.redoFlushByTrx_ && redoPubBufSize_ == targetConfig.redoPubBufSize_ && maxConnNum_ == targetConfig.maxConnNum_ && - bufferPoolSize_ == targetConfig.bufferPoolSize_ && crcCheckEnable_ == targetConfig.crcCheckEnable_; + bufferPoolSize_ == targetConfig.bufferPoolSize_ && crcCheckEnable_ == targetConfig.crcCheckEnable_ && + metaInfoBak_ == targetConfig.metaInfoBak_; } bool DBConfig::operator!=(const DBConfig &targetConfig) const @@ -266,4 +283,4 @@ bool DBConfig::CheckPersistenceEqual(const DBConfig &targetConfig) const { return pageSize_ == targetConfig.pageSize_ && crcCheckEnable_ == targetConfig.crcCheckEnable_; } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/grd_api_manager.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/grd_api_manager.cpp index 4352bf1072de49cb2fa29fafb60dea71e66f5119..f552d026dfb29f0ebdf347f6bfc7d56830bb6999 100755 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/grd_api_manager.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/grd_api_manager.cpp @@ -20,8 +20,8 @@ #endif #include "check_common.h" -#include "doc_errno.h" -#include "document_store_manager.h" +#include "grd_store_errno.h" +#include "grd_store_manager.h" #include "grd_base/grd_error.h" #include "grd_db_api_inner.h" #include "grd_document_api_inner.h" @@ -37,7 +37,7 @@ static void *g_library = nullptr; static bool g_isGmdbLib = false; -namespace DocumentDB { +namespace GRDDB { void GRD_DBApiInitCommon(GRD_APIInfo &GRD_DBApiInfo) { GRD_DBApiInfo.DBOpenApi = GRD_DBOpenInner; @@ -70,6 +70,7 @@ void GRD_DBApiInitCommon(GRD_APIInfo &GRD_DBApiInfo) GRD_DBApiInfo.KVBatchPutApi = GRD_KVBatchPutInner; GRD_DBApiInfo.KVBatchDelApi = GRD_KVBatchDelInner; GRD_DBApiInfo.KVBatchDestoryApi = GRD_KVBatchDestroyInner; + GRD_DBApiInfo.DBRepairApi = GRD_DBRepairInner; } void GRD_DBApiInitEnhance(GRD_APIInfo &GRD_DBApiInfo) @@ -107,6 +108,7 @@ void GRD_DBApiInitEnhance(GRD_APIInfo &GRD_DBApiInfo) GRD_DBApiInfo.KVBatchPutApi = (KVBatchPut)dlsym(g_library, "GRD_KVBatchPut"); GRD_DBApiInfo.KVBatchDelApi = (KVBatchDel)dlsym(g_library, "GRD_KVBatchDel"); GRD_DBApiInfo.KVBatchDestoryApi = (KVBatchDestory)dlsym(g_library, "GRD_KVBatchDestroy"); + GRD_DBApiInfo.DBRepairApi = (DBRepair)dlsym(g_library, "GRD_DBRepair"); #endif } @@ -129,4 +131,4 @@ GRD_APIInfo GetApiInfoInstance() #endif return GRD_TempApiStruct; } -} // namespace DocumentDB +} // namespace GRDDB diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/json_common.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/json_common.cpp index 40b92e3fe6d31da203d5bd19e8d7e3cad49d5e9f..6c5e4a34c51d94ece227c39f7badf0f542b25ab7 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/json_common.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/json_common.cpp @@ -17,10 +17,10 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { ValueObject JsonCommon::GetValueInSameLevel(JsonObject &node, const std::string &field) { while (!node.IsNull()) { @@ -731,4 +731,4 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target }); return isMatchFlag; } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/os_api.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/os_api.cpp index d642f8b11093a35255b62fa2673b6fea29c3723f..d8cf96d705c1b764d00a6d29798c5d0c111439c0 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/os_api.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/os_api.cpp @@ -19,11 +19,11 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "rd_log_print.h" #include "securec.h" -namespace DocumentDB { +namespace GRDDB { namespace { const int ACCESS_MODE_EXISTENCE = 0; } @@ -89,4 +89,4 @@ void SplitFilePath(const std::string &filePath, std::string &fieldir, std::strin fileName = filePath.substr(slashPos + 1); } } // namespace OSAPI -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/rd_log_print.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/rd_log_print.cpp index 993880acdac6b1c365599a61340f200b2d9385ed..e59c094c3bc8c3599f6da073dfb3d73a8d921484 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/rd_log_print.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/rd_log_print.cpp @@ -18,7 +18,7 @@ #include "hilog/log.h" #include "securec.h" -namespace DocumentDB { +namespace GRDDB { namespace { void PrintLog(RdLogPrint::Level level, const char *tag, const std::string &msg) { @@ -79,4 +79,4 @@ void RdLogPrint::Log(Level level, const char *tag, const char *format, ...) PrintLog(level, tag, msg); } -} // namespace DocumentDB +} // namespace GRDDB diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/base/grd_db_api.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/base/grd_db_api.cpp index 07e5a1e8622b7064f81d40731e1f642eeffab7d3..1c9fef5c5f3cfb5fbda1c0071abf86c831d5ed49 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/base/grd_db_api.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/base/grd_db_api.cpp @@ -15,14 +15,14 @@ #include "grd_base/grd_db_api.h" #include "check_common.h" -#include "doc_errno.h" -#include "document_store_manager.h" +#include "grd_store_errno.h" +#include "grd_store_manager.h" #include "grd_api_manager.h" #include "grd_base/grd_error.h" #include "grd_type_inner.h" #include "rd_log_print.h" -using namespace DocumentDB; +using namespace GRDDB; static GRD_APIInfo GRD_DBApiInfo; GRD_API int32_t GRD_DBOpen(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db) @@ -100,3 +100,27 @@ GRD_API int32_t GRD_IndexPreload(GRD_DB *db, const char *collectionName) } return GRD_DBApiInfo.IndexPreloadApi(db, collectionName); } + +GRD_API int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags) +{ + if (GRD_DBApiInfo.CreateCollectionApi == nullptr) { + GRD_DBApiInfo = GetApiInfoInstance(); + } + if (GRD_DBApiInfo.CreateCollectionApi == nullptr) { + GLOGE("Fail to dlysm RD api symbol"); + return GRD_INNER_ERR; + } + return GRD_DBApiInfo.CreateCollectionApi(db, collectionName, optionStr, flags); +} + +GRD_API int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags) +{ + if (GRD_DBApiInfo.DropCollectionApi == nullptr) { + GRD_DBApiInfo = GetApiInfoInstance(); + } + if (GRD_DBApiInfo.DropCollectionApi == nullptr) { + GLOGE("Fail to dlysm RD api symbol"); + return GRD_INNER_ERR; + } + return GRD_DBApiInfo.DropCollectionApi(db, collectionName, flags); +} \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/base/grd_db_api_inner.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/base/grd_db_api_inner.cpp index fcf84320102dffcab1a763a2b878dce82fdd9985..223150e6e0acad6d46d04505ce3449c7cdd3c20e 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/base/grd_db_api_inner.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/base/grd_db_api_inner.cpp @@ -14,14 +14,14 @@ */ #include "grd_db_api_inner.h" #include "check_common.h" -#include "doc_errno.h" -#include "document_store_manager.h" +#include "grd_store_errno.h" +#include "grd_store_manager.h" #include "grd_api_manager.h" #include "grd_base/grd_error.h" #include "grd_type_inner.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { int32_t GRD_DBOpenInner(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db) { if (db == nullptr) { @@ -29,21 +29,21 @@ int32_t GRD_DBOpenInner(const char *dbPath, const char *configStr, uint32_t flag } std::string path = (dbPath == nullptr ? "" : dbPath); std::string config = (configStr == nullptr ? "" : configStr); - DocumentStore *store = nullptr; - int ret = DocumentStoreManager::GetDocumentStore(path, config, flags, store); + GRDStore *store = nullptr; + int ret = GRDStoreManager::GetGRDStore(path, config, flags, store); if (ret != E_OK || store == nullptr) { - return TransferDocErr(ret); + return TransToGRDErr(ret); } *db = new (std::nothrow) GRD_DB(); if (*db == nullptr) { - (void)DocumentStoreManager::CloseDocumentStore(store, GRD_DB_CLOSE_IGNORE_ERROR); + (void)GRDStoreManager::CloseGRDStore(store, GRD_DB_CLOSE_IGNORE_ERROR); store = nullptr; return GRD_FAILED_MEMORY_ALLOCATE; } (*db)->store_ = store; - return TransferDocErr(ret); + return TransToGRDErr(ret); } int32_t GRD_DBCloseInner(GRD_DB *db, uint32_t flags) @@ -52,9 +52,9 @@ int32_t GRD_DBCloseInner(GRD_DB *db, uint32_t flags) return GRD_INVALID_ARGS; } - int ret = DocumentStoreManager::CloseDocumentStore(db->store_, flags); + int ret = GRDStoreManager::CloseGRDStore(db->store_, flags); if (ret != E_OK) { - return TransferDocErr(ret); + return TransToGRDErr(ret); } db->store_ = nullptr; @@ -77,4 +77,4 @@ int32_t GRD_IndexPreloadInner(GRD_DB *db, const char *collectionName) { return GRD_OK; } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/check_common.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/check_common.cpp index d545c0e44def5af750a72f026028d5e3a37751e9..700fe0dfb5478413ecdc270318ec0d6142f99282 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/check_common.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/check_common.cpp @@ -17,13 +17,13 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "grd_base/grd_db_api.h" #include "rd_log_print.h" #include "securec.h" -using namespace DocumentDB; -namespace DocumentDB { +using namespace GRDDB; +namespace GRDDB { namespace { constexpr const char *KEY_ID = "_id"; constexpr const char *COLLECTION_PREFIX_GRD = "GRD_"; @@ -260,4 +260,4 @@ int CheckCommon::CheckProjection(JsonObject &projectionObj, std::vector; using Value = std::vector; -} // namespace DocumentDB +} // namespace GRDDB #endif // CHECK_COMMON_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_document_api.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_document_api.cpp index accc95d7bde8ca2b86630869bd618e8628fbcb77..38b40d8e208a4c15d72bc4a1ee47bf004e230608 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_document_api.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_document_api.cpp @@ -21,34 +21,10 @@ #include "grd_resultset_inner.h" #include "grd_type_inner.h" #include "rd_log_print.h" -using namespace DocumentDB; +using namespace GRDDB; static GRD_APIInfo GRD_DocApiInfo; -GRD_API int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags) -{ - if (GRD_DocApiInfo.CreateCollectionApi == nullptr) { - GRD_DocApiInfo = GetApiInfoInstance(); - } - if (GRD_DocApiInfo.CreateCollectionApi == nullptr) { - GLOGE("Fail to dlysm RD api symbol"); - return GRD_INNER_ERR; - } - return GRD_DocApiInfo.CreateCollectionApi(db, collectionName, optionStr, flags); -} - -GRD_API int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags) -{ - if (GRD_DocApiInfo.DropCollectionApi == nullptr) { - GRD_DocApiInfo = GetApiInfoInstance(); - } - if (GRD_DocApiInfo.DropCollectionApi == nullptr) { - GLOGE("Fail to dlysm RD api symbol"); - return GRD_INNER_ERR; - } - return GRD_DocApiInfo.DropCollectionApi(db, collectionName, flags); -} - GRD_API int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, uint32_t flags) { diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_document_api_inner.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_document_api_inner.cpp index fe4663b3d0e480a2ff8fbdda614e9817b682acde..c95ff50582e19098d20528b702852bc094b95dd4 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_document_api_inner.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_document_api_inner.cpp @@ -21,7 +21,7 @@ #include "grd_resultset_inner.h" #include "grd_type_inner.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { int32_t GRD_CreateCollectionInner(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { @@ -31,7 +31,7 @@ int32_t GRD_CreateCollectionInner(GRD_DB *db, const char *collectionName, const std::string name = (collectionName == nullptr ? "" : collectionName); std::string option = (optionStr == nullptr ? "" : optionStr); int ret = db->store_->CreateCollection(name, option, flags); - return TransferDocErr(ret); + return TransToGRDErr(ret); } int32_t GRD_DropCollectionInner(GRD_DB *db, const char *collectionName, uint32_t flags) @@ -42,7 +42,7 @@ int32_t GRD_DropCollectionInner(GRD_DB *db, const char *collectionName, uint32_t std::string name = (collectionName == nullptr ? "" : collectionName); int ret = db->store_->DropCollection(name, flags); - return TransferDocErr(ret); + return TransToGRDErr(ret); } int32_t GRD_UpdateDocInner(GRD_DB *db, const char *collectionName, const char *filter, const char *update, @@ -55,7 +55,7 @@ int32_t GRD_UpdateDocInner(GRD_DB *db, const char *collectionName, const char *f if (ret >= 0) { return ret; } - return TransferDocErr(ret); + return TransToGRDErr(ret); } int32_t GRD_UpsertDocInner(GRD_DB *db, const char *collectionName, const char *filter, const char *document, @@ -69,7 +69,7 @@ int32_t GRD_UpsertDocInner(GRD_DB *db, const char *collectionName, const char *f if (ret >= 0) { return ret; } - return TransferDocErr(ret); + return TransToGRDErr(ret); } int32_t GRD_InsertDocInner(GRD_DB *db, const char *collectionName, const char *document, uint32_t flags) @@ -78,7 +78,7 @@ int32_t GRD_InsertDocInner(GRD_DB *db, const char *collectionName, const char *d return GRD_INVALID_ARGS; } int ret = db->store_->InsertDocument(collectionName, document, flags); - return TransferDocErr(ret); + return TransToGRDErr(ret); } int32_t GRD_DeleteDocInner(GRD_DB *db, const char *collectionName, const char *filter, uint32_t flags) @@ -86,8 +86,8 @@ int32_t GRD_DeleteDocInner(GRD_DB *db, const char *collectionName, const char *f if (db == nullptr || db->store_ == nullptr || filter == nullptr || collectionName == nullptr) { return GRD_INVALID_ARGS; } - int ret = db->store_->DeleteDocument(collectionName, filter, flags); - int errCode = TransferDocErr(ret); + int ret = db->store_->DeleteDataByKey(collectionName, filter, flags); + int errCode = TransToGRDErr(ret); switch (errCode) { case GRD_OK: return 1; // The amount of text deleted @@ -107,14 +107,14 @@ int32_t GRD_FindDocInner(GRD_DB *db, const char *collectionName, Query query, ui GRD_ResultSet *grdResultSet = new (std::nothrow) GRD_ResultSet(); if (grdResultSet == nullptr) { GLOGE("Memory allocation failed!"); - return -E_FAILED_MEMORY_ALLOCATE; + return GRD_FAILED_MEMORY_ALLOCATE; } int ret = db->store_->FindDocument(collectionName, query.filter, query.projection, flags, grdResultSet); if (ret != E_OK) { delete grdResultSet; - return TransferDocErr(ret); + return TransToGRDErr(ret); } *resultSet = grdResultSet; - return TransferDocErr(ret); + return TransToGRDErr(ret); } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_resultset_api.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_resultset_api.cpp index 5e905677522a6c60a6d16c7c195ccde5d6b15ea2..08bbc74569c868f856a02cfc47d6b809f8af1c8a 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_resultset_api.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_resultset_api.cpp @@ -14,13 +14,13 @@ */ #include "grd_base/grd_resultset_api.h" -#include "doc_errno.h" +#include "grd_store_errno.h" #include "grd_api_manager.h" #include "grd_base/grd_error.h" #include "grd_resultset_inner.h" #include "rd_log_print.h" -using namespace DocumentDB; +using namespace GRDDB; static GRD_APIInfo GRD_ResultSetApiInfo; GRD_API int32_t GRD_Next(GRD_ResultSet *resultSet) diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_resultset_api_inner.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_resultset_api_inner.cpp index 5b0986037425dda6913747c3fceb756342e1c567..3b9a3777d493039b8c2af5fa7b4af0f1718dc537 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_resultset_api_inner.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/document/grd_resultset_api_inner.cpp @@ -14,13 +14,13 @@ */ #include "grd_resultset_api_inner.h" -#include "doc_errno.h" +#include "grd_store_errno.h" #include "grd_api_manager.h" #include "grd_base/grd_error.h" #include "grd_resultset_inner.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { int32_t GRD_NextInner(GRD_ResultSet *resultSet) { if (resultSet == nullptr) { @@ -28,7 +28,7 @@ int32_t GRD_NextInner(GRD_ResultSet *resultSet) return GRD_INVALID_ARGS; }; int ret = resultSet->resultSet_.GetNext(true, true); - return TransferDocErr(ret); + return TransToGRDErr(ret); } int32_t GRD_GetValueInner(GRD_ResultSet *resultSet, char **value) @@ -44,7 +44,7 @@ int32_t GRD_GetValueInner(GRD_ResultSet *resultSet, char **value) return GRD_NOT_AVAILABLE; } *value = val; - return TransferDocErr(ret); + return TransToGRDErr(ret); } int32_t GRD_FreeValueInner(char *value) @@ -75,4 +75,4 @@ int32_t GRD_FetchInner(GRD_ResultSet *resultSet, GRD_KVItemT *key, GRD_KVItemT * { return GRD_NOT_SUPPORT; } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_db_api_inner.h b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_db_api_inner.h index 0aafa77506d217a8262e9f3a7ce0e4d616325c3e..d747bef090ecdcccd4a12f6fc888cfde11bc064b 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_db_api_inner.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_db_api_inner.h @@ -17,7 +17,7 @@ #define GRD_DB_API_INNER_H #include #include "grd_base/grd_type_export.h" -namespace DocumentDB { +namespace GRDDB { int32_t GRD_DBOpenInner(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db); int32_t GRD_DBCloseInner(GRD_DB *db, uint32_t flags); @@ -25,5 +25,5 @@ int32_t GRD_DBCloseInner(GRD_DB *db, uint32_t flags); int32_t GRD_IndexPreloadInner(GRD_DB *db, const char *collectionName); int32_t GRD_FlushInner(GRD_DB *db, uint32_t flags); -} // namespace DocumentDB +} // namespace GRDDB #endif // GRD_DB_API_INNER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_document_api_inner.h b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_document_api_inner.h index 4011ede6107f8f76e2b68b44b85eb15b708eee36..d9034b5094046b87a696155e8347c0c4e6e3f7f3 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_document_api_inner.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_document_api_inner.h @@ -21,7 +21,7 @@ #include "grd_base/grd_resultset_api.h" #include "grd_base/grd_type_export.h" -namespace DocumentDB { +namespace GRDDB { int32_t GRD_CreateCollectionInner(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags); int32_t GRD_DropCollectionInner(GRD_DB *db, const char *collectionName, uint32_t flags); @@ -38,5 +38,5 @@ int32_t GRD_UpsertDocInner(GRD_DB *db, const char *collectionName, const char *f uint32_t flags); int32_t GRD_DeleteDocInner(GRD_DB *db, const char *collectionName, const char *filter, uint32_t flags); -} // namespace DocumentDB +} // namespace GRDDB #endif // GRD_DOCUMENT_API_INNER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_kv_api_inner.h b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_kv_api_inner.h index f4e7a83e130ce73b975f8901f504417ef2e74e75..22cad3f4661373d506b7a18d650d652da6efce43 100755 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_kv_api_inner.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_kv_api_inner.h @@ -21,7 +21,7 @@ #include "grd_base/grd_resultset_api.h" #include "grd_base/grd_type_export.h" -namespace DocumentDB { +namespace GRDDB { int32_t GRD_KVPutInner(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, const GRD_KVItemT *value); int32_t GRD_KVGetInner(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, const GRD_KVItemT *value); @@ -50,5 +50,7 @@ int32_t GRD_KVBatchPutInner(GRD_DB *db, const char *collectionName, GRD_KVBatchT int32_t GRD_KVBatchDelInner(GRD_DB *db, const char *collectionName, GRD_KVBatchT *batch); int32_t GRD_KVBatchDestroyInner(GRD_KVBatchT *batch); -} // namespace DocumentDB + +int32_t GRD_DBRepairInner(const char *dbFile, const char *configStr); +} // namespace GRDDB #endif // GRD_KV_API_INNER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_resultset_api_inner.h b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_resultset_api_inner.h index 6c4ca6811b5a5a18c8d79ff03924fdc4b539f742..48fe1f2e70a5e1c9b2db340879735a3f8bdbc066 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_resultset_api_inner.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_resultset_api_inner.h @@ -20,7 +20,7 @@ #include "grd_base/grd_type_export.h" -namespace DocumentDB { +namespace GRDDB { typedef struct GRD_ResultSet GRD_ResultSet; int32_t GRD_NextInner(GRD_ResultSet *resultSet); @@ -33,5 +33,5 @@ int32_t GRD_FetchInner(GRD_ResultSet *resultSet, GRD_KVItemT *key, GRD_KVItemT * int32_t GRD_FreeValueInner(char *value); int32_t GRD_FreeResultSetInner(GRD_ResultSet *resultSet); -} // namespace DocumentDB +} // namespace GRDDB #endif // GRD_RESULTSET_API_INNER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_resultset_inner.h b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_resultset_inner.h index d840ad79370a4cca20b76e5ed877aadde6d1eda8..678c7cc61963aaaf4014be3a1453717ff8aaa314 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_resultset_inner.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_resultset_inner.h @@ -16,11 +16,11 @@ #ifndef GRD_RESULTSET_INNER_H #define GRD_RESULTSET_INNER_H -#include "doc_errno.h" +#include "grd_store_errno.h" #include "grd_base/grd_error.h" #include "result_set.h" typedef struct GRD_ResultSet { - DocumentDB::ResultSet resultSet_; + GRDDB::ResultSet resultSet_; } GRD_ResultSet; #endif // GRD_RESULTSET_INNER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_sequence_api_inner.h b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_sequence_api_inner.h index 072f55e238b70ba0c3df0ccbbaf2f336fc8e0d1e..5d43a0eb7f5eb00b62228082b0add323afb8d624 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_sequence_api_inner.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_sequence_api_inner.h @@ -21,9 +21,9 @@ #include "grd_base/grd_resultset_api.h" #include "grd_base/grd_type_export.h" -namespace DocumentDB { +namespace GRDDB { int32_t GRD_CreateSeqInner(GRD_DB *db, const char *sequenceName, uint32_t flags); int32_t GRD_DropSeqInner(GRD_DB *db, const char *sequenceName, uint32_t flags); -} // namespace DocumentDB +} // namespace GRDDB #endif // GRD_SEQUENCE_API_INNER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_type_inner.h b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_type_inner.h index f26f6ac4897e2a80b7f347844a775f78208346a4..11ee40d5cb2400a1f7627d47a58846bf7a1c27de 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_type_inner.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/include/grd_type_inner.h @@ -16,12 +16,12 @@ #ifndef GRD_TYPE_INNER_H #define GRD_TYPE_INNER_H -#include "doc_errno.h" -#include "document_store.h" +#include "grd_store_errno.h" +#include "grd_store.h" #include "grd_base/grd_error.h" typedef struct GRD_DB { - DocumentDB::DocumentStore *store_ = nullptr; + GRDDB::GRDStore *store_ = nullptr; } GRD_DB; #endif // GRD_TYPE_INNER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/kv/grd_kv_api.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/kv/grd_kv_api.cpp index 7f441a65f69062b418eff6bf2e75a059bc2d84f7..75083ede2d239da18e3a6050e24397027d0d6d7e 100755 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/kv/grd_kv_api.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/kv/grd_kv_api.cpp @@ -19,7 +19,7 @@ #include "grd_resultset_inner.h" #include "grd_type_inner.h" #include "rd_log_print.h" -using namespace DocumentDB; +using namespace GRDDB; static GRD_APIInfo GRD_KVApiInfo; @@ -168,3 +168,26 @@ GRD_API int32_t GRD_KVBatchDestroy(GRD_KVBatchT *batch) } return GRD_KVApiInfo.KVBatchDestoryApi(batch); } + +GRD_API GRD_DbValueT GRD_GetConfig(GRD_DB *db, GRD_ConfigTypeE type) +{ + if (GRD_KVApiInfo.GetConfigApi == nullptr) { + GRD_KVApiInfo = GetApiInfoInstance(); + } + if (GRD_KVApiInfo.GetConfigApi == nullptr) { + GRD_DbValueT value = {.type = GRD_DB_DATATYPE_NULL, .value = {0}}; + return value; + } + return GRD_KVApiInfo.GetConfigApi(db, type); +} + +GRD_API int32_t GRD_DBRepair(const char *dbFile, const char *configStr) +{ + if (GRD_KVApiInfo.DBRepairApi == nullptr) { + GRD_KVApiInfo = GetApiInfoInstance(); + } + if (GRD_KVApiInfo.DBRepairApi == nullptr) { + return GRD_INNER_ERR; + } + return GRD_KVApiInfo.DBRepairApi(dbFile, configStr); +} \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/kv/grd_kv_api_inner.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/kv/grd_kv_api_inner.cpp index d491f828f7a5b54810cf65415721d91572463690..d3398423bbf9590d16bd3c6a175acc65f2e0de3b 100755 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/executor/kv/grd_kv_api_inner.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/executor/kv/grd_kv_api_inner.cpp @@ -17,22 +17,36 @@ #include "check_common.h" #include "grd_api_manager.h" #include "grd_base/grd_error.h" +#include "grd_resultset_inner.h" #include "grd_type_inner.h" #include "rd_log_print.h" -namespace DocumentDB { + +namespace GRDDB { int32_t GRD_KVPutInner(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, const GRD_KVItemT *value) { - return GRD_NOT_SUPPORT; + if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || key == nullptr || value == nullptr) { + return GRD_INVALID_ARGS; + } + int ret = db->store_->KVInsert(collectionName, key, value); + return TransToGRDErr(ret); } int32_t GRD_KVGetInner(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, const GRD_KVItemT *value) { - return GRD_NOT_SUPPORT; + if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || key == nullptr || value == nullptr) { + return GRD_INVALID_ARGS; + } + int ret = db->store_->KVGet(collectionName, key, value); + return TransToGRDErr(ret); } int32_t GRD_KVDelInner(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key) { - return GRD_NOT_SUPPORT; + if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || key == nullptr) { + return GRD_INVALID_ARGS; + } + int ret = db->store_->KVDelete(collectionName, key); + return TransToGRDErr(ret); } int32_t GRD_KVScanInner(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, GRD_KvScanModeE mode, @@ -44,22 +58,58 @@ int32_t GRD_KVScanInner(GRD_DB *db, const char *collectionName, const GRD_KVItem int32_t GRD_KVFilterInner(GRD_DB *db, const char *collectionName, const GRD_FilterOptionT *scanParams, GRD_ResultSet **resultSet) { - return GRD_NOT_SUPPORT; + if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || scanParams == nullptr || resultSet == nullptr) { + return GRD_INVALID_ARGS; + } + GRD_ResultSet *grdResultSet = new (std::nothrow) GRD_ResultSet(); + if (grdResultSet == nullptr) { + GLOGE("Memory allocation failed when kv filter!"); + return GRD_FAILED_MEMORY_ALLOCATE; + } + // todohbx: resultset已经创建,这里应该初始化result set,然后将result set返回, + int errCode = db->store_->KVFilter(collectionName, scanParams, grdResultSet); + if (errCode != E_OK) { + delete grdResultSet; + return TransToGRDErr(errCode); + } + *resultSet = grdResultSet; + return TransToGRDErr(errCode); } int32_t GRD_KVGetSizeInner(GRD_ResultSet *resultSet, uint32_t *keyLen, uint32_t *valueLen) { - return GRD_NOT_SUPPORT; + if (resultSet == nullptr || keyLen == nullptr || valueLen == nullptr) { + return GRD_INVALID_ARGS; + } + int errCode = resultSet->resultSet_.KVGetSize(keyLen, valueLen); + if (errCode != GRD_OK) { + GLOGE("failed to get size"); + return TransToGRDErr(errCode); + } + return TransToGRDErr(errCode); } int32_t GRD_GetItemInner(GRD_ResultSet *resultSet, void *key, void *value) { - return GRD_NOT_SUPPORT; + if (resultSet == nullptr || key == nullptr || value == nullptr) { + return GRD_INVALID_ARGS; + } + int errCode = resultSet->resultSet_.KVGetItem(key, value); + if (errCode != GRD_OK) { + GLOGE("failed to get size"); + return TransToGRDErr(errCode); + } + return TransToGRDErr(errCode); } int32_t GRD_KVFreeItemInner(GRD_KVItemT *item) { - return GRD_NOT_SUPPORT; + if (item == nullptr) { + return GRD_INVALID_ARGS; + } + // todohbx: make sure + free(item); + return GRD_OK; } int32_t GRD_KVBatchPrepareInner(uint16_t itemNum, GRD_KVBatchT **batch) @@ -87,4 +137,9 @@ int32_t GRD_KVBatchDestroyInner(GRD_KVBatchT *batch) { return GRD_NOT_SUPPORT; } -} // namespace DocumentDB \ No newline at end of file + +int32_t GRD_DBRepairInner(const char *dbFile, const char *configStr) +{ + return GRD_DATA_CORRUPTED; +} +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/collection.h b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/collection.h index 30d109eda401489efb6fed1ade829869290271bc..497ce253a09722acd1b3f7c78701e8108d681534 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/collection.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/collection.h @@ -21,25 +21,35 @@ #include "check_common.h" #include "kv_store_executor.h" -namespace DocumentDB { +namespace GRDDB { class Collection { public: Collection(const std::string &name, KvStoreExecutor *executor); ~Collection(); + /** + * Document api: + */ int InsertDocument(const std::string &id, const std::string &document, bool &isIdExist); int GetDocumentById(Key &key, Value &document) const; int GetMatchedDocument(const JsonObject &filterObj, Key &key, std::pair &values, int isIdExist) const; - int DeleteDocument(Key &key); + int DeleteDataByKey(Key &key); int IsCollectionExists(int &errCode); int UpsertDocument(const std::string &id, const std::string &newDocument, bool &isIdExist); int UpdateDocument(const std::string &id, const std::string &document); + /** + * Kv api: + */ + int InsertKv(Key &key, const Value &value); + int GetKv(Key &key, Value &value) const; + int GetAllKv(std::vector> &data); + private: int InsertUntilSuccess(Key &key, const std::string &id, Value &valSet); std::string name_; KvStoreExecutor *executor_ = nullptr; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // COLLECTION_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_key.h b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_key.h index dc20f5fc846a841426a2db775978143b2a234486..89292025f972f9fba84a672ccd974a739a77aef5 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_key.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_key.h @@ -27,7 +27,7 @@ #define GRD_DOC_OID_HEX_SIZE (GRD_DOC_OID_SIZE * 2) #define GRD_DOC_ID_TYPE_SIZE 1 -namespace DocumentDB { +namespace GRDDB { enum class DocIdType { INT = 1, STRING, @@ -44,5 +44,5 @@ class DocumentKey { public: static int GetOidDocKey(DocKey &key); }; -} // namespace DocumentDB +} // namespace GRDDB #endif // DOCUMENT_KEY_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_store.h b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/grd_store.h similarity index 76% rename from frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_store.h rename to frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/grd_store.h index 3f1deacb9279377a9e1f689672beeed5a83dd38e..784f7cd26dbaee2c83ba43ef96827928c4fead5c 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_store.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/grd_store.h @@ -22,32 +22,22 @@ #include "collection.h" #include "document_type.h" +#include "grd_base/grd_type_export.h" #include "kv_store_executor.h" struct GRD_ResultSet; -namespace DocumentDB { -class DocumentStore { +namespace GRDDB { +class GRDStore { public: - DocumentStore(KvStoreExecutor *); - ~DocumentStore(); - + GRDStore(KvStoreExecutor *); + ~GRDStore(); + /** + * Common api: + */ int CreateCollection(const std::string &name, const std::string &option, uint32_t flags); int DropCollection(const std::string &name, uint32_t flags); - int UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, - uint32_t flags); - - int UpsertDocument(const std::string &collection, const std::string &filter, const std::string &document, - uint32_t flags); - - int InsertDocument(const std::string &collection, const std::string &document, uint32_t flags); - - int DeleteDocument(const std::string &collection, const std::string &filter, uint32_t flags); - - int FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, - uint32_t flags, GRD_ResultSet *grdResultSet); - Collection GetCollection(std::string &collectionName); bool IsExistResultSet(const std::string &collection); @@ -64,9 +54,39 @@ public: bool IsCollectionExists(const std::string &collectionName, int &errCode); + /** + * Document api: + */ + int UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, + uint32_t flags); + + int UpsertDocument(const std::string &collection, const std::string &filter, const std::string &document, + uint32_t flags); + + int InsertDocument(const std::string &collection, const std::string &document, uint32_t flags); + + int DeleteDataByKey(const std::string &collection, const std::string &filter, uint32_t flags); + + int FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, + uint32_t flags, GRD_ResultSet *grdResultSet); + + /** + * Kv api: + */ + int KVInsert(const std::string &collection, const GRD_KVItemT *key, const GRD_KVItemT *value); + + int KVGet(const std::string &collection, const GRD_KVItemT *key, const GRD_KVItemT *value); + + int KVDelete(const std::string &collection, const GRD_KVItemT *key); + + int KVFilter( const char *collectionName, const GRD_FilterOptionT *scanParams, GRD_ResultSet *grdResultSet); + std::mutex dbMutex_; private: + /** + * Document private api: + */ int UpdateDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, const std::string &update, bool &isReplace); int UpsertDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, const std::string &document, @@ -75,9 +95,15 @@ private: bool &isIdExist); int DeleteDataFromDB(std::shared_ptr &context, JsonObject &filterObj); int InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr &context); + + /** + * Kv private api: + */ + std::vector KvItemToBlob(GRD_KVItemT &item); + KvStoreExecutor *executor_ = nullptr; std::map collections_; std::function closeNotifier_; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // DOCUMENT_STORE_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/doc_errno.h b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/grd_store_errno.h similarity index 92% rename from frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/doc_errno.h rename to frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/grd_store_errno.h index 4f8d1fe7e3cbd2ee3e67f2dedc7bf6bbe8ed9e24..52b7e0c9b2783eef5ab16c5072ab07bffba0238c 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/doc_errno.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/grd_store_errno.h @@ -13,10 +13,10 @@ * limitations under the License. */ -#ifndef DOC_ERRNO_H -#define DOC_ERRNO_H +#ifndef GRD_STORE_ERRNO_H +#define GRD_STORE_ERRNO_H -namespace DocumentDB { +namespace GRDDB { constexpr int E_OK = 0; constexpr int E_BASE = 1000; constexpr int E_ERROR = E_BASE + 1; @@ -43,6 +43,6 @@ constexpr int E_INVALID_FILE_FORMAT = E_BASE + 53; constexpr int E_FAILED_FILE_OPERATION = E_BASE + 54; constexpr int E_NOT_SUPPORT = E_BASE + 55; -int TransferDocErr(int err); -} // namespace DocumentDB -#endif // DOC_ERRNO_H \ No newline at end of file +int TransToGRDErr(int err); +} // namespace GRDDB +#endif // GRD_STORE_ERRNO_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_store_manager.h b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/grd_store_manager.h similarity index 67% rename from frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_store_manager.h rename to frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/grd_store_manager.h index f9745fae8f50083eec9824bfaee574ae2ceb5bcf..9d66b2bdefce26b27e9665b52154eb19ee03728f 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/document_store_manager.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/grd_store_manager.h @@ -13,21 +13,21 @@ * limitations under the License. */ -#ifndef DOCUMENT_STORE_MANAGER_H -#define DOCUMENT_STORE_MANAGER_H +#ifndef GRD_STORE_MANAGER_H +#define GRD_STORE_MANAGER_H #include #include -#include "document_store.h" +#include "grd_store.h" -namespace DocumentDB { -class DocumentStoreManager { +namespace GRDDB { +class GRDStoreManager { public: - static int GetDocumentStore(const std::string &path, const std::string &config, uint32_t flags, - DocumentStore *&store); + static int GetGRDStore(const std::string &path, const std::string &config, uint32_t flags, + GRDStore *&store); - static int CloseDocumentStore(DocumentStore *store, uint32_t flags); + static int CloseGRDStore(GRDStore *store, uint32_t flags); private: static int CheckDBPath(const std::string &path, std::string &canonicalPath, std::string &dbName); @@ -35,5 +35,5 @@ private: static std::mutex openCloseMutex_; static std::map dbConnCount_; }; -} // namespace DocumentDB -#endif // DOCUMENT_STORE_MANAGER_H \ No newline at end of file +} // namespace GRDDB +#endif // GRD_STORE_MANAGER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/projection_tree.h b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/projection_tree.h index 7d3b080b40c355b2554fe51319e3526376c45175..35673b73a3388b92458a20bbf1d2ee4899c17ff2 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/projection_tree.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/projection_tree.h @@ -19,11 +19,11 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "json_common.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { struct ProjectionNode { std::unordered_map sonNode; bool isDeepest; @@ -47,5 +47,5 @@ public: private: ProjectionNode node_; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // PROJECTION_TREE_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/result_set.h b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/result_set.h index a8a7e14cf7f52083b4a9670c0d9f9845143d88a1..b124511a9eaea41f6c448abcf0ec78e991bde5e0 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/result_set.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/result_set.h @@ -21,22 +21,33 @@ #include #include "check_common.h" -#include "doc_errno.h" -#include "document_store.h" +#include "grd_store_errno.h" +#include "grd_store.h" #include "grd_base/grd_type_export.h" #include "rd_json_object.h" -namespace DocumentDB { +namespace GRDDB { +enum GRD_ResultSetType { + DOCUMENT_RESULT_SET = 0, + KV_RESULT_SET +}; class ResultSet { public: ResultSet(); ~ResultSet(); - int Init(std::shared_ptr &context, DocumentStore *store, bool isCutBranch); + int Init(std::shared_ptr &context, GRDStore *store, bool isCutBranch); int GetNext(bool isNeedTransaction = false, bool isNeedCheckTable = false); int GetValue(char **value); int GetValue(std::string &value); int GetKey(std::string &key); int EraseCollection(); + /** + * Kv api: + */ + int InitKvResultSet(std::string collectionName, GRDStore *store); + int KVGetSize(uint32_t *keyLen, uint32_t *valueLen); + int KVGetItem(void *key, void *value); + int KVNext(); private: int GetNextInner(bool isNeedCheckTable); @@ -48,12 +59,22 @@ private: int CutJsonBranchInner(JsonObject &cjsonObj, bool viewType, bool isIdExistInValue, bool &isInsertIdflag); - DocumentStore *store_ = nullptr; + GRDStore *store_ = nullptr; bool isCutBranch_ = false; size_t index_ = 0; std::shared_ptr context_; std::pair matchData_; std::string lastKeyIndex_; + + /** + * Kv: + */ + std::string collectionName_; + size_t position_ = -1; + size_t maxPosition_ = 0; + std::vector> data_; + std::mutex mutex_; + int type_ = DOCUMENT_RESULT_SET; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // RESULTSET_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/result_set_common.h b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/result_set_common.h index abdf5c9b3ce66af2c112ed19fc54bb3fec633915..d2afe8b5ed87bbad797a1773d730885367784bb8 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/result_set_common.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/include/result_set_common.h @@ -18,13 +18,13 @@ #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "grd_base/grd_type_export.h" #include "result_set.h" #include "vector" -namespace DocumentDB { +namespace GRDDB { class ValueObject; -int InitResultSet(std::shared_ptr &context, DocumentStore *store, ResultSet &resultSet, bool isCutBranch); -} // namespace DocumentDB +int InitResultSet(std::shared_ptr &context, GRDStore *store, ResultSet &resultSet, bool isCutBranch); +} // namespace GRDDB #endif // RESULTSET_COMMON_H diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/collection.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/collection.cpp index 89f76030fff7edee29ad0fd05b4c5adde2b29c11..6173f1da97fe874e171b2468cf33c8283c383301 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/collection.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/collection.cpp @@ -17,11 +17,11 @@ #include "check_common.h" #include "rd_db_constant.h" -#include "doc_errno.h" +#include "grd_store_errno.h" #include "document_key.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { Collection::Collection(const std::string &name, KvStoreExecutor *executor) : executor_(executor) { std::string lowerCaseName = name; @@ -78,7 +78,7 @@ int Collection::GetDocumentById(Key &key, Value &document) const return executor_->GetDataById(name_, key, document); } -int Collection::DeleteDocument(Key &key) +int Collection::DeleteDataByKey(Key &key) { if (executor_ == nullptr) { return -E_INNER_ERROR; @@ -151,4 +151,37 @@ int Collection::UpdateDocument(const std::string &id, const std::string &newDocu Value valSet(newDocument.begin(), newDocument.end()); return executor_->PutData(name_, keyId, valSet); } -} // namespace DocumentDB + +int Collection::InsertKv(Key &key, const Value &value) +{ + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + int errCode = E_OK; + bool isCollectionExist = IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!isCollectionExist) { + return -E_INVALID_ARGS; + } + return executor_->PutData(name_, key, value); +} + +int Collection::GetKv(Key &key, Value &value) const +{ + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + return executor_->GetDataByKey(name_, key, value); +} + +int Collection::GetAllKv(std::vector> &data) +{ + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + return executor_->GetAllKvByOrder(name_, data); +} + +} // namespace GRDDB diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_key.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_key.cpp index 1666428a46607b50147e07d55dee7b4c4b2a5272..a1b1fb7f7f140deb6a87609153d2f8ef2165a9ce 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_key.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_key.cpp @@ -17,11 +17,11 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "rd_log_print.h" #include "securec.h" -namespace DocumentDB { +namespace GRDDB { static uint16_t g_oIdIncNum = 0; constexpr uint16_t MAX_NUMBER_OF_AUTOINCREMENTS = 65535; constexpr uint16_t UINT_ZERO = 0; @@ -53,4 +53,4 @@ int DocumentKey::GetOidDocKey(DocKey &key) int ret = InitDocIdFromOid(key); return ret; } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_store.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/grd_store.cpp similarity index 84% rename from frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_store.cpp rename to frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/grd_store.cpp index 9f4f9abbf160fc82e1016e1b3aeab4e9859d8e2c..2757bdfd04f2f43b38849500f94891487829be67 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_store.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/grd_store.cpp @@ -13,11 +13,11 @@ * limitations under the License. */ -#include "document_store.h" +#include "grd_store.h" #include "check_common.h" #include "collection_option.h" -#include "doc_errno.h" +#include "grd_store_errno.h" #include "document_key.h" #include "grd_base/grd_type_export.h" #include "grd_resultset_inner.h" @@ -25,18 +25,18 @@ #include "result_set.h" #include "result_set_common.h" -namespace DocumentDB { +namespace GRDDB { constexpr int JSON_LENS_MAX = 1024 * 1024; constexpr const char *KEY_ID = "_id"; -DocumentStore::DocumentStore(KvStoreExecutor *executor) : executor_(executor) {} +GRDStore::GRDStore(KvStoreExecutor *executor) : executor_(executor) {} -DocumentStore::~DocumentStore() +GRDStore::~GRDStore() { delete executor_; } -int DocumentStore::CreateCollection(const std::string &name, const std::string &option, uint32_t flags) +int GRDStore::CreateCollection(const std::string &name, const std::string &option, uint32_t flags) { std::string lowerCaseName; int errCode = E_OK; @@ -82,7 +82,7 @@ END: return errCode; } -int DocumentStore::DropCollection(const std::string &name, uint32_t flags) +int GRDStore::DropCollection(const std::string &name, uint32_t flags) { std::string lowerCaseName; int errCode = E_OK; @@ -205,7 +205,7 @@ int GetUpDataRePlaceData(ResultSet &resultSet, const std::string &id, const std: return errCode; } -int DocumentStore::UpdateDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, +int GRDStore::UpdateDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, const std::string &update, bool &isReplace) { std::lock_guard lock(dbMutex_); @@ -254,7 +254,7 @@ END: return (errCode == E_OK) ? count : errCode; } -int DocumentStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, +int GRDStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, uint32_t flags) { int errCode = UpdateArgsCheck(collection, filter, update, flags); @@ -379,7 +379,7 @@ int InsertIdToDocument(ResultSet &resultSet, JsonObject &filterObj, JsonObject & return errCode; } -int DocumentStore::UpsertDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, +int GRDStore::UpsertDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, const std::string &document, JsonObject &documentObj, bool &isReplace) { std::lock_guard lock(dbMutex_); @@ -442,7 +442,7 @@ int UpsertDocumentFormatCheck(const std::string &document, JsonObject &documentO return errCode; } -int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, +int GRDStore::UpsertDocument(const std::string &collection, const std::string &filter, const std::string &document, uint32_t flags) { int errCode = UpsertArgsCheck(collection, filter, document, flags); @@ -499,7 +499,7 @@ int InsertArgsCheck(const std::string &collection, const std::string &document, return errCode; } -int DocumentStore::InsertDataIntoDB(const std::string &collection, const std::string &document, +int GRDStore::InsertDataIntoDB(const std::string &collection, const std::string &document, JsonObject &documentObj, bool &isIdExist) { std::lock_guard lock(dbMutex_); @@ -517,7 +517,7 @@ int DocumentStore::InsertDataIntoDB(const std::string &collection, const std::st return coll.InsertDocument(id, document, isIdExist); } -int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, uint32_t flags) +int GRDStore::InsertDocument(const std::string &collection, const std::string &document, uint32_t flags) { int errCode = InsertArgsCheck(collection, document, flags); if (errCode != E_OK) { @@ -539,7 +539,7 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri int DeleteArgsCheck(const std::string &collection, const std::string &filter, uint32_t flags) { if (flags != 0u) { - GLOGE("DeleteDocument flags is not zero"); + GLOGE("DeleteDataByKey flags is not zero"); return -E_INVALID_ARGS; } std::string lowerCaseCollName; @@ -559,7 +559,7 @@ int DeleteArgsCheck(const std::string &collection, const std::string &filter, ui return errCode; } -int DocumentStore::DeleteDataFromDB(std::shared_ptr &context, JsonObject &filterObj) +int GRDStore::DeleteDataFromDB(std::shared_ptr &context, JsonObject &filterObj) { std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { @@ -584,7 +584,7 @@ int DocumentStore::DeleteDataFromDB(std::shared_ptr &context, Json END: if (errCode == E_OK) { Key key(id.begin(), id.end()); - errCode = coll.DeleteDocument(key); + errCode = coll.DeleteDataByKey(key); } if (errCode == E_OK || errCode == E_NOT_FOUND) { executor_->Commit(); @@ -593,7 +593,7 @@ END: } return errCode; } -int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, uint32_t flags) +int GRDStore::DeleteDataByKey(const std::string &collection, const std::string &filter, uint32_t flags) { int errCode = DeleteArgsCheck(collection, filter, flags); if (errCode != E_OK) { @@ -615,7 +615,7 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri context->collectionName = collection; return DeleteDataFromDB(context, filterObj); } -Collection DocumentStore::GetCollection(std::string &collectionName) +Collection GRDStore::GetCollection(std::string &collectionName) { return Collection(collectionName, executor_); } @@ -763,7 +763,7 @@ int FindProjectionInit(const std::string &projection, const std::shared_ptr &context) +int GRDStore::InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr &context) { std::lock_guard lock(dbMutex_); int errCode = E_OK; @@ -798,7 +798,7 @@ END: return errCode; } -int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, +int GRDStore::FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) { int errCode = FindArgsCheck(collection, filter, projection, flags); @@ -834,7 +834,7 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string return InitFindResultSet(grdResultSet, context); } -bool DocumentStore::IsExistResultSet(const std::string &collection) +bool GRDStore::IsExistResultSet(const std::string &collection) { if (collections_.find(collection) != collections_.end()) { GLOGE("DB is resource busy"); @@ -843,7 +843,7 @@ bool DocumentStore::IsExistResultSet(const std::string &collection) return false; } -int DocumentStore::EraseCollection(const std::string &collectionName) +int GRDStore::EraseCollection(const std::string &collectionName) { std::lock_guard lock(dbMutex_); if (collections_.find(collectionName) != collections_.end()) { @@ -854,12 +854,12 @@ int DocumentStore::EraseCollection(const std::string &collectionName) return E_INVALID_ARGS; } -void DocumentStore::OnClose(const std::function ¬ifier) +void GRDStore::OnClose(const std::function ¬ifier) { closeNotifier_ = notifier; } -int DocumentStore::Close(uint32_t flags) +int GRDStore::Close(uint32_t flags) { std::lock_guard lock(dbMutex_); if (flags == GRD_DB_CLOSE && !collections_.empty()) { @@ -873,21 +873,21 @@ int DocumentStore::Close(uint32_t flags) return E_OK; } -int DocumentStore::StartTransaction() +int GRDStore::StartTransaction() { if (executor_ == nullptr) { return -E_INNER_ERROR; } return executor_->StartTransaction(); } -int DocumentStore::Commit() +int GRDStore::Commit() { if (executor_ == nullptr) { return -E_INNER_ERROR; } return executor_->Commit(); } -int DocumentStore::Rollback() +int GRDStore::Rollback() { if (executor_ == nullptr) { return -E_INNER_ERROR; @@ -895,7 +895,7 @@ int DocumentStore::Rollback() return executor_->Rollback(); } -bool DocumentStore::IsCollectionExists(const std::string &collectionName, int &errCode) +bool GRDStore::IsCollectionExists(const std::string &collectionName, int &errCode) { if (executor_ == nullptr) { errCode = -E_INNER_ERROR; @@ -903,4 +903,86 @@ bool DocumentStore::IsCollectionExists(const std::string &collectionName, int &e } return executor_->IsCollectionExists(collectionName, errCode); } -} // namespace DocumentDB \ No newline at end of file + +int GRDStore::KVInsert(const std::string &collection, const GRD_KVItemT *key, const GRD_KVItemT *value) +{ + std::string lowerCaseCollName; + int errCode = E_OK; + if (!CheckCommon::CheckCollectionName(collection, lowerCaseCollName, errCode)) { + GLOGE("Check collection name invalid. %d", errCode); + return errCode; + } + Collection coll = Collection(collection, executor_); + Key blobKey = std::vector((uint8_t *)key->data, (uint8_t *)key->data + key->dataLen); + const Value blobValue = std::vector((uint8_t *)value->data, (uint8_t *)value->data + value->dataLen); + return coll.InsertKv(blobKey, blobValue); +} + +int GRDStore::KVGet(const std::string &collection, const GRD_KVItemT *key, const GRD_KVItemT *value) +{ + std::string lowerCaseCollName; + int errCode = E_OK; + if (!CheckCommon::CheckCollectionName(collection, lowerCaseCollName, errCode)) { + GLOGE("Check collection name invalid. %d", errCode); + return errCode; + } + Collection coll = Collection(collection, executor_); + Key blobKey = std::vector((uint8_t *)key->data, (uint8_t *)key->data + key->dataLen); + Value blobValue; + return coll.GetKv(blobKey, blobValue); +} + +int GRDStore::KVDelete(const std::string &collection, const GRD_KVItemT *key) +{ + std::string lowerCaseCollName; + int errCode = E_OK; + if (!CheckCommon::CheckCollectionName(collection, lowerCaseCollName, errCode)) { + GLOGE("Check collection name invalid. %d", errCode); + return errCode; + } + Collection coll = Collection(collection, executor_); + Key blobKey = std::vector((uint8_t *)key->data, (uint8_t *)key->data + key->dataLen); + return coll.DeleteDataByKey(blobKey); +} + +int GRDStore::KVFilter(const char *collectionName, const GRD_FilterOptionT *scanParams, GRD_ResultSet *grdResultSet) +{ + if (scanParams == nullptr || scanParams->mode != KV_SCAN_ALL) { + GLOGE("KVFilter failed, invalid scan params"); + return -E_INVALID_ARGS; + } + std::string lowerCaseCollName; + int errCode = E_OK; + if (!CheckCommon::CheckCollectionName(collectionName, lowerCaseCollName, errCode)) { + GLOGE("Check collection name invalid. %d", errCode); + return errCode; + } + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + + Collection coll = Collection(collectionName, executor_); + + errCode = executor_->StartTransaction(); + if (errCode != E_OK) { + return errCode; + } + if (!coll.IsCollectionExists(errCode)) { + errCode = -E_INVALID_ARGS; + } + if (errCode != E_OK) { + goto FILTER_END; + } + + errCode = grdResultSet->resultSet_.InitKvResultSet(collectionName, this); + +FILTER_END: + if (errCode == E_OK) { + executor_->Commit(); + } else { + executor_->Rollback(); + } + return errCode; +} + +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/doc_errno.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/grd_store_errno.cpp similarity index 96% rename from frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/doc_errno.cpp rename to frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/grd_store_errno.cpp index 3fe46256ee956983c0683154dfa244449fa4f555..7fbb6f1371df8802b533f4ae3bf2a89e2e2dad30 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/doc_errno.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/grd_store_errno.cpp @@ -13,11 +13,10 @@ * limitations under the License. */ -#include "doc_errno.h" - +#include "grd_store_errno.h" #include "grd_base/grd_error.h" -namespace DocumentDB { +namespace GRDDB { int GetErrorCategory(int errCode) { int categoryCode = errCode % 1000000; // 1000000: mod to get last 6 digits @@ -26,7 +25,7 @@ int GetErrorCategory(int errCode) return categoryCode; } -int TransferDocErr(int err) +int TransToGRDErr(int err) { if (err > 0) { return err; @@ -72,4 +71,4 @@ int TransferDocErr(int err) return GetErrorCategory(GRD_INNER_ERR); } } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_store_manager.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/grd_store_manager.cpp similarity index 86% rename from frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_store_manager.cpp rename to frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/grd_store_manager.cpp index 00a6a294f890f46177e14fc38a04ade82d4b8128..d44497698a2fde6b6cf84dc20fa359efee8263ec 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/document_store_manager.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/grd_store_manager.cpp @@ -13,16 +13,16 @@ * limitations under the License. */ -#include "document_store_manager.h" +#include "grd_store_manager.h" #include "db_config.h" -#include "doc_errno.h" +#include "grd_store_errno.h" #include "grd_base/grd_type_export.h" #include "kv_store_manager.h" #include "os_api.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { namespace { bool CheckDBOpenFlag(unsigned int flag) { @@ -46,11 +46,11 @@ bool CheckDBCreate(uint32_t flags, const std::string &path) } } // namespace -std::mutex DocumentStoreManager::openCloseMutex_; -std::map DocumentStoreManager::dbConnCount_; +std::mutex GRDStoreManager::openCloseMutex_; +std::map GRDStoreManager::dbConnCount_; -int DocumentStoreManager::GetDocumentStore(const std::string &path, const std::string &config, uint32_t flags, - DocumentStore *&store) +int GRDStoreManager::GetGRDStore(const std::string &path, const std::string &config, uint32_t flags, + GRDStore *&store) { std::string canonicalPath; std::string dbName; @@ -88,7 +88,7 @@ int DocumentStoreManager::GetDocumentStore(const std::string &path, const std::s return errCode; } - store = new (std::nothrow) DocumentStore(executor); + store = new (std::nothrow) GRDStore(executor); if (store == nullptr) { delete executor; GLOGE("Memory allocation failed!"); @@ -107,7 +107,7 @@ int DocumentStoreManager::GetDocumentStore(const std::string &path, const std::s return errCode; } -int DocumentStoreManager::CloseDocumentStore(DocumentStore *store, uint32_t flags) +int GRDStoreManager::CloseGRDStore(GRDStore *store, uint32_t flags) { if (!CheckDBCloseFlag(flags)) { GLOGE("Check document db close flags failed."); @@ -125,7 +125,7 @@ int DocumentStoreManager::CloseDocumentStore(DocumentStore *store, uint32_t flag return E_OK; } -int DocumentStoreManager::CheckDBPath(const std::string &path, std::string &canonicalPath, std::string &dbName) +int GRDStoreManager::CheckDBPath(const std::string &path, std::string &canonicalPath, std::string &dbName) { if (path.empty()) { GLOGE("Invalid path empty"); @@ -153,4 +153,4 @@ int DocumentStoreManager::CheckDBPath(const std::string &path, std::string &cano return E_OK; } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/projection_tree.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/projection_tree.cpp index f33d694f32c04c21f6bc3a1a9fa0196815d98ec8..042981ca18a425280b7a6d6fae6f3e2aca31a498 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/projection_tree.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/projection_tree.cpp @@ -14,7 +14,7 @@ */ #include "projection_tree.h" -namespace DocumentDB { +namespace GRDDB { constexpr int JSON_DEEP_MAX = 4; static int ParseSinglePathToTree(ProjectionNode *node, std::vector &singlePath) @@ -89,4 +89,4 @@ int ProjectionNode::DeleteProjectionNode() } return E_OK; } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/result_set.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/result_set.cpp index 439a5485682b884dd68ef416cb4d2e2b9a548ba7..bc47c24229e3cc675720907c7181f98714c4ec7d 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/result_set.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/result_set.cpp @@ -19,7 +19,7 @@ #include "rd_log_print.h" #include "securec.h" -namespace DocumentDB { +namespace GRDDB { constexpr const char *KEY_ID = "_id"; ResultSet::ResultSet() {} @@ -34,7 +34,7 @@ int ResultSet::EraseCollection() } return E_OK; } -int ResultSet::Init(std::shared_ptr &context, DocumentStore *store, bool isCutBranch) +int ResultSet::Init(std::shared_ptr &context, GRDStore *store, bool isCutBranch) { isCutBranch_ = isCutBranch; context_ = context; @@ -124,6 +124,9 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) int ResultSet::GetNext(bool isNeedTransaction, bool isNeedCheckTable) { + if (type_ == KV_RESULT_SET) { + return KVNext(); + } if (!isNeedTransaction) { return GetNextInner(isNeedCheckTable); } @@ -296,4 +299,59 @@ int ResultSet::CutJsonBranch(std::string &jsonKey, std::string &jsonData) jsonData = cjsonObj.Print(); return E_OK; } -} // namespace DocumentDB + +int ResultSet::InitKvResultSet(std::string collectionName, GRDStore *store) +{ + std::lock_guard lock(mutex_); + type_ = KV_RESULT_SET; + collectionName_ = collectionName; + store_ = store; + position_ = -1; + maxPosition_ = 0; + + // 获取所有数据 + Collection coll = store_->GetCollection(collectionName); + std::vector> data; + int errCode = coll.GetAllKv(data); + if (errCode != E_OK) { + return errCode; + } + + data_ = data; + maxPosition_ = data.size(); + return E_OK; +} + +int ResultSet::KVNext() +{ + std::lock_guard lock(mutex_); + if (data_.empty()) { + return -E_NOT_FOUND; + } + if (position_ >= (maxPosition_ - 1)) { + position_ = maxPosition_; + return -E_NOT_FOUND; + } + position_++; + return E_OK; +} + +int ResultSet::KVGetSize(uint32_t *keyLen, uint32_t *valueLen) +{ + if (data_.empty() || position_ < 0 || position_ >= maxPosition_ || data_.size() != maxPosition_) { + return -E_NOT_FOUND; + } + *keyLen = data_[position_].first.size(); + *valueLen = data_[position_].second.size(); + return E_OK; +} +int ResultSet::KVGetItem(void *key, void *value) +{ + if (data_.empty() || position_ < 0 || position_ >= maxPosition_ || data_.size() != maxPosition_) { + return -E_NOT_FOUND; + } + key = data_[position_].first.data(); + value = data_[position_].second.data(); + return E_OK; +} +} // namespace GRDDB diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/result_set_common.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/result_set_common.cpp index dd9acaeb265af70df00b0f7374f3d6df381c0c8f..d5d2ef37ede9b8fd3efdd4cde0ead7d8ef24930b 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/result_set_common.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/interface/src/result_set_common.cpp @@ -15,12 +15,12 @@ #include "result_set_common.h" #include "grd_format_config.h" -#include "doc_errno.h" +#include "grd_store_errno.h" #include "grd_base/grd_error.h" -namespace DocumentDB { +namespace GRDDB { class ValueObject; -int InitResultSet(std::shared_ptr &context, DocumentStore *store, ResultSet &resultSet, bool isCutBranch) +int InitResultSet(std::shared_ptr &context, GRDStore *store, ResultSet &resultSet, bool isCutBranch) { if (isCutBranch) { for (const auto &singlePath : context->projectionPath) { @@ -36,4 +36,4 @@ int InitResultSet(std::shared_ptr &context, DocumentStore *store, } return resultSet.Init(context, store, isCutBranch); } -} // namespace DocumentDB +} // namespace GRDDB diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/kv_store_executor.h b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/kv_store_executor.h index a12bda14fae0de0c52464b2369d96db5ca4c892f..fc84bdce819756963727ec47174543a924fa33b1 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/kv_store_executor.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/kv_store_executor.h @@ -20,7 +20,7 @@ #include "check_common.h" -namespace DocumentDB { +namespace GRDDB { class KvStoreExecutor { public: virtual ~KvStoreExecutor() = default; @@ -43,6 +43,8 @@ public: virtual int SetCollectionOption(const std::string &name, const std::string &option) = 0; virtual int CleanCollectionOption(const std::string &name) = 0; + + virtual int GetAllKvByOrder(const std::string &name, std::vector> &data) = 0; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // KV_STORE_EXECUTOR_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/kv_store_manager.h b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/kv_store_manager.h index 5589c20aa180f28794906eb74b7d7df82b516cf5..f6e7567bb8a2d7d6e3b81990f546127501bcddc5 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/kv_store_manager.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/kv_store_manager.h @@ -21,11 +21,11 @@ #include "db_config.h" #include "kv_store_executor.h" -namespace DocumentDB { +namespace GRDDB { class KvStoreManager { public: static int GetKvStore(const std::string &path, const DBConfig &config, bool isFirstOpen, KvStoreExecutor *&executor); }; -} // namespace DocumentDB +} // namespace GRDDB #endif // KV_STORE_MANAGER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/rd_json_object.h b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/rd_json_object.h index dad46abc339015afbdefe385718d34d4ea3f3f20..d925e7e3e9dc43d08b1fef91cef731cc3cdeeec9 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/rd_json_object.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/include/rd_json_object.h @@ -30,7 +30,7 @@ typedef void cJSON; #endif -namespace DocumentDB { +namespace GRDDB { class ValueObject { public: enum class ValueType { @@ -116,5 +116,5 @@ private: bool isOwner_ = false; bool caseSensitive_ = false; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // JSON_OBJECT_H diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp index 26fb8421780ef831154f0ea0bfc20132bdb87dde..03fef46ee347e96f19b850c85494b67b43560fe6 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp @@ -15,12 +15,12 @@ #include "kv_store_manager.h" -#include "doc_errno.h" +#include "grd_store_errno.h" #include "rd_log_print.h" #include "rd_sqlite_utils.h" #include "sqlite_store_executor_impl.h" -namespace DocumentDB { +namespace GRDDB { int KvStoreManager::GetKvStore(const std::string &path, const DBConfig &config, bool isFirstOpen, KvStoreExecutor *&executor) { @@ -70,4 +70,4 @@ END: delete sqliteExecutor; return errCode; } -} // namespace DocumentDB \ No newline at end of file +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_json_object.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_json_object.cpp index 1b469f2c410f16a5d33424e90e15945b8de6742c..2dfb69c74666e5aab4991ca02067119a3400d73d 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_json_object.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_json_object.cpp @@ -19,11 +19,11 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "json_common.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { #ifndef OMIT_cJSON ValueObject::ValueObject(bool val) { @@ -940,4 +940,4 @@ int JsonObject::DeleteItemDeeplyOnTarget(const JsonFieldPath &path) return E_OK; } #endif -} // namespace DocumentDB +} // namespace GRDDB diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_sqlite_utils.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_sqlite_utils.cpp index 27bef4c14adc5eb38126bf52a30b6d4323eb7f90..00252b3934b48f6c621d97e73b93acc283d7bb58 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_sqlite_utils.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_sqlite_utils.cpp @@ -16,10 +16,10 @@ #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "rd_log_print.h" -namespace DocumentDB { +namespace GRDDB { const int MAX_BLOB_READ_SIZE = 5 * 1024 * 1024; // 5M limit const int BUSY_TIMEOUT_MS = 3000; // 3000ms for sqlite busy timeout. const std::string BEGIN_SQL = "BEGIN TRANSACTION"; @@ -282,4 +282,48 @@ END: (void)RDSQLiteUtils::ResetStatement(stmt, true); return MapSqliteError(errCode); } -} // namespace DocumentDB + +int RDSQLiteUtils::GetBatchDataBySql(sqlite3 *db, const std::string &sql, + std::vector, std::vector>> &data) +{ + if (db == nullptr || sql.empty()) { + return -E_INVALID_ARGS; + } + sqlite3_stmt *statement = nullptr; + int errCode = RDSQLiteUtils::GetStatement(db, sql, statement); + if (errCode != E_OK) { // LCOV_EXCL_BR_LINE + return errCode; + } + + do { + errCode = RDSQLiteUtils::StepWithRetry(statement); + if (errCode == MapSqliteError(SQLITE_ROW)) { + std::vector key; + std::vector value; + errCode = RDSQLiteUtils::GetColumnBlobValue(statement, 0, key); + if (errCode != E_OK) { // LCOV_EXCL_BR_LINE + goto END; + } + + errCode = RDSQLiteUtils::GetColumnBlobValue(statement, 1, value); + if (errCode != E_OK) { // LCOV_EXCL_BR_LINE + goto END; + } + + data.push_back(std::make_pair(key, value)); + } else if (errCode == MapSqliteError(SQLITE_DONE)) { + break; + } else { + GLOGE("SQLite step failed:%d", errCode); + goto END; + } + } while (true); + + errCode = E_OK; + +END: + (void)RDSQLiteUtils::ResetStatement(statement, true); + return MapSqliteError(errCode); +} + +} // namespace GRDDB diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_sqlite_utils.h b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_sqlite_utils.h index 32e422c3847c4446976c42de851058f793b43b50..9cb5507114d99f8f8db77f2febc511f0276ce366 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_sqlite_utils.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/rd_sqlite_utils.h @@ -22,7 +22,7 @@ #include "sqlite3sym.h" -namespace DocumentDB { +namespace GRDDB { enum class TransactType { DEFERRED, IMMEDIATE, @@ -49,8 +49,11 @@ public: static int ExecSql(sqlite3 *db, const std::string &sql, const std::function &bindCallback, const std::function &resultCallback); + static int GetBatchDataBySql(sqlite3 *db, const std::string &sql, + std::vector, std::vector>> &data); + private: static void SqliteLogCallback(void *data, int err, const char *msg); }; -} // namespace DocumentDB +} // namespace GRDDB #endif // SQLITE_UTILS_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp index 5360652478ca81688766faf4b469fbf0a669d4d8..c28e8c557215ec9388260cdc0f836c3810e4fb25 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -17,12 +17,12 @@ #include "check_common.h" #include "rd_db_constant.h" -#include "doc_errno.h" +#include "grd_store_errno.h" #include "document_key.h" #include "rd_log_print.h" #include "rd_sqlite_utils.h" -namespace DocumentDB { +namespace GRDDB { constexpr const uint8_t KEY_TYPE = uint8_t(DocIdType::STRING); int SqliteStoreExecutorImpl::CreateDatabase(const std::string &path, const DBConfig &config, sqlite3 *&db) { @@ -409,4 +409,14 @@ int SqliteStoreExecutorImpl::CleanCollectionOption(const std::string &name) Key collOptKey = { collOptKeyStr.begin(), collOptKeyStr.end() }; return DelData("grd_meta", collOptKey); } -} // namespace DocumentDB \ No newline at end of file + +int SqliteStoreExecutorImpl::GetAllKvByOrder(const std::string &name, std::vector> &data) +{ + if (dbHandle_ == nullptr) { + return -E_INVALID_ARGS; + } + data.clear(); + std::string sql = "SELECT key, value FROM '" + name + "' ORDER BY KEY;"; + return RDSQLiteUtils::GetBatchDataBySql(dbHandle_, sql, data); +} +} // namespace GRDDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.h b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.h index 8da9ed30f3ddfe6ac1d7b71e96daf749665c73d6..ec5fdb3d7330f194652763e452c471b29acffcde 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.h @@ -21,7 +21,7 @@ #include "kv_store_executor.h" #include "sqlite3.h" -namespace DocumentDB { +namespace GRDDB { class SqliteStoreExecutorImpl : public KvStoreExecutor { public: static int CreateDatabase(const std::string &path, const DBConfig &config, sqlite3 *&db); @@ -52,8 +52,12 @@ public: int SetCollectionOption(const std::string &name, const std::string &option) override; int CleanCollectionOption(const std::string &name) override; + /** + * Kv api: + */ + int GetAllKvByOrder(const std::string &name, std::vector> &data) override; private: sqlite3 *dbHandle_ = nullptr; }; -} // namespace DocumentDB +} // namespace GRDDB #endif // SQLITE_STORE_EXECUTOR_IMPL_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/BUILD.gn b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/BUILD.gn index a23631f3df27468a0c38982376f88bf515c262ce..74b4be3391654d6fec43b97240b26358762dab92 100755 --- a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/BUILD.gn +++ b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/BUILD.gn @@ -61,10 +61,10 @@ ohos_source_set("src_file") { "../../src/executor/kv/grd_kv_api.cpp", "../../src/executor/kv/grd_kv_api_inner.cpp", "../../src/interface/src/collection.cpp", - "../../src/interface/src/doc_errno.cpp", + "../../src/interface/src/grd_store_errno.cpp", "../../src/interface/src/document_key.cpp", - "../../src/interface/src/document_store.cpp", - "../../src/interface/src/document_store_manager.cpp", + "../../src/interface/src/grd_store.cpp", + "../../src/interface/src/grd_store_manager.cpp", "../../src/interface/src/projection_tree.cpp", "../../src/interface/src/result_set.cpp", "../../src/interface/src/result_set_common.cpp", diff --git a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp index 7232eab6d8b25bc81f5e1d03eb13f75d1da58316..76a6186fcac0559f0b8a1524280248f28b2e1730 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp @@ -15,7 +15,7 @@ #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "doc_limit.h" #include "documentdb_test_utils.h" #include "grd_base/grd_db_api.h" @@ -24,7 +24,7 @@ #include "rd_log_print.h" #include "rd_sqlite_utils.h" -using namespace DocumentDB; +using namespace GRDDB; using namespace testing::ext; using namespace DocumentDBUnitTest; diff --git a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp index 1f9c8a67f46bd241604020c33310d58025c21178..cfe36263db6243181e0b12b1c780ca24b8b78d98 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp @@ -15,7 +15,7 @@ #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "documentdb_test_utils.h" #include "grd_base/grd_db_api.h" #include "grd_base/grd_error.h" @@ -23,7 +23,7 @@ #include "rd_log_print.h" #include "rd_sqlite_utils.h" -using namespace DocumentDB; +using namespace GRDDB; using namespace testing::ext; using namespace DocumentDBUnitTest; diff --git a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index d2f49d31fa7002611af8ad9a0280b4b7cd6b7879..b0b7c9b168366729b2517849b792ef9c67a1696b 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -16,7 +16,7 @@ #include #include "cJSON.h" -#include "doc_errno.h" +#include "grd_store_errno.h" #include "documentdb_test_utils.h" #include "grd_base/grd_db_api.h" #include "grd_base/grd_error.h" @@ -24,7 +24,7 @@ #include "rd_log_print.h" #include "rd_sqlite_utils.h" -using namespace DocumentDB; +using namespace GRDDB; using namespace testing::ext; using namespace DocumentDBUnitTest; diff --git a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index 44515ca6b43275908b51a46dbc5c38bbb0a41699..f07f89ba5a68f826620a184d1e3cc6bc8742de1d 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -17,7 +17,7 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "documentdb_test_utils.h" #include "grd_base/grd_db_api.h" #include "grd_base/grd_error.h" @@ -93,10 +93,10 @@ static void InsertData(GRD_DB *g_db, const char *collectionName) static void CompareValue(const char *value, const char *targetValue) { int errCode; - DocumentDB::JsonObject valueObj = DocumentDB::JsonObject::Parse(value, errCode); - EXPECT_EQ(errCode, DocumentDB::E_OK); - DocumentDB::JsonObject targetValueObj = DocumentDB::JsonObject::Parse(targetValue, errCode); - EXPECT_EQ(errCode, DocumentDB::E_OK); + GRDDB::JsonObject valueObj = GRDDB::JsonObject::Parse(value, errCode); + EXPECT_EQ(errCode, GRDDB::E_OK); + GRDDB::JsonObject targetValueObj = GRDDB::JsonObject::Parse(targetValue, errCode); + EXPECT_EQ(errCode, GRDDB::E_OK); EXPECT_EQ(valueObj.Print(), targetValueObj.Print()); } diff --git a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp index 4ad61a330809b8a9bb3a13353615c09b83332a91..53339e1404136f38f7da9b7a904f71e7cf049966 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp @@ -16,12 +16,12 @@ #include #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "documentdb_test_utils.h" #include "json_common.h" #include "rd_log_print.h" -using namespace DocumentDB; +using namespace GRDDB; using namespace testing::ext; using namespace DocumentDBUnitTest; diff --git a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp index 45e79c8dc125de61ab58ae94d37ccd882ffa64a1..e4d24be634ca2c28fbb53de208782d730e7744ca 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp @@ -15,11 +15,11 @@ #include -#include "doc_errno.h" +#include "grd_store_errno.h" #include "documentdb_test_utils.h" #include "rd_json_object.h" -using namespace DocumentDB; +using namespace GRDDB; using namespace testing::ext; using namespace DocumentDBUnitTest; diff --git a/frameworks/libs/distributeddb/test/BUILD.gn b/frameworks/libs/distributeddb/test/BUILD.gn index d564778816d2f15b4710e35da6e1f707a1761bd3..ea0aa68a5c201b57be213a1368eb18ca6880f411 100644 --- a/frameworks/libs/distributeddb/test/BUILD.gn +++ b/frameworks/libs/distributeddb/test/BUILD.gn @@ -142,10 +142,10 @@ ohos_source_set("src_file") { "../gaussdb_rd/src/executor/kv/grd_kv_api.cpp", "../gaussdb_rd/src/executor/kv/grd_kv_api_inner.cpp", "../gaussdb_rd/src/interface/src/collection.cpp", - "../gaussdb_rd/src/interface/src/doc_errno.cpp", + "../gaussdb_rd/src/interface/src/grd_store_errno.cpp", "../gaussdb_rd/src/interface/src/document_key.cpp", - "../gaussdb_rd/src/interface/src/document_store.cpp", - "../gaussdb_rd/src/interface/src/document_store_manager.cpp", + "../gaussdb_rd/src/interface/src/grd_store.cpp", + "../gaussdb_rd/src/interface/src/grd_store_manager.cpp", "../gaussdb_rd/src/interface/src/projection_tree.cpp", "../gaussdb_rd/src/interface/src/result_set.cpp", "../gaussdb_rd/src/interface/src/result_set_common.cpp", diff --git a/frameworks/libs/distributeddb/test/fuzztest/json_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/json_fuzzer/BUILD.gn index 48bf2bc8c10201dadda477f5c58b0e4511e5ab6d..8ee096d418d4f9532d4b2c1a752415cdb32ddeaf 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/json_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/json_fuzzer/BUILD.gn @@ -61,10 +61,10 @@ ohos_source_set("src_file") { "../../../gaussdb_rd/src/executor/kv/grd_kv_api.cpp", "../../../gaussdb_rd/src/executor/kv/grd_kv_api_inner.cpp", "../../../gaussdb_rd/src/interface/src/collection.cpp", - "../../../gaussdb_rd/src/interface/src/doc_errno.cpp", + "../../../gaussdb_rd/src/interface/src/grd_store_errno.cpp", "../../../gaussdb_rd/src/interface/src/document_key.cpp", - "../../../gaussdb_rd/src/interface/src/document_store.cpp", - "../../../gaussdb_rd/src/interface/src/document_store_manager.cpp", + "../../../gaussdb_rd/src/interface/src/grd_store.cpp", + "../../../gaussdb_rd/src/interface/src/grd_store_manager.cpp", "../../../gaussdb_rd/src/interface/src/projection_tree.cpp", "../../../gaussdb_rd/src/interface/src/result_set.cpp", "../../../gaussdb_rd/src/interface/src/result_set_common.cpp", diff --git a/frameworks/libs/distributeddb/test/fuzztest/json_fuzzer/json_fuzzer.cpp b/frameworks/libs/distributeddb/test/fuzztest/json_fuzzer/json_fuzzer.cpp index 8b4ff2d79c11e40bc7f0dfd01048ea3cb657934d..df00e982c3592eef691590ea7343902946cd8870 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/json_fuzzer/json_fuzzer.cpp +++ b/frameworks/libs/distributeddb/test/fuzztest/json_fuzzer/json_fuzzer.cpp @@ -1407,7 +1407,7 @@ void FreeResultSetFuzz() GRD_ResultSet *resultSet = nullptr; GRD_FreeResultSet(resultSet); resultSet = new GRD_ResultSet; - resultSet->resultSet_ = DocumentDB::ResultSet(); + resultSet->resultSet_ = GRDDB::ResultSet(); GRD_FreeResultSet(resultSet); GRD_DropCollection(g_db, COLLECTION_NAME, 0); } diff --git a/frameworks/libs/distributeddb/test/fuzztest/jsoninner_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/jsoninner_fuzzer/BUILD.gn index d3823c7e39afbae6409eb6aa3de3cb128376a7f8..663a74420c17512c999f54cbc7d6b354b4bdf35c 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/jsoninner_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/jsoninner_fuzzer/BUILD.gn @@ -61,10 +61,10 @@ ohos_source_set("src_file") { "../../../gaussdb_rd/src/executor/kv/grd_kv_api.cpp", "../../../gaussdb_rd/src/executor/kv/grd_kv_api_inner.cpp", "../../../gaussdb_rd/src/interface/src/collection.cpp", - "../../../gaussdb_rd/src/interface/src/doc_errno.cpp", + "../../../gaussdb_rd/src/interface/src/grd_store_errno.cpp", "../../../gaussdb_rd/src/interface/src/document_key.cpp", - "../../../gaussdb_rd/src/interface/src/document_store.cpp", - "../../../gaussdb_rd/src/interface/src/document_store_manager.cpp", + "../../../gaussdb_rd/src/interface/src/grd_store.cpp", + "../../../gaussdb_rd/src/interface/src/grd_store_manager.cpp", "../../../gaussdb_rd/src/interface/src/projection_tree.cpp", "../../../gaussdb_rd/src/interface/src/result_set.cpp", "../../../gaussdb_rd/src/interface/src/result_set_common.cpp", diff --git a/frameworks/libs/distributeddb/test/fuzztest/jsoninner_fuzzer/jsoninner_fuzzer.cpp b/frameworks/libs/distributeddb/test/fuzztest/jsoninner_fuzzer/jsoninner_fuzzer.cpp index d619d96602751698dc71b84775861800a7773ed6..f9f42aba4493776a96d375e9437497b8a63bda5a 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/jsoninner_fuzzer/jsoninner_fuzzer.cpp +++ b/frameworks/libs/distributeddb/test/fuzztest/jsoninner_fuzzer/jsoninner_fuzzer.cpp @@ -43,7 +43,7 @@ #include "grd_type_inner.h" #include "securec.h" -using namespace DocumentDB; +using namespace GRDDB; const char *TEST_DB = "./data"; const char *TEST_DB_FILE = "./data/testfile"; @@ -1416,7 +1416,7 @@ void FreeResultSetFuzz() GRD_ResultSet *resultSet = nullptr; GRD_FreeResultSetInner(resultSet); resultSet = new GRD_ResultSet; - resultSet->resultSet_ = DocumentDB::ResultSet(); + resultSet->resultSet_ = GRDDB::ResultSet(); GRD_FreeResultSetInner(resultSet); GRD_DropCollectionInner(g_db, COLLECTION_NAME, 0); }