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 44ce39b6dfb9ef5060619d9432aec688433a0d1d..1ec53e65bd8b9902b495ee5ca83f899adb27f8a5 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 @@ -56,6 +56,10 @@ bool CheckAndGetDBConfig(const JsonObject &config, const std::string &name, cons int errCode = E_OK; ValueObject configValue = config.GetObjectByPath(configField, errCode); + if (errCode != E_OK) { + GLOGE("Cant find config Value"); + return errCode; + } if (configValue.GetValueType() != ValueObject::ValueType::VALUE_NUMBER) { GLOGE("Check DB config failed, not found or type of %s is not NUMBER.", name.c_str()); return false; 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 6157cd09e3c4f36fa379e151ced63d9e8a5a508e..171c1fcbbcde6c15e7cc720c9818215c632ce099 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 @@ -83,9 +83,9 @@ std::vector JsonCommon::GetLeafValue(const JsonObject &node) bool JsonCommon::CheckNode(JsonObject &node) { while (!node.IsNull()) { - int ret = 0; std::set fieldSet; bool isFieldNameExist = true; + int ret = E_OK; std::string fieldName = node.GetItemField(ret); if (ret != E_OK) { isFieldNameExist = false; @@ -214,8 +214,7 @@ int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, } if (!node.GetChild().IsNull() && node.GetChild().GetItemField() != "") { JsonObject nodeNew = node.GetChild(); - int ret = E_OK; - ret = ParseNode(nodeNew, singlePath, resultPath, false); + int ret = ParseNode(nodeNew, singlePath, resultPath, false); if (ret != E_OK) { return ret; } @@ -505,9 +504,7 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json int errCode = E_OK; JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); std::string lastFieldName = itemPath.back(); - int isAddedFlag = false; if (errCode != E_OK) { - isAddedFlag = true; AddSpliteField(src, item, itemPath, externErrCode); return false; } @@ -521,7 +518,6 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json GLOGE("Add item to object failed. %d", errCode); return false; } - isAddedFlag = true; return false; } if (!isCollapse) { @@ -529,13 +525,10 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json if (!ret) { return false; // replace failed } - isAddedFlag = true; return false; // Different node types, overwrite directly, skip child node } - if (!isAddedFlag) { - GLOGE("Add nothing because data conflict"); - externErrCode = -E_DATA_CONFLICT; - } + GLOGE("Add nothing because data conflict"); + externErrCode = -E_DATA_CONFLICT; return false; // Source path not exist, overwrite directly, skip child node } } // namespace @@ -544,8 +537,7 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl { int externErrCode = E_OK; JsonObjectIterator(add, {}, - [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, - const JsonObject &item) { + [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, const JsonObject &item) { bool isCollapse = false; // Whether there is a path generated by the dot operator, such as t1.t2.t3 JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); if (src.IsFieldExists(itemPath)) { @@ -645,12 +637,10 @@ bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject & bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, bool &isCollapse, int &isMatchFlag) { - int errCode; - int isAlreadyMatched = 0; + int errCode = E_OK; JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); if (errCode != -E_JSON_PATH_NOT_EXISTS && srcItem == item) { isMatchFlag = true; - isAlreadyMatched = 1; return false; } JsonFieldPath granpaPath = itemPath; @@ -661,7 +651,6 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK - isAlreadyMatched = 1; isMatchFlag = true; break; } @@ -670,6 +659,7 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject } return false; } + int isAlreadyMatched = 0; // means no match anyting return IsObjectItemMatch(srcItem, item, isAlreadyMatched, isCollapse, isMatchFlag); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h index 1e5f9ece23163e70b64b041d7ca500a4dba8b502..a2a41180d854da7c20a8c196dcd8d38f32f28898 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h @@ -36,7 +36,6 @@ public: int DeleteDocument(Key &key); int IsCollectionExists(int &errCode); int UpsertDocument(const std::string &id, const std::string &newDocument, bool &isIdExist); - bool FindDocument(); int UpdateDocument(const std::string &id, const std::string &document); private: 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 47842e9c7563a6955be03d334721d75b6daf7796..09173698fcf0d878ac36314de3c585890a2e739e 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 @@ -78,15 +78,6 @@ int Collection::InsertDocument(const std::string &id, const std::string &documen return executor_->InsertData(name_, key, valSet); } -bool Collection::FindDocument() -{ - if (executor_ == nullptr) { - return -E_INNER_ERROR; - } - int errCode = E_OK; - return executor_->IsCollectionExists(name_, errCode); -} - int Collection::GetDocumentById(Key &key, Value &document) const { if (executor_ == nullptr) { 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 5d9f8a14b53af7255993e836d44449f04be463ca..24b1ed3ce257da53632bd53ab7fa72992b673fc1 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 @@ -156,8 +156,8 @@ int UpdateArgsCheck(const std::string &collection, const std::string &filter, co GLOGE("update Parsed failed"); return errCode; } - std::vector> allPath; if (update != "{}") { + std::vector> allPath; allPath = JsonCommon::ParsePath(updateObj, errCode); if (errCode != E_OK) { GLOGE("updateObj ParsePath failed"); @@ -367,7 +367,7 @@ int InsertIdToDocument(ResultSet &resultSet, JsonObject &filterObj, JsonObject & } if (isIdExist) { docId = idValue.GetStringValue(); - JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); + JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); // this errCode will always be E_OK. documentObj.InsertItemObject(0, idObj); } else { if (ret == E_OK) { // E_OK means find data. @@ -434,8 +434,8 @@ END: int UpsertDocumentFormatCheck(const std::string &document, JsonObject &documentObj) { int errCode = E_OK; - std::vector> allPath; if (document != "{}") { + std::vector> allPath; allPath = JsonCommon::ParsePath(documentObj, errCode); if (errCode != E_OK) { return errCode; @@ -627,7 +627,7 @@ Collection DocumentStore::GetCollection(std::string &collectionName) return Collection(collectionName, executor_); } -int JudgeViewType(size_t &index, ValueObject &leafItem, bool &viewType) +int JudgeViewType(const size_t &index, ValueObject &leafItem, bool &viewType) { switch (leafItem.GetValueType()) { case ValueObject::ValueType::VALUE_BOOL: @@ -712,7 +712,7 @@ int FindArgsCheck(const std::string &collection, const std::string &filter, cons return errCode; } -int FindProjectionInit(const std::string &projection, std::shared_ptr &context) +int FindProjectionInit(const std::string &projection, const std::shared_ptr &context) { int errCode = E_OK; std::vector> allPath; @@ -780,8 +780,7 @@ END: int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) { - int errCode = E_OK; - errCode = FindArgsCheck(collection, filter, projection, flags); + int errCode = FindArgsCheck(collection, filter, projection, flags); if (errCode != E_OK) { GLOGE("delete arg is illegal"); return errCode; @@ -878,7 +877,8 @@ int DocumentStore::Rollback() bool DocumentStore::IsCollectionExists(const std::string &collectionName, int &errCode) { if (executor_ == nullptr) { - return -E_INNER_ERROR; + errCode = -E_INNER_ERROR; + return false; } return executor_->IsCollectionExists(collectionName, errCode); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index a1b73353e74f1b36dab903584a98af126b0323aa..2b97323a67bf8d9b1a75640c645d64b8c2be8cb3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -126,12 +126,11 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) int ResultSet::GetNext(bool isNeedTransaction, bool isNeedCheckTable) { - int errCode = E_OK; if (!isNeedTransaction) { return GetNextInner(isNeedCheckTable); } std::lock_guard lock(store_->dbMutex_); - errCode = store_->StartTransaction(); + int errCode = store_->StartTransaction(); if (errCode != E_OK) { GLOGE("Start transaction faild"); return errCode;