diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp index 674dd3610af6e66cdb3ce8df3e15d566f237fc11..44ce39b6dfb9ef5060619d9432aec688433a0d1d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp @@ -27,12 +27,12 @@ namespace DocumentDB { namespace { -const int MIN_REDO_BUFFER_SIZE = 256; -const int MAX_REDO_BUFFER_SIZE = 16384; -const int MIN_CONNECTION_NUM = 16; -const int MAX_CONNECTION_NUM = 1024; -const int MIN_BUFFER_POOL_SIZE = 1024; -const int MAX_BUFFER_POOL_SIZE = 4 * 1024 * 1024; +constexpr int MIN_REDO_BUFFER_SIZE = 256; +constexpr int MAX_REDO_BUFFER_SIZE = 16384; +constexpr int MIN_CONNECTION_NUM = 16; +constexpr int MAX_CONNECTION_NUM = 1024; +constexpr int MIN_BUFFER_POOL_SIZE = 1024; +constexpr int MAX_BUFFER_POOL_SIZE = 4 * 1024 * 1024; constexpr const char *DB_CONFIG_PAGESIZE = "pagesize"; constexpr const char *DB_CONFIG_REDO_FLUSH_BY_TRX = "redoflushbytrx"; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 5b0d25615276f6d53d2744c9edbed71cf307b672..0706c64e1bcb301dba737c6a18165f3639cd75d2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -369,7 +369,7 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie while (!hitPath.empty()) { abandonPath.emplace_back(hitPath.back()); JsonObject srcFatherItem = src.FindItem(hitPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS) { + if (errCode == E_OK) { break; } if (!srcFatherItem.IsNull()) { @@ -412,7 +412,7 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie bool JsonValueReplace(const JsonObject &src, const JsonFieldPath &fatherPath, const JsonObject &father, const JsonObject &item, int &externErrCode) { - int errCode = 0; + int errCode = E_OK; JsonFieldPath granPaPath = fatherPath; if (!granPaPath.empty()) { granPaPath.pop_back(); @@ -453,7 +453,7 @@ bool JsonValueReplace(const JsonObject &src, const JsonFieldPath &fatherPath, co bool JsonNodeReplace(const JsonObject &src, const JsonFieldPath &itemPath, const JsonObject &father, const JsonObject &item, int &externErrCode) { - int errCode = 0; + int errCode = E_OK; JsonFieldPath fatherPath = itemPath; fatherPath.pop_back(); if (!fatherPath.empty()) { @@ -590,7 +590,7 @@ bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, i JsonObject srcChild = src.GetChild(); JsonObject targetObj = target; bool isMatch = false; - int errCode = 0; + int errCode = E_OK; while (!srcChild.IsNull()) { if (srcChild.GetType() == JsonObject::Type::JSON_OBJECT && target.GetType() == JsonObject::Type::JSON_OBJECT && (IsJsonNodeMatch(srcChild, target, errCode))) { // The return value reflects the value of errCode @@ -606,9 +606,11 @@ bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, i bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag) { - int errCode; + int errCode = E_OK; + // This function has only two error codes, and the other error + // code is not an exception, but the specified node was not found JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS && srcItem == item) { + if (errCode == E_OK && srcItem == item) { isMatchFlag = true; isAlreadyMatched = 1; return false; @@ -617,7 +619,7 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, std::string lastFieldName = granpaPath.back(); granpaPath.pop_back(); JsonObject granpaItem = src.FindItemPowerMode(granpaPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { + if (errCode == E_OK && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp index a45056d06c56b6e63c68e87a5848dcf160979146..1e6d04f2521cdfdb1dbccbc154f163353ff922fe 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp @@ -21,7 +21,7 @@ #include "log_print.h" namespace DocumentDB { -const int JSON_LENS_MAX = 1024 * 1024; +constexpr int JSON_LENS_MAX = 1024 * 1024; Collection::Collection(const std::string &name, KvStoreExecutor *executor) : executor_(executor) { @@ -158,9 +158,8 @@ int Collection::UpsertDocument(const std::string &id, const std::string &documen GLOGD("Append value failed. %d", errCode); return errCode; } - // kkk std::string valStr = originValue.Print(); - if (valStr.length() + 1 > JSON_LENS_MAX) { + if (valStr.length() >= JSON_LENS_MAX) { GLOGE("document's length is too long"); return -E_OVER_LIMIT; } @@ -214,7 +213,7 @@ int Collection::UpdateDocument(const std::string &id, const std::string &update, return errCode; } std::string valStr = originValue.Print(); - if (valStr.length() + 1 > JSON_LENS_MAX) { + if (valStr.length() >= JSON_LENS_MAX) { GLOGE("document's length is too long"); return -E_OVER_LIMIT; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index 1821dbb2bf018e347a0476e95f7439dfc0c66383..cf29ac15ed53e1bb3ad86ea237cc810ac32e091d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -24,7 +24,7 @@ #include "result_set_common.h" namespace DocumentDB { -const int JSON_LENS_MAX = 1024 * 1024; +constexpr int JSON_LENS_MAX = 1024 * 1024; constexpr const char *KEY_ID = "_id"; DocumentStore::DocumentStore(KvStoreExecutor *executor) : executor_(executor) {} diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp index 265ca61dcec0dcc62daf7b85ef320bd5f54efd16..94c56b6fe9468ea2c650750ba298a4d8b343c8a5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp @@ -15,7 +15,7 @@ #include "projection_tree.h" namespace DocumentDB { -const int JSON_DEEP_MAX = 4; +constexpr int JSON_DEEP_MAX = 4; int ProjectionTree::ParseTree(std::vector> &path) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 7d2fefb8ac1f9609fcee3f4e75f1ef88c2b36a36..e607ed65f85618c61776f179868ea17b270cf999 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -224,17 +224,12 @@ int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int if (subObj == nullptr) { return -E_INVALID_ARGS; } - int ret = E_OK; std::string fieldName; if (subObj->string != nullptr) { fieldName = subObj->string; } if (parentType == cJSON_Array) { - ret = CheckJsonRepeatField(subObj); - if (ret != E_OK) { - return ret; - } - return E_OK; + return CheckJsonRepeatField(subObj); } if (fieldName.empty()) { return -E_INVALID_JSON_FORMAT; @@ -242,16 +237,9 @@ int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int if (fieldSet.find(fieldName) == fieldSet.end()) { fieldSet.insert(fieldName); } else { - ret = -E_INVALID_JSON_FORMAT; - } - if (ret != E_OK) { - return ret; - } - ret = CheckJsonRepeatField(subObj); - if (ret != E_OK) { - return ret; + return -E_INVALID_JSON_FORMAT; } - return E_OK; + return CheckJsonRepeatField(subObj); } std::string JsonObject::Print() const @@ -512,11 +500,7 @@ std::string JsonObject::GetItemField() const std::string JsonObject::GetItemField(int &errCode) const { - if (cjson_ == nullptr) { - errCode = E_INVALID_ARGS; - return ""; - } - if (cjson_->string == nullptr) { + if (cjson_ == nullptr || cjson_->string == nullptr) { errCode = E_INVALID_ARGS; return ""; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp index 295dfb1765ee229c1f845e6b478e9efd3b4386d5..1de43e0dc0f6a83750cf3caaedf1758bcf34ff22 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -280,7 +280,7 @@ int SqliteStoreExecutorImpl::CreateCollection(const std::string &name, const std if (errCode != E_OK) { GLOGE("[sqlite executor] Set collection option failed. err=%d", errCode); } - return E_OK; + return errCode; } int SqliteStoreExecutorImpl::DropCollection(const std::string &name, bool ignoreNonExists) @@ -306,9 +306,8 @@ int SqliteStoreExecutorImpl::DropCollection(const std::string &name, bool ignore int errCode = SQLiteUtils::ExecSql(dbHandle_, sql); if (errCode != E_OK) { GLOGE("[sqlite executor] Drop collection failed. err=%d", errCode); - return errCode; } - return E_OK; + return errCode; } bool SqliteStoreExecutorImpl::IsCollectionExists(const std::string &name, int &errCode) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp index 3e0c86f7460ad5d8b4f32199dadf0de339ebdc60..81d9ff2569ff4c9cf8af98d260783e82fc5f78ba 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp @@ -190,7 +190,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigTest001, TestSize.Level0) { GRD_DB *db = nullptr; std::string path = "./document.db"; - const int MAX_JSON_LEN = 512 * 1024; + constexpr int MAX_JSON_LEN = 512 * 1024; std::string configStr = std::string(MAX_JSON_LEN, 'a'); int status = GRD_DBOpen(path.c_str(), configStr.c_str(), GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_OVER_LIMIT); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_delete_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_delete_test.cpp index 8165c73b2d17300929e07ee105f245950929671d..4debaabfeaa3b44580b38ae5ed666ff3c0b41dcc 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_delete_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_delete_test.cpp @@ -29,8 +29,8 @@ using namespace DocumentDBUnitTest; namespace { constexpr const char *COLLECTION_NAME = "student"; constexpr const char *NULL_JSON_STR = "{}"; -const int MAX_COLLECTION_LENS = 511; -std::string g_path = "./document.db"; +constexpr int MAX_COLLECTION_LENS = 511; +std::string path = "./document.db"; GRD_DB *g_db = nullptr; class DocumentDBDeleteTest : public testing::Test {