From 5e7ab814133b91b2a6cb8e32361adcc156df6026 Mon Sep 17 00:00:00 2001 From: wbq_sky Date: Sat, 24 Sep 2022 18:00:06 +0800 Subject: [PATCH] fix the review issue Signed-off-by: wbq_sky --- .../distributeddb/common/include/db_common.h | 3 +- .../distributeddb/common/include/db_types.h | 2 +- .../common/include/endian_convert.h | 2 +- .../common/include/performance_analysis.h | 2 +- .../common/include/platform_specific.h | 2 +- .../distributeddb/common/include/ref_object.h | 9 +-- .../common/include/runtime_context.h | 2 +- .../common/include/schema_constant.h | 1 + .../common/include/schema_negotiate.h | 2 +- .../common/include/schema_object.h | 5 +- .../distributeddb/common/include/task_pool.h | 3 +- .../common/include/user_change_monitor.h | 3 +- .../common/src/flatbuffer_schema.cpp | 69 ++++++++----------- .../distributeddb/common/src/json_object.cpp | 19 +++-- .../common/src/param_check_utils.cpp | 4 +- .../libs/distributeddb/common/src/parcel.cpp | 10 +-- .../common/src/performance_analysis.cpp | 10 +-- .../common/src/platform_specific.cpp | 17 ++--- .../distributeddb/common/src/ref_object.cpp | 16 ++--- .../common/src/runtime_context.cpp | 2 +- .../common/src/runtime_context_impl.h | 10 +-- .../common/src/schema_negotiate.cpp | 2 +- .../common/src/schema_object.cpp | 66 ++++++++---------- .../distributeddb/common/src/schema_utils.cpp | 8 ++- .../distributeddb/common/src/task_pool_impl.h | 5 +- .../common/src/time_tick_monitor.h | 5 +- .../common/src/user_change_monitor.cpp | 3 +- .../interfaces/include/get_query_info.h | 2 +- .../storage/src/generic_kvdb.cpp | 13 ++-- ...e_ver_natural_store_commit_notify_data.cpp | 2 +- .../sqlite_single_ver_storage_engine.cpp | 4 +- .../sqlite_single_ver_storage_executor.h | 2 +- ...lite_single_ver_storage_executor_cache.cpp | 32 ++++----- 33 files changed, 162 insertions(+), 175 deletions(-) diff --git a/frameworks/libs/distributeddb/common/include/db_common.h b/frameworks/libs/distributeddb/common/include/db_common.h index aca9546ebd1..2b51e51e45d 100644 --- a/frameworks/libs/distributeddb/common/include/db_common.h +++ b/frameworks/libs/distributeddb/common/include/db_common.h @@ -18,9 +18,10 @@ #include #include + #include "db_types.h" -#include "store_types.h" #include "kvdb_properties.h" +#include "store_types.h" namespace DistributedDB { class DBCommon final { diff --git a/frameworks/libs/distributeddb/common/include/db_types.h b/frameworks/libs/distributeddb/common/include/db_types.h index c620dbe41ae..656beaacae8 100644 --- a/frameworks/libs/distributeddb/common/include/db_types.h +++ b/frameworks/libs/distributeddb/common/include/db_types.h @@ -21,8 +21,8 @@ #include #include -#include "types_export.h" #include "db_constant.h" +#include "types_export.h" namespace DistributedDB { using Timestamp = uint64_t; diff --git a/frameworks/libs/distributeddb/common/include/endian_convert.h b/frameworks/libs/distributeddb/common/include/endian_convert.h index 97060c201ea..c2e20756a90 100644 --- a/frameworks/libs/distributeddb/common/include/endian_convert.h +++ b/frameworks/libs/distributeddb/common/include/endian_convert.h @@ -16,8 +16,8 @@ #ifndef ENDIAN_CONVERT_H #define ENDIAN_CONVERT_H -#include #include +#include namespace DistributedDB { inline bool IsBigEndian() diff --git a/frameworks/libs/distributeddb/common/include/performance_analysis.h b/frameworks/libs/distributeddb/common/include/performance_analysis.h index 4a89f22f088..1b0da052c1d 100644 --- a/frameworks/libs/distributeddb/common/include/performance_analysis.h +++ b/frameworks/libs/distributeddb/common/include/performance_analysis.h @@ -16,8 +16,8 @@ #ifndef PERFORMANCE_ANALYSIS_H #define PERFORMANCE_ANALYSIS_H -#include #include +#include #include "db_types.h" diff --git a/frameworks/libs/distributeddb/common/include/platform_specific.h b/frameworks/libs/distributeddb/common/include/platform_specific.h index 5f9a8ce053a..10d91822f80 100644 --- a/frameworks/libs/distributeddb/common/include/platform_specific.h +++ b/frameworks/libs/distributeddb/common/include/platform_specific.h @@ -16,9 +16,9 @@ #ifndef PLATFORM_SPECIFIC_H #define PLATFORM_SPECIFIC_H -#include #include #include +#include namespace DistributedDB { #if (defined(OS_TYPE_WINDOWS)) || (defined(OS_TYPE_MAC)) diff --git a/frameworks/libs/distributeddb/common/include/ref_object.h b/frameworks/libs/distributeddb/common/include/ref_object.h index 7fce0ea1e73..9cf3a569c0a 100644 --- a/frameworks/libs/distributeddb/common/include/ref_object.h +++ b/frameworks/libs/distributeddb/common/include/ref_object.h @@ -17,10 +17,11 @@ #define KV_DB_REF_OBJECT_H #include -#include -#include -#include #include +#include +#include +#include + #include "macro_utils.h" namespace DistributedDB { @@ -36,7 +37,7 @@ public: private: DISABLE_COPY_ASSIGN_MOVE(AutoLock); const RefObject *refObj_; - bool IsLocked_; + bool isLocked_; }; RefObject(); diff --git a/frameworks/libs/distributeddb/common/include/runtime_context.h b/frameworks/libs/distributeddb/common/include/runtime_context.h index 63ab1c15f02..dc291b983b0 100644 --- a/frameworks/libs/distributeddb/common/include/runtime_context.h +++ b/frameworks/libs/distributeddb/common/include/runtime_context.h @@ -17,8 +17,8 @@ #define RUNTIME_CONTEXT_H #include -#include #include +#include #include "auto_launch.h" #include "auto_launch_export.h" diff --git a/frameworks/libs/distributeddb/common/include/schema_constant.h b/frameworks/libs/distributeddb/common/include/schema_constant.h index bbfe3b2d101..0fb0e6b75aa 100644 --- a/frameworks/libs/distributeddb/common/include/schema_constant.h +++ b/frameworks/libs/distributeddb/common/include/schema_constant.h @@ -16,6 +16,7 @@ #ifndef SCHEMA_CONSTANT_H #define SCHEMA_CONSTANT_H +#include #include // This header is supposed to be included only in source files. Do not include it in any header files. diff --git a/frameworks/libs/distributeddb/common/include/schema_negotiate.h b/frameworks/libs/distributeddb/common/include/schema_negotiate.h index d12304cb75c..9bb759211fb 100644 --- a/frameworks/libs/distributeddb/common/include/schema_negotiate.h +++ b/frameworks/libs/distributeddb/common/include/schema_negotiate.h @@ -15,8 +15,8 @@ #ifndef SCHEMA_NEGOTIATE_H #define SCHEMA_NEGOTIATE_H -#include "schema_object.h" #include "relational_schema_object.h" +#include "schema_object.h" namespace DistributedDB { struct SyncOpinion { diff --git a/frameworks/libs/distributeddb/common/include/schema_object.h b/frameworks/libs/distributeddb/common/include/schema_object.h index 2cf9091a678..e265565e445 100644 --- a/frameworks/libs/distributeddb/common/include/schema_object.h +++ b/frameworks/libs/distributeddb/common/include/schema_object.h @@ -16,15 +16,16 @@ #ifndef SCHEMA_OBJECT_H #define SCHEMA_OBJECT_H -#include #include +#include + #ifndef OMIT_FLATBUFFER #include #endif // OMIT_FLATBUFFER #include "db_types.h" +#include "ischema.h" #include "macro_utils.h" #include "relational_schema_object.h" -#include "ischema.h" #include "value_object.h" namespace DistributedDB { diff --git a/frameworks/libs/distributeddb/common/include/task_pool.h b/frameworks/libs/distributeddb/common/include/task_pool.h index fe5d8c8bc5a..39d400d4397 100644 --- a/frameworks/libs/distributeddb/common/include/task_pool.h +++ b/frameworks/libs/distributeddb/common/include/task_pool.h @@ -16,8 +16,9 @@ #ifndef TASK_POOL_H #define TASK_POOL_H -#include #include +#include + #include "macro_utils.h" namespace DistributedDB { diff --git a/frameworks/libs/distributeddb/common/include/user_change_monitor.h b/frameworks/libs/distributeddb/common/include/user_change_monitor.h index 6591a40c401..1f2837c3a8d 100644 --- a/frameworks/libs/distributeddb/common/include/user_change_monitor.h +++ b/frameworks/libs/distributeddb/common/include/user_change_monitor.h @@ -17,9 +17,10 @@ #define USER_CHANGE_MONITOR_H #include -#include "platform_specific.h" + #include "macro_utils.h" #include "notification_chain.h" +#include "platform_specific.h" #include "runtime_context.h" namespace DistributedDB { diff --git a/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp b/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp index 021b5ec7400..7f4ba262ad7 100644 --- a/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp +++ b/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp @@ -14,12 +14,14 @@ */ #include "schema_object.h" -#include + #include -#include "schema_constant.h" -#include "schema_utils.h" +#include + #include "db_errno.h" #include "log_print.h" +#include "schema_constant.h" +#include "schema_utils.h" namespace DistributedDB { namespace { @@ -169,11 +171,7 @@ int SchemaObject::FlatBufferSchema::ParseFlatBufferSchema(const std::string &inD return errCode; } - errCode = ParseCheckIndexes(indexCollect); - if (errCode != E_OK) { - return errCode; - } - return E_OK; + return ParseCheckIndexes(indexCollect); } int SchemaObject::FlatBufferSchema::CompareFlatBufferDefine(const FlatBufferSchema &other) const @@ -196,7 +194,7 @@ int SchemaObject::FlatBufferSchema::CompareFlatBufferDefine(const FlatBufferSche std::string selfRootName = SchemaUtils::StripNameSpace(selfRootTableName->str()); std::string otherRootName = SchemaUtils::StripNameSpace(otherRootTableName->str()); if (selfRootName != otherRootName) { - LOGE("[FBSchema][Compare] RootName differ, self=%s, other=%s.", selfRootName.c_str(), otherRootName.c_str()); + LOGE("[FBSchema][Compare] RootName dif."); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } // We don't have to compare rootTableAttribute or index here, they are done by SchemaObject @@ -212,12 +210,12 @@ int CheckSizePrefixRawValue(const RawValue &inValue) return -E_INVALID_ARGS; } if (inValue.second <= SIZE_PREFIX_SIZE) { - LOGE("[FBSchema][CheckSizePreValue] ValueSize=%u too short.", inValue.second); + LOGW("[FBSchema][CheckSizePreValue] ValueSize too short:%" PRIu32, inValue.second); return -E_INVALID_ARGS; } auto realSize = flatbuffers::ReadScalar(inValue.first); if (realSize != inValue.second - SIZE_PREFIX_SIZE) { - LOGE("[FBSchema][CheckSizePreValue] RealSize=%u mismatch valueSize=(%u-4).", realSize, inValue.second); + LOGE("[FBSchema][CheckSizePreValue] RealSize=%" PRIu32 " mismatch %" PRIu32, realSize, inValue.second); return -E_INVALID_ARGS; } return E_OK; @@ -439,7 +437,7 @@ int SchemaObject::FlatBufferSchema::ExtractFlatBufferValue(RawString inPath, con // Currently we don't support nest-path auto fieldInfo = GetFieldInfoFromSchemaByPath(*schema, pathStr); if (fieldInfo == nullptr) { - LOGE("[FBSchema][Extract] FieldInfo of path=%s not found.", pathStr); + LOGW("[FBSchema][Extract] FieldInfo of path not found."); return -E_INTERNAL_ERROR; } // Begin extract, we have to minimal verify if we don't trust value from database @@ -532,19 +530,18 @@ int SchemaObject::FlatBufferSchema::ParseCheckRootTableDefine(const reflection:: CHECK_NULL_UNLIKELY_RETURN_ERROR(name); int errCode = SchemaUtils::CheckFieldName(name->str()); if (errCode != E_OK) { - LOGE("[FBSchema][ParseRootDefine] Invalid fieldName=%s, errCode=%d.", name->c_str(), errCode); + LOGE("[FBSchema][ParseRootDefine] Invalid fieldName, errCode=%d.", errCode); return -E_SCHEMA_PARSE_FAIL; } FieldPath path{name->str()}; if (owner_.schemaDefine_[ROOT_DEFINE_DEPTH].count(path) != 0) { // Unlikely - LOGE("[FBSchema][ParseRootDefine] FieldPath=%s already exist at root.", name->c_str()); + LOGE("[FBSchema][ParseRootDefine] FieldPath already exist at root."); return -E_SCHEMA_PARSE_FAIL; } errCode = ParseCheckFieldInfo(schema, *eachField, path, indexCollect); if (errCode != E_OK) { - LOGE("[FBSchema][ParseRootDefine] ParseFieldInfo errCode=%d, FieldPath=%s.", errCode, - SchemaUtils::FieldPathString(path).c_str()); + LOGE("[FBSchema][ParseRootDefine] ParseFieldInfo errCode=%d", errCode); return errCode; } } @@ -555,7 +552,7 @@ int SchemaObject::FlatBufferSchema::ParseCheckRootTableDefine(const reflection:: } } if (fieldPathCount > SchemaConstant::SCHEMA_FEILD_NAME_COUNT_MAX) { - LOGE("[FBSchema][ParseRootDefine] FieldPath count=%u exceed the limitation.", fieldPathCount); + LOGE("[FBSchema][ParseRootDefine] FieldPath count=%" PRIu32 " exceed the limitation.", fieldPathCount); return -E_SCHEMA_PARSE_FAIL; } return E_OK; @@ -691,7 +688,7 @@ int SchemaObject::FlatBufferSchema::ParseCheckStructDefine(const reflection::Sch CHECK_NULL_UNLIKELY_RETURN_ERROR(eachName); int errCode = SchemaUtils::CheckFieldName(eachName->str()); if (errCode != E_OK) { - LOGE("[FBSchema][ParseStruct] Invalid fieldName=%s, errCode=%d.", eachName->c_str(), errCode); + LOGE("[FBSchema][ParseStruct] Invalid fieldName, errCode=%d.", errCode); return -E_SCHEMA_PARSE_FAIL; } FieldPath eachPath = path; @@ -699,8 +696,7 @@ int SchemaObject::FlatBufferSchema::ParseCheckStructDefine(const reflection::Sch RawIndexInfos notUsed; errCode = ParseCheckFieldInfo(schema, *eachField, eachPath, notUsed); if (errCode != E_OK) { - LOGE("[FBSchema][ParseStruct] ParseFieldInfo errCode=%d, FieldPath=%s.", errCode, - SchemaUtils::FieldPathString(eachPath).c_str()); + LOGE("[FBSchema][ParseStruct] ParseFieldInfo errCode=%d.", errCode); return errCode; } } @@ -723,7 +719,7 @@ int SchemaObject::FlatBufferSchema::ParseCheckIndexes(const RawIndexInfos &index if (IsNotCompositeIndex(rawIndexStr)) { int errCode = owner_.ParseCheckEachIndexFromStringArray(indexStrArray); if (errCode != E_OK) { - LOGE("[FBSchema][ParseIndex] Create single-index=%s fail, errCode=%d.", entry.first.c_str(), errCode); + LOGE("[FBSchema][ParseIndex] Create single-index fail:%d.", errCode); return errCode; } description_ += ("INDEX=" + entry.first + ";"); @@ -744,8 +740,7 @@ int SchemaObject::FlatBufferSchema::ParseCheckIndexes(const RawIndexInfos &index } int errCode = owner_.ParseCheckEachIndexFromStringArray(indexStrArray); if (errCode != E_OK) { - LOGE("[FBSchema][ParseIndex] Create composite-index=%s, rawStr=%s fail, errCode=%d.", entry.first.c_str(), - rawIndexStr.c_str(), errCode); + LOGE("[FBSchema][ParseIndex] Create composite-index fail:%d.", errCode); return errCode; } description_ += ("INDEX=" + entry.first + ";"); @@ -768,12 +763,12 @@ int CompareFieldCount(bool isRoot, uint32_t selfCount, uint32_t otherCount) { if (isRoot) { if (otherCount < selfCount) { - LOGE("[FBSchema][CompareRoot] RootFieldSize: other=%u less than self=%u.", otherCount, selfCount); + LOGW("[FBSchema][CompareRoot] RootFieldSize: %" PRu32 " vs %" PRu32, selfCount, otherCount); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } } else { if (selfCount != otherCount) { - LOGE("[FBSchema][CompareRoot] StructFieldSize: self=%u differ with other=%u.", selfCount, otherCount); + LOGW("[FBSchema][CompareRoot] StructFieldSize: %" PRu32 " vs %" PRu32, selfCount, otherCount); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } } @@ -785,26 +780,23 @@ int CompareFieldInfoBesideType(const reflection::Field &selfField, const reflect { // Compare offset if (selfField.offset() != otherField.offset()) { - LOGE("[FBSchema][CompareField] Offset differ: self=%u, other=%u.", selfField.offset(), otherField.offset()); + LOGW("[FBSchema][CompareField] Offset diff"); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } // Compare default value if (selfField.default_integer() != otherField.default_integer()) { - LOGE("[FBSchema][CompareField] DefaultInteger differ: self=%lld, other=%lld.", - static_cast(selfField.default_integer()), static_cast(otherField.default_integer())); + LOGE("[FBSchema][CompareField] DefaultInteger diff"); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } // QUEER: for the same default_real value in fbs, flatbuffer will generate different value in binary ??? if (!IsDoubleNearlyEqual(selfField.default_real(), otherField.default_real())) { - LOGE("[FBSchema][CompareField] DefaultReal differ: self=%f, other=%f.", selfField.default_real(), - otherField.default_real()); + LOGE("[FBSchema][CompareField] DefaultReal diff"); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } // Ignore deprecated, Compare required if (IsRequiredSupportType(theType)) { if (selfField.required() != otherField.required()) { - LOGE("[FBSchema][CompareField] Require differ: self=%d, other=%d.", selfField.required(), - otherField.required()); + LOGE("[FBSchema][CompareField] Require diff"); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } } @@ -821,7 +813,7 @@ int CompareFieldInfo(const reflection::Field &selfField, const reflection::Field auto selfBaseType = selfType->base_type(); auto otherBaseType = otherType->base_type(); if (selfBaseType != otherBaseType) { - LOGE("[FBSchema][CompareField] BaseType differ: self=%s, other=%s.", reflection::EnumNameBaseType(selfBaseType), + LOGE("[FBSchema][CompareField] BaseType diff:%s vs %s.", reflection::EnumNameBaseType(selfBaseType), reflection::EnumNameBaseType(otherBaseType)); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } @@ -829,7 +821,7 @@ int CompareFieldInfo(const reflection::Field &selfField, const reflection::Field auto selfElementType = selfType->element(); auto otherElementType = otherType->element(); if (selfElementType != otherElementType) { - LOGE("[FBSchema][CompareField] ElementType differ: self=%u, other=%u.", selfElementType, otherElementType); + LOGE("[FBSchema][CompareField] ElementType diff:%" PRu32 " vs %" PRu32, selfElementType, otherElementType); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } } @@ -858,7 +850,7 @@ int CompareExtraField(const PairConstPointer &bothObject) continue; } if (eachOtherField->required()) { - LOGE("[FBSchema][CompareDefine] Extra field=%s should not be required.", otherName->c_str()); + LOGE("[FBSchema][CompareDefine] Extra field should not be required."); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } } @@ -886,13 +878,13 @@ int SchemaObject::FlatBufferSchema::CompareTableOrStructDefine(const PairConstPo CHECK_NULL_UNLIKELY_RETURN_ERROR(selfName); auto correspondOtherField = otherFields->LookupByKey(selfName->c_str()); if (correspondOtherField == nullptr) { - LOGE("[FBSchema][CompareDefine] SelfField=%s not found in other.", selfName->c_str()); + LOGE("[FBSchema][CompareDefine] SelfField not found in other."); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } bool isStruct = false; errCode = CompareFieldInfo(*eachSelfField, *correspondOtherField, isStruct); if (IsNotEqualNotCompatible(errCode)) { - LOGE("[FBSchema][CompareDefine] Compare info of field=%s fail, errCode=%d.", selfName->c_str(), errCode); + LOGE("[FBSchema][CompareDefine] Compare info of field fail, errCode=%d.", errCode); return errCode; } if (isStruct) { @@ -941,8 +933,7 @@ int SchemaObject::FlatBufferSchema::CompareStruct(const PairConstPointerstr()); std::string otherName = SchemaUtils::StripNameSpace(otherStructName->str()); if (selfName != otherName) { - LOGE("[FBSchema][CompareStruct] The field is not of same struct type, self=%s, other=%s.", - selfName.c_str(), otherName.c_str()); + LOGE("[FBSchema][CompareStruct] The field is not of same struct type"); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } if (compared.count(selfName) != 0) { // This struct-type had already been compared, no need to do recurse again diff --git a/frameworks/libs/distributeddb/common/src/json_object.cpp b/frameworks/libs/distributeddb/common/src/json_object.cpp index 807798a6a49..860f0b3c611 100644 --- a/frameworks/libs/distributeddb/common/src/json_object.cpp +++ b/frameworks/libs/distributeddb/common/src/json_object.cpp @@ -14,9 +14,11 @@ */ #include "json_object.h" + +#include #include #include -#include + #include "db_errno.h" #include "log_print.h" @@ -116,8 +118,8 @@ int JsonObject::Parse(const std::string &inString) int errCode = E_OK; uint32_t nestDepth = CalculateNestDepth(inString, errCode); if (errCode != E_OK || nestDepth > maxNestDepth_) { - LOGE("[Json][Parse] Json calculate nest depth failed %d, depth=%u exceed max allowed=%u.", errCode, nestDepth, - maxNestDepth_); + LOGE("[Json][Parse] Json calculate nest depth failed %d, depth=%" PRIu32 " exceed max allowed:%" PRIu32, + errCode, nestDepth, maxNestDepth_); return -E_JSON_PARSE_FAIL; } #ifdef JSONCPP_USE_BUILDER @@ -173,8 +175,8 @@ int JsonObject::Parse(const uint8_t *dataBegin, const uint8_t *dataEnd) int errCode = E_OK; uint32_t nestDepth = CalculateNestDepth(dataBegin, dataEnd, errCode); if (errCode != E_OK || nestDepth > maxNestDepth_) { - LOGE("[Json][Parse] Json calculate nest depth failed %d, depth=%u exceed max allowed=%u.", errCode, nestDepth, - maxNestDepth_); + LOGE("[Json][Parse] Json calculate nest depth failed %d, depth:%" PRIu32 " exceed max allowed:%" PRIu32, + errCode, nestDepth, maxNestDepth_); return -E_JSON_PARSE_FAIL; } #ifdef JSONCPP_USE_BUILDER @@ -436,7 +438,7 @@ int JsonObject::GetArrayContentOfStringOrStringArray(const FieldPath &inPath, } // If reach here, then something is not ok outContent.clear(); - LOGE("[Json][GetArrayContent] Not string or array or GetStringArray fail=%d at index=%u.", errCode, index); + LOGE("[Json][GetArrayContent] Not string or array fail=%d at index:%" PRIu32, errCode, index); return -E_NOT_SUPPORT; } return E_OK; @@ -451,10 +453,7 @@ bool InsertFieldCheckParameter(const FieldPath &inPath, FieldType inType, const return false; } // Infinite double not support - if (inType == FieldType::LEAF_FIELD_DOUBLE && !std::isfinite(inValue.doubleValue)) { - return false; - } - return true; + return !(inType == FieldType::LEAF_FIELD_DOUBLE && !std::isfinite(inValue.doubleValue)); } void LeafJsonNodeAppendValue(Json::Value &leafNode, FieldType inType, const FieldValue &inValue) diff --git a/frameworks/libs/distributeddb/common/src/param_check_utils.cpp b/frameworks/libs/distributeddb/common/src/param_check_utils.cpp index 1cb41e1de5d..2a1fe4d232a 100644 --- a/frameworks/libs/distributeddb/common/src/param_check_utils.cpp +++ b/frameworks/libs/distributeddb/common/src/param_check_utils.cpp @@ -17,8 +17,8 @@ #include "db_common.h" #include "db_errno.h" -#include "platform_specific.h" #include "log_print.h" +#include "platform_specific.h" namespace DistributedDB { bool ParamCheckUtils::CheckDataDir(const std::string &dataDir, std::string &canonicalDir) @@ -192,7 +192,7 @@ uint8_t ParamCheckUtils::GetValidCompressionRate(uint8_t compressionRate) { // Valid when between 1 and 100. When compressionRate is invalid, change it to default rate. if (compressionRate < 1 || compressionRate > DBConstant::DEFAULT_COMPTRESS_RATE) { - LOGD("Invalid compression rate:%u.", compressionRate); + LOGD("Invalid compression rate:%" PRIu8, compressionRate); compressionRate = DBConstant::DEFAULT_COMPTRESS_RATE; } return compressionRate; diff --git a/frameworks/libs/distributeddb/common/src/parcel.cpp b/frameworks/libs/distributeddb/common/src/parcel.cpp index 372a9bfc66f..815597416fa 100644 --- a/frameworks/libs/distributeddb/common/src/parcel.cpp +++ b/frameworks/libs/distributeddb/common/src/parcel.cpp @@ -17,12 +17,12 @@ #include +#include "db_constant.h" +#include "db_errno.h" #include "endian_convert.h" -#include "securec.h" -#include "macro_utils.h" #include "log_print.h" -#include "db_errno.h" -#include "db_constant.h" +#include "macro_utils.h" +#include "securec.h" namespace DistributedDB { Parcel::Parcel(uint8_t *inBuf, uint32_t len) @@ -392,7 +392,7 @@ int Parcel::WriteBlob(const char *buffer, uint32_t bufLen) uint32_t leftLen = static_cast(totalLen_ - parcelLen_); int errCode = memcpy_s(bufPtr_, leftLen, buffer, bufLen); if (errCode != EOK) { - LOGE("[WriteBlob] leftLen:%u, bufLen:%u", leftLen, bufLen); + LOGE("[WriteBlob] leftLen:%" PRIu32 ", bufLen:%" PRIu32, leftLen, bufLen); isError_ = true; return -E_SECUREC_ERROR; } diff --git a/frameworks/libs/distributeddb/common/src/performance_analysis.cpp b/frameworks/libs/distributeddb/common/src/performance_analysis.cpp index f0aa482b9d7..94207bf3067 100644 --- a/frameworks/libs/distributeddb/common/src/performance_analysis.cpp +++ b/frameworks/libs/distributeddb/common/src/performance_analysis.cpp @@ -17,10 +17,10 @@ #include #include "db_errno.h" -#include "macro_utils.h" -#include "time_helper.h" #include "log_print.h" +#include "macro_utils.h" #include "platform_specific.h" +#include "time_helper.h" namespace DistributedDB { const std::string PerformanceAnalysis::STATISTICAL_DATA_FILE_NAME_HEADER = "/data/log/statistic"; @@ -192,9 +192,11 @@ void PerformanceAnalysis::OutStatistics() { std::string addrStatistics = STATISTICAL_DATA_FILE_NAME_HEADER + fileID_ + CSV_FILE_EXTENSION; outFile.open(addrStatistics, std::ios_base::app); + if (!outFile.is_open()) { + return; + } // This part filters the zeros data - outFile << "stepNum" << "," << "maxTime(us)" << "," << "minTime(us)" << "," << "averageTime(us)" - << "," << "count" << "," << "\n"; + outFile << "stepNum, maxTime(us), minTime(us), averageTime(us), count,\n"; for (size_t i = 0; i < stepTimeRecordInfo_.size(); i++) { // output to performance file if (stepTimeRecordInfo_[i].max != 0) { outFile << i << "," << stepTimeRecordInfo_[i].max<< "," << stepTimeRecordInfo_[i].min diff --git a/frameworks/libs/distributeddb/common/src/platform_specific.cpp b/frameworks/libs/distributeddb/common/src/platform_specific.cpp index 93f33a3ae29..16df2d75745 100644 --- a/frameworks/libs/distributeddb/common/src/platform_specific.cpp +++ b/frameworks/libs/distributeddb/common/src/platform_specific.cpp @@ -18,23 +18,24 @@ #include #include #include -#include -#include -#include #include -#include -#include + #include +#include +#include +#include +#include +#include +#include #if defined OS_TYPE_WINDOWS -#include #include +#include #include #endif -#include -#include "securec.h" #include "db_errno.h" #include "log_print.h" +#include "securec.h" namespace DistributedDB { namespace OS { diff --git a/frameworks/libs/distributeddb/common/src/ref_object.cpp b/frameworks/libs/distributeddb/common/src/ref_object.cpp index a3cd10760d9..cc5442dc448 100644 --- a/frameworks/libs/distributeddb/common/src/ref_object.cpp +++ b/frameworks/libs/distributeddb/common/src/ref_object.cpp @@ -21,22 +21,22 @@ constexpr static int MAX_REF_COUNT = 1024; RefObject::AutoLock::AutoLock(const RefObject *obj, bool unlocked) : refObj_(obj), - IsLocked_(false) + isLocked_(false) { if (refObj_ != nullptr) { if (unlocked) { refObj_->LockObj(); } - IsLocked_ = true; + isLocked_ = true; } } void RefObject::AutoLock::Lock() { if (refObj_ != nullptr) { - if (!IsLocked_) { + if (!isLocked_) { refObj_->LockObj(); - IsLocked_ = true; + isLocked_ = true; } else { LOGE("RefObject-AutoLock: obj' acquires lock more than once."); } @@ -46,9 +46,9 @@ void RefObject::AutoLock::Lock() void RefObject::AutoLock::Unlock() { if (refObj_ != nullptr) { - if (IsLocked_) { + if (isLocked_) { refObj_->UnlockObj(); - IsLocked_ = false; + isLocked_ = false; } else { LOGE("RefObject-AutoLock: obj releases lock more than once."); } @@ -58,9 +58,9 @@ void RefObject::AutoLock::Unlock() RefObject::AutoLock::~AutoLock() { if (refObj_ != nullptr) { - if (IsLocked_) { + if (isLocked_) { refObj_->UnlockObj(); - IsLocked_ = false; + isLocked_ = false; } refObj_ = nullptr; } diff --git a/frameworks/libs/distributeddb/common/src/runtime_context.cpp b/frameworks/libs/distributeddb/common/src/runtime_context.cpp index 9acf1e19cd5..022ff75a83f 100644 --- a/frameworks/libs/distributeddb/common/src/runtime_context.cpp +++ b/frameworks/libs/distributeddb/common/src/runtime_context.cpp @@ -14,9 +14,9 @@ */ #include +#include "log_print.h" #include "runtime_context_impl.h" #include "version.h" -#include "log_print.h" namespace DistributedDB { RuntimeContext *RuntimeContext::GetInstance() diff --git a/frameworks/libs/distributeddb/common/src/runtime_context_impl.h b/frameworks/libs/distributeddb/common/src/runtime_context_impl.h index 60652baa801..5df535dd42c 100644 --- a/frameworks/libs/distributeddb/common/src/runtime_context_impl.h +++ b/frameworks/libs/distributeddb/common/src/runtime_context_impl.h @@ -16,18 +16,18 @@ #ifndef RUNTIME_CONTEXT_IMPL_H #define RUNTIME_CONTEXT_IMPL_H -#include #include +#include #include -#include "runtime_context.h" -#include "task_pool.h" +#include "auto_launch.h" #include "evloop/include/ievent.h" #include "evloop/include/ievent_loop.h" +#include "icommunicator_aggregator.h" #include "lock_status_observer.h" +#include "runtime_context.h" +#include "task_pool.h" #include "time_tick_monitor.h" -#include "icommunicator_aggregator.h" -#include "auto_launch.h" #include "user_change_monitor.h" namespace DistributedDB { diff --git a/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp b/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp index f183488e9cf..e1669b7f748 100644 --- a/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp +++ b/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp @@ -128,7 +128,7 @@ RelationalSyncOpinion SchemaNegotiate::MakeLocalSyncOpinion(const RelationalSche SchemaType localType = localSchema.GetSchemaType(); SchemaType remoteType = ReadSchemaType(remoteSchemaType); if (remoteType == SchemaType::UNRECOGNIZED) { - LOGW("[RelationalSchema][opinion] Remote schema type %d is unrecognized.", remoteSchemaType); + LOGW("[RelationalSchema][opinion] Remote schema type %" PRIu8 " is unrecognized.", remoteSchemaType); return {}; } diff --git a/frameworks/libs/distributeddb/common/src/schema_object.cpp b/frameworks/libs/distributeddb/common/src/schema_object.cpp index 003bfe0f1bc..46114c7c6ca 100644 --- a/frameworks/libs/distributeddb/common/src/schema_object.cpp +++ b/frameworks/libs/distributeddb/common/src/schema_object.cpp @@ -14,10 +14,10 @@ */ #include "schema_object.h" -#include "schema_utils.h" #include "db_errno.h" #include "log_print.h" #include "schema_constant.h" +#include "schema_utils.h" namespace DistributedDB { namespace { @@ -27,6 +27,7 @@ const std::string FLATBUFFER_EXTRACT_FUNC_NAME = "flatbuffer_extract_by_path"; // For Json-Schema, display its original content before parse. For FlatBuffer-Schema, only display its parsed content. void DisplaySchemaLineByLine(SchemaType inType, const std::string &inSchema) { +#ifdef TRACE_SCHEMA_INFO constexpr uint32_t lengthPerLine = 400; // 400 char per line constexpr uint32_t usualMaxLine = 25; // For normal schema, 25 line for 10k length is quite enough LOGD("[Schema][Display] IS %s, LENGTH=%zu.", SchemaUtils::SchemaTypeString(inType).c_str(), inSchema.size()); @@ -39,6 +40,7 @@ void DisplaySchemaLineByLine(SchemaType inType, const std::string &inSchema) std::string lineStr = inSchema.substr(line * lengthPerLine, lengthPerLine); LOGD("%s", lineStr.c_str()); } +#endif } } @@ -356,7 +358,7 @@ int SchemaObject::ExtractValue(ValueSource sourceType, RawString inPath, const R return -E_INVALID_ARGS; } if (inValue.second <= schemaSkipSize_) { - LOGE("[Schema][Extract] Value length=%u invalid, skipsize=%u.", inValue.second, schemaSkipSize_); + LOGE("[Schema][Extract] Value length=%" PRIu32 " invalid, skip:%" PRIu32, inValue.second, schemaSkipSize_); return -E_FLATBUFFER_VERIFY_FAIL; } @@ -383,7 +385,7 @@ int SchemaObject::ExtractValue(ValueSource sourceType, RawString inPath, const R // Currently do not try no sizePrefix, future may depend on sourceType int errCode = flatbufferSchema_.ExtractFlatBufferValue(inPath, rawValue, outExtract, false); if (errCode != E_OK) { - LOGE("[Schema][Extract] Fail, path=%s, srcType=%d.", inPath, static_cast(sourceType)); + LOGE("[Schema][Extract] Fail, srcType=%d.", static_cast(sourceType)); } delete tempCache; // delete nullptr is safe tempCache = nullptr; @@ -410,11 +412,7 @@ int SchemaObject::ParseJsonSchema(const JsonObject &inJsonObject) if (errCode != E_OK) { return errCode; } - errCode = ParseCheckSchemaSkipSize(inJsonObject); - if (errCode != E_OK) { - return errCode; - } - return E_OK; + return ParseCheckSchemaSkipSize(inJsonObject); } namespace { @@ -542,7 +540,7 @@ int SchemaObject::ParseCheckSchemaDefine(const JsonObject& inJsonObject) std::map subPathType; int errCode = inJsonObject.GetSubFieldPathAndType(nestPathCurDepth, subPathType); if (errCode != E_OK) { // Unlikely - LOGE("[Schema][ParseDefine] Internal Error: GetSubFieldPathAndType Fail, Depth=%u.", depth); + LOGE("[Schema][ParseDefine] Internal Error: GetSubFieldPathAndType Fail, Depth=%" PRIu32, depth); return -E_INTERNAL_ERROR; } fieldNameCount += subPathType.size(); @@ -551,8 +549,7 @@ int SchemaObject::ParseCheckSchemaDefine(const JsonObject& inJsonObject) SchemaAttribute attribute; errCode = CheckSchemaDefineItemDecideAttribute(inJsonObject, subField.first, subField.second, attribute); if (errCode != E_OK) { - LOGE("[Schema][ParseDefine] CheckSchemaDefineItemDecideAttribute Fail, Path=%s.", - SchemaUtils::FieldPathString(subField.first).c_str()); + LOGE("[Schema][ParseDefine] CheckSchemaDefineItemDecideAttribute Fail."); return -E_SCHEMA_PARSE_FAIL; } // If everything ok, insert this schema item into schema define @@ -561,8 +558,7 @@ int SchemaObject::ParseCheckSchemaDefine(const JsonObject& inJsonObject) // Deal with the nestpath and check depth limitation if (subField.second == FieldType::INTERNAL_FIELD_OBJECT) { if (depth == SchemaConstant::SCHEMA_FEILD_PATH_DEPTH_MAX - 1) { // Minus 1 to be the boundary - LOGE("[Schema][ParseDefine] Path=%s is INTERNAL_FIELD_OBJECT but reach schema depth limitation.", - SchemaUtils::FieldPathString(subField.first).c_str()); + LOGE("[Schema][ParseDefine] node is INTERNAL_FIELD_OBJECT but reach schema depth limitation."); return -E_SCHEMA_PARSE_FAIL; } nestPathCurDepth.insert(subField.first); @@ -575,7 +571,7 @@ int SchemaObject::ParseCheckSchemaDefine(const JsonObject& inJsonObject) } if (fieldNameCount > SchemaConstant::SCHEMA_FEILD_NAME_COUNT_MAX) { // Check Field Count Here - LOGE("[Schema][ParseDefine] FieldName count=%u exceed the limitation.", fieldNameCount); + LOGE("[Schema][ParseDefine] FieldName count=%" PRIu32 " exceed the limitation.", fieldNameCount); return -E_SCHEMA_PARSE_FAIL; } return E_OK; @@ -590,7 +586,7 @@ int SchemaObject::CheckSchemaDefineItemDecideAttribute(const JsonObject& inJsonO } int errCode = SchemaUtils::CheckFieldName(inPath.back()); if (errCode != E_OK) { - LOGE("[Schema][CheckItemDecideAttr] Invalid fieldName=%s, errCode=%d.", inPath.back().c_str(), errCode); + LOGE("[Schema][CheckItemDecideAttr] Invalid fieldName, errCode=%d.", errCode); return -E_SCHEMA_PARSE_FAIL; } if (inType == FieldType::LEAF_FIELD_STRING) { @@ -693,15 +689,15 @@ int SchemaObject::ParseCheckEachIndexFromStringArray(const std::vector SchemaConstant::SCHEMA_FEILD_PATH_DEPTH_MAX) { - LOGE("[Schema][ParseEachIndex] Root not indexable or path=%s depth exceed limit.", eachPathStr.c_str()); + LOGE("[Schema][ParseEachIndex] Root not indexable or path depth exceed limit."); return -E_SCHEMA_PARSE_FAIL; } if (indexPathSet.count(eachPath) != 0) { - LOGE("[Schema][ParseEachIndex] IndexPath=%s Duplicated.", eachPathStr.c_str()); + LOGE("[Schema][ParseEachIndex] IndexPath Duplicated."); return -E_SCHEMA_PARSE_FAIL; } indexPathVec.push_back(eachPath); @@ -713,7 +709,7 @@ int SchemaObject::ParseCheckEachIndexFromStringArray(const std::vector & uint32_t depth = eachPath.size() - 1; // minus 1 to change depth count from zero std::string eachPathStr = SchemaUtils::FieldPathString(eachPath); if (schemaDefine_.count(depth) == 0) { - LOGE("[Schema][CheckIndexable] No schema define of this depth, path=%s.", eachPathStr.c_str()); + LOGE("[Schema][CheckIndexable] No schema define of this depth."); return -E_SCHEMA_PARSE_FAIL; } if (schemaDefine_[depth].count(eachPath) == 0) { - LOGE("[Schema][CheckIndexable] No such path in schema define, path=%s.", eachPathStr.c_str()); + LOGE("[Schema][CheckIndexable] No such path in schema define."); return -E_SCHEMA_PARSE_FAIL; } if (!schemaDefine_[depth][eachPath].isIndexable) { - LOGE("[Schema][CheckIndexable] Path=%s is not indexable.", eachPathStr.c_str()); + LOGE("[Schema][CheckIndexable] Path is not indexable."); return -E_SCHEMA_PARSE_FAIL; } // Save this indexField to indexInfo @@ -827,15 +823,13 @@ int SchemaObject::CompareSchemaDefineByDepth(const SchemaDefine &oldDefine, cons // Looking for incompatible : new define should at least contain all field the old define hold for (auto &entry : oldDefine) { if (newDefine.count(entry.first) == 0) { - LOGE("[Schema][CompareDefineDepth] fieldpath=%s not found in new schema.", - SchemaUtils::FieldPathString(entry.first).c_str()); + LOGE("[Schema][CompareDefineDepth] fieldpath not found in new schema."); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } // SchemaAttribute require to be equal exactly int errCode = CompareSchemaAttribute(entry.second, newDefine.at(entry.first)); if (errCode != -E_SCHEMA_EQUAL_EXACTLY) { - LOGE("[Schema][CompareDefineDepth] Attribute mismatch at fieldpath=%s.", - SchemaUtils::FieldPathString(entry.first).c_str()); + LOGE("[Schema][CompareDefineDepth] Attribute mismatch at fieldpath."); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } } @@ -845,9 +839,8 @@ int SchemaObject::CompareSchemaDefineByDepth(const SchemaDefine &oldDefine, cons continue; } if (!IsExtraFieldConformToCompatibility(entry.second)) { - LOGE("[Schema][CompareDefineDepth] ExtraField=%s, {notnull=%d, default=%d}, not conform compatibility.", - SchemaUtils::FieldPathString(entry.first).c_str(), entry.second.hasNotNullConstraint, - entry.second.hasDefaultValue); + LOGE("[Schema][CompareDefineDepth] ExtraField, {notnull=%d, default=%d}, not conform compatibility.", + entry.second.hasNotNullConstraint, entry.second.hasDefaultValue); return -E_SCHEMA_UNEQUAL_INCOMPATIBLE; } } @@ -966,12 +959,12 @@ int SchemaObject::CompareSchemaIndexes(const SchemaObject &newSchema, IndexDiffe // Find the increase and change index for (const auto &entry : newSchema.schemaIndexes_) { if (schemaIndexes_.count(entry.first) == 0) { - LOGD("[Schema][CompareIndex] Increase indexName=%s.", SchemaUtils::FieldPathString(entry.first).c_str()); + LOGD("[Schema][CompareIndex] Increase indexName."); indexDiffer.increase[entry.first] = entry.second; } else { // Both schema have same IndexName, Check whether indexInfo differs if (!IsIndexInfoExactlyEqual(entry.second, schemaIndexes_.at(entry.first))) { - LOGD("[Schema][CompareIndex] Change indexName=%s.", SchemaUtils::FieldPathString(entry.first).c_str()); + LOGD("[Schema][CompareIndex] Change indexName."); indexDiffer.change[entry.first] = entry.second; } } @@ -979,7 +972,7 @@ int SchemaObject::CompareSchemaIndexes(const SchemaObject &newSchema, IndexDiffe // Find the decrease index for (const auto &entry : schemaIndexes_) { if (newSchema.schemaIndexes_.count(entry.first) == 0) { - LOGD("[Schema][CompareIndex] Decrease indexName=%s.", SchemaUtils::FieldPathString(entry.first).c_str()); + LOGD("[Schema][CompareIndex] Decrease indexName."); indexDiffer.decrease.insert(entry.first); } } @@ -1098,7 +1091,7 @@ int SchemaObject::CheckValue(const ValueObject &inValue, std::set &la std::map subPathType; int errCode = inValue.GetSubFieldPathAndType(nestPathCurDepth, subPathType); // Value field of current depth if (errCode != E_OK && errCode != -E_INVALID_PATH) { // E_INVALID_PATH for path not exist - LOGE("[Schema][CheckValue] GetSubFieldPathAndType Fail=%d, Depth=%u.", errCode, depth); + LOGE("[Schema][CheckValue] GetSubFieldPathAndType Fail=%d, Depth=%" PRIu32, errCode, depth); return -E_VALUE_MISMATCH_FEILD_TYPE; } nestPathCurDepth.clear(); // Clear it for collecting new nestPath @@ -1119,8 +1112,8 @@ int SchemaObject::CheckValue(const ValueObject &inValue, std::set &la } errCode = CheckValueBySchemaItem(schemaItem, subPathType, lackingPaths); if (errCode != -E_VALUE_MATCH) { - LOGE("[Schema][CheckValue] Path=%s, schema{NotNull=%d,Default=%d,Type=%s}, Value{Type=%s}, errCode=%d.", - SchemaUtils::FieldPathString(schemaItem.first).c_str(), schemaItem.second.hasNotNullConstraint, + LOGE("[Schema][CheckValue] Schema{NotNull=%d,Default=%d,Type=%s}, Value{Type=%s}, errCode=%d.", + schemaItem.second.hasNotNullConstraint, schemaItem.second.hasDefaultValue, SchemaUtils::FieldTypeString(schemaItem.second.type).c_str(), ValueFieldType(subPathType, schemaItem.first).c_str(), errCode); return errCode; @@ -1144,8 +1137,7 @@ int SchemaObject::AmendValueIfNeed(ValueObject &inValue, const std::set -#include -#include + #include +#include +#include +#include + #include "db_errno.h" #include "log_print.h" #include "schema_constant.h" diff --git a/frameworks/libs/distributeddb/common/src/task_pool_impl.h b/frameworks/libs/distributeddb/common/src/task_pool_impl.h index 7e533a2d64e..97440afc4b3 100644 --- a/frameworks/libs/distributeddb/common/src/task_pool_impl.h +++ b/frameworks/libs/distributeddb/common/src/task_pool_impl.h @@ -16,11 +16,12 @@ #ifndef TASK_POOL_IMPL_H #define TASK_POOL_IMPL_H -#include -#include #include #include +#include #include +#include + #include "task_pool.h" #include "task_queue.h" diff --git a/frameworks/libs/distributeddb/common/src/time_tick_monitor.h b/frameworks/libs/distributeddb/common/src/time_tick_monitor.h index 0bb42c5d0c2..3a53f32aa31 100644 --- a/frameworks/libs/distributeddb/common/src/time_tick_monitor.h +++ b/frameworks/libs/distributeddb/common/src/time_tick_monitor.h @@ -16,10 +16,11 @@ #ifndef TIME_TICK_MONITOR_H #define TIME_TICK_MONITOR_H -#include "runtime_context.h" #include "db_types.h" -#include "platform_specific.h" #include "macro_utils.h" +#include "runtime_context.h" +#include "platform_specific.h" + namespace DistributedDB { class TimeTickMonitor final { diff --git a/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp b/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp index f670ce3182d..6f6166e19a7 100644 --- a/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp +++ b/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp @@ -77,7 +77,6 @@ NotificationChain::Listener *UserChangeMonitor::RegisterUserChangedListerner(con int UserChangeMonitor::PrepareNotifierChain() { - int errCode = E_OK; std::unique_lock lockGuard(userChangeMonitorLock_); if (userNotifier_ != nullptr) { return E_OK; @@ -86,7 +85,7 @@ int UserChangeMonitor::PrepareNotifierChain() if (userNotifier_ == nullptr) { return -E_OUT_OF_MEMORY; } - errCode = userNotifier_->RegisterEventType(USER_ACTIVE_EVENT); + int errCode = userNotifier_->RegisterEventType(USER_ACTIVE_EVENT); if (errCode != E_OK) { goto ERROR_HANDLE; } diff --git a/frameworks/libs/distributeddb/interfaces/include/get_query_info.h b/frameworks/libs/distributeddb/interfaces/include/get_query_info.h index 5adaf9d91b7..bb380290e5a 100644 --- a/frameworks/libs/distributeddb/interfaces/include/get_query_info.h +++ b/frameworks/libs/distributeddb/interfaces/include/get_query_info.h @@ -27,4 +27,4 @@ public: } }; } -#endif \ No newline at end of file +#endif // DISTRIBUTEDDB_GET_QUERY_INFO_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp b/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp index 556a3fdc051..c1e681e5675 100644 --- a/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp +++ b/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp @@ -95,15 +95,14 @@ void GenericKvDB::ReleaseDBConnection(GenericKvDBConnection *connection) SetConnectionFlag(false); } - connectMutex_.lock(); if (connection != nullptr) { - connection->SetSafeDeleted(); - DelConnection(connection); - DecreaseConnectionCounter(); - connectMutex_.unlock(); + { + std::lock_guard lock(connectMutex_); + connection->SetSafeDeleted(); + DelConnection(connection); + DecreaseConnectionCounter(); + } DecObjRef(this); - } else { - connectMutex_.unlock(); } } diff --git a/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp b/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp index 56d61937afc..d4148e27001 100644 --- a/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp +++ b/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp @@ -139,7 +139,7 @@ const std::list SingleVerNaturalStoreCommitNotifyData::FilterEntriesByKey const std::list &entries, const Key &filterKey, int &errCode) { errCode = E_OK; - if (filterKey.size() == 0) { + if (filterKey.empty()) { return entries; } std::list filterEntries; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp index 3c3e075920b..a5b63634d2c 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp @@ -298,7 +298,7 @@ int SQLiteSingleVerStorageEngine::AttachMainDbAndCacheDb(SQLiteSingleVerStorageE } uint64_t maxVersion = 0; - errCode = handle->GetMaxVersionIncacheDb(maxVersion); + errCode = handle->GetMaxVersionInCacheDb(maxVersion); if (errCode != E_OK || maxVersion < CACHE_RECORD_DEFAULT_VERSION) { maxVersion = CACHE_RECORD_DEFAULT_VERSION; } @@ -430,7 +430,7 @@ int SQLiteSingleVerStorageEngine::InitExecuteMigrate(SQLiteSingleVerStorageExecu // Has been attach, maybe ever crashed, need update version executorState_ == ExecutorState::CACHE_ATTACH_MAIN) { uint64_t maxVersion = 0; - errCode = handle->GetMaxVersionIncacheDb(maxVersion); + errCode = handle->GetMaxVersionInCacheDb(maxVersion); if (errCode != E_OK || maxVersion < CACHE_RECORD_DEFAULT_VERSION) { maxVersion = CACHE_RECORD_DEFAULT_VERSION; } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.h index ddc9154c151..92eafb275e5 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.h @@ -206,7 +206,7 @@ public: std::vector &dataItems); int GetMinVersionCacheData(std::vector &dataItems, uint64_t &maxVerIncurCacheDb) const; - int GetMaxVersionIncacheDb(uint64_t &maxVersion) const; + int GetMaxVersionInCacheDb(uint64_t &maxVersion) const; int AttachMainDbAndCacheDb(CipherType type, const CipherPassword &passwd, const std::string &attachDbAbsPath, EngineState engineState); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp index 62e8f57afa7..f236a4fdb81 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp @@ -224,7 +224,7 @@ int SQLiteSingleVerStorageExecutor::AttachMainDbAndCacheDb(CipherType type, cons return errCode; } -int SQLiteSingleVerStorageExecutor::GetMaxVersionIncacheDb(uint64_t &maxVersion) const +int SQLiteSingleVerStorageExecutor::GetMaxVersionInCacheDb(uint64_t &maxVersion) const { sqlite3_stmt *statement = nullptr; std::string sql; @@ -238,24 +238,18 @@ int SQLiteSingleVerStorageExecutor::GetMaxVersionIncacheDb(uint64_t &maxVersion) int errCode = SQLiteUtils::GetStatement(dbHandle_, sql, statement); if (errCode != E_OK) { - LOGE("GetStatement fail when get max version in cache db! errCode = [%d]", errCode); - goto END; + LOGE("GetStatement fail when get max version in cache db"); + return CheckCorruptedStatus(errCode); } - do { - errCode = SQLiteUtils::StepWithRetry(statement, isMemDb_); - if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { - maxVersion = static_cast(sqlite3_column_int64(statement, 0)); - } else if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { - errCode = E_OK; - break; - } else { - LOGE("SQLite step failed:%d", errCode); - break; - } - } while (true); - -END: + errCode = SQLiteUtils::StepWithRetry(statement, isMemDb_); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { + maxVersion = static_cast(sqlite3_column_int64(statement, 0)); + errCode = E_OK; + } else if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { + maxVersion = 0; + errCode = E_OK; + } SQLiteUtils::ResetStatement(statement, true, errCode); return CheckCorruptedStatus(errCode); } @@ -274,7 +268,7 @@ int SQLiteSingleVerStorageExecutor::MigrateDataItem(DataItem &dataItem, NotifyMi } // after solving conflict, the item should not be saved into mainDB if (notify.dataStatus.isDefeated) { - LOGD("Data status is defeated:%d", errCode); + LOGD("Data status is defeated"); return errCode; } bool isUpdate = notify.dataStatus.preStatus != DataStatus::NOEXISTED; @@ -476,7 +470,7 @@ int SQLiteSingleVerStorageExecutor::VacuumLocalData() const int errCode = SQLiteUtils::ExecuteRawSQL(dbHandle_, sql); if (errCode != E_OK) { - LOGE("SQLite sync mode failed: %d", errCode); + LOGE("[SingleVerExe] vaccum local data failed: %d", errCode); } return CheckCorruptedStatus(errCode); -- Gitee