From e587959453d1f4e0ab4018bb97d23fa5a3348da9 Mon Sep 17 00:00:00 2001 From: bluhuang Date: Fri, 22 Mar 2024 15:27:40 +0800 Subject: [PATCH] add log Signed-off-by: bluhuang --- .../distributeddb/common/include/db_common.h | 2 ++ .../distributeddb/common/src/db_common.cpp | 8 +++++++ .../common/src/platform_specific.cpp | 9 ++++--- ...rd_single_ver_natural_store_connection.cpp | 24 +++++++++++++++++++ .../gaussdb_rd/rd_single_ver_result_set.cpp | 6 +++-- .../rd_single_ver_storage_engine.cpp | 5 ++-- .../rd_single_ver_storage_executor.cpp | 4 ++-- 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/frameworks/libs/distributeddb/common/include/db_common.h b/frameworks/libs/distributeddb/common/include/db_common.h index 2775893abec..414ff7474c6 100644 --- a/frameworks/libs/distributeddb/common/include/db_common.h +++ b/frameworks/libs/distributeddb/common/include/db_common.h @@ -112,6 +112,8 @@ public: static std::string GenerateHashLabel(const DBInfo &dbInfo); static uint64_t EraseBit(uint64_t origin, uint64_t eraseBit); + + static std::string GetAnonymousString(const std::string &originStr); private: static void InsertNodesByScore(const std::map> &graph, const std::vector &generateNodes, const std::map &scoreGraph, diff --git a/frameworks/libs/distributeddb/common/src/db_common.cpp b/frameworks/libs/distributeddb/common/src/db_common.cpp index f7950a032c7..ee169b38cea 100644 --- a/frameworks/libs/distributeddb/common/src/db_common.cpp +++ b/frameworks/libs/distributeddb/common/src/db_common.cpp @@ -633,4 +633,12 @@ uint64_t DBCommon::EraseBit(uint64_t origin, uint64_t eraseBit) { return origin & (~eraseBit); } +std::string DBCommon::GetAnonymousString(const std::string &originStr) +{ + // 3 means one-third + std::string str = originStr.length() == 0 ? "empty uri" : + originStr.substr(0, originStr.length() / 3) + "*****" + + originStr.substr(2 * originStr.length() / 3); + return str; +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/common/src/platform_specific.cpp b/frameworks/libs/distributeddb/common/src/platform_specific.cpp index 21384e5d10d..f8603dde22a 100644 --- a/frameworks/libs/distributeddb/common/src/platform_specific.cpp +++ b/frameworks/libs/distributeddb/common/src/platform_specific.cpp @@ -32,6 +32,7 @@ #include #endif +#include "db_common.h" #include "db_errno.h" #include "log_print.h" #include "securec.h" @@ -117,7 +118,8 @@ int MakeDBDirectory(const std::string &directory) { int errCode = mkdir(directory.c_str()); if (errCode < 0) { - LOGE("[MakeDir] Make directory fail:%d.", errno); + std::string str = DBCommon::GetAnonymousString(directory); + LOGE("[MakeDir] Make directory fail:%d, directory path: %s", errno, str.c_str()); return -E_SYSTEM_API_FAIL; } return E_OK; @@ -434,7 +436,8 @@ int MakeDBDirectory(const std::string &directory) { int errCode = mkdir(directory.c_str(), (S_IRWXU | S_IRWXG)); // The permission is 770 for linux based os if (errCode < 0) { - LOGE("[MakeDir] Make directory fail:%d.", errno); + std::string str = DBCommon::GetAnonymousString(directory); + LOGE("[MakeDir] Make directory fail:%d, directory path: %s", errno, str.c_str()); return -E_SYSTEM_API_FAIL; } return E_OK; @@ -613,7 +616,7 @@ int OpenFile(const std::string &fileName, FileHandle *&fileHandle) } fileHandle->handle = open(fileName.c_str(), (O_WRONLY | O_CREAT), (S_IRUSR | S_IWUSR | S_IRGRP)); if (fileHandle->handle < 0) { - LOGE("[FileLock] can not open file when lock it:[%d]", errno); + LOGE("[FileLock] can not open file when lock it:[%d], filename: %s", errno, fileName.c_str()); delete fileHandle; fileHandle = nullptr; return -E_SYSTEM_API_FAIL; diff --git a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_natural_store_connection.cpp b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_natural_store_connection.cpp index cbc0a1f3b51..e80c048168b 100755 --- a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_natural_store_connection.cpp +++ b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_natural_store_connection.cpp @@ -129,6 +129,26 @@ int RdSingleVerNaturalStoreConnection::GetResultSet(const IOption &option, const return E_OK; } +static void PrintResultsetKeys(const QueryExpression &queryExpression) +{ + std::vector beginKeyVec = queryExpression.GetBeginKey(); + std::vector endKeyVec = queryExpression.GetEndKey(); + std::string beginKey; + std::string endKey; + if (beginKeyVec.size() == 0) { + beginKey = "NULL"; + } else { + beginKey.assign(beginKeyVec.begin(), beginKeyVec.end()); + } + if (endKeyVec.size() == 0) { + endKey = "NULL"; + } else { + endKey.assign(endKeyVec.begin(), endKeyVec.end()); + } + + LOGD("begin key: %s, end key: %s", beginKey.c_str(), endKey.c_str()); +} + int RdSingleVerNaturalStoreConnection::GetResultSet(const IOption &option, const Query &query, IKvDBResultSet *&resultSet) const { @@ -148,6 +168,7 @@ int RdSingleVerNaturalStoreConnection::GetResultSet(const IOption &option, if (errCode != E_OK) { return errCode; } + RdSingleVerResultSet *tmpResultSet = new (std::nothrow) RdSingleVerResultSet(naturalStore, queryExpression.GetBeginKey(), queryExpression.GetEndKey(), KV_SCAN_RANGE); if (tmpResultSet == nullptr) { @@ -325,6 +346,9 @@ int RdSingleVerNaturalStoreConnection::GetEntriesInner(const IOption &option, co queryExpression.GetEndKey()), entries); ReleaseExecutor(handle); DBDfxAdapter::FinishTracing(); + if (errCode != -E_NOT_FOUND) { + PrintResultsetKeys(queryExpression); + } return errCode; } int RdSingleVerNaturalStoreConnection::GetEntries(const IOption &option, const Query &query, diff --git a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_result_set.cpp b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_result_set.cpp index 327994d14d9..aa4e90ad190 100755 --- a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_result_set.cpp +++ b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_result_set.cpp @@ -162,7 +162,8 @@ int RdSingleVerResultSet::Move(int offset) const errCode = MoveToNext(); if (errCode != E_OK) { if (errCode == -E_NOT_FOUND) { - LOGE("[RdSingleVerStorageExecutor] move offset: %d, out of bounds, position: %d", offset, position_); + LOGE("[RdSingleVerResultSet] move offset: %d, out of bounds or result set empty, position: %d", + offset, position_); return -E_INVALID_ARGS; } LOGE("[RdSinResSet] move by offset failed, errCode=%d, offset=%d", errCode, offset); @@ -174,7 +175,8 @@ int RdSingleVerResultSet::Move(int offset) const errCode = MoveToPrev(); if (errCode != E_OK) { if (errCode == -E_NOT_FOUND && offset <= 0) { - LOGE("[RdSingleVerStorageExecutor] move offset: %d, out of bounds, position: %d", offset, position_); + LOGE("[RdSingleVerResultSet] move offset: %d, out of bounds or result set empty, position: %d", + offset, position_); return -E_INVALID_ARGS; } LOGE("[RdSinResSet] move by offset failed, errCode=%d, offset=%d", errCode, offset); diff --git a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_storage_engine.cpp index b7ea5bad004..eb77269c873 100644 --- a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_storage_engine.cpp @@ -133,7 +133,8 @@ int RdSingleVerStorageEngine::TryToOpenMainDatabase(bool isWrite, GRD_DB *&db) } int errCode = OpenGrdDb(optionTemp, db); if (errCode != E_OK) { - LOGE("Failed to open the main database [%d]", errCode); + std::string str = DBCommon::GetAnonymousString(option_.uri); + LOGE("Failed to open the main database [%d], uri: %s", errCode, str.c_str()); return errCode; } @@ -212,4 +213,4 @@ int RdSingleVerStorageEngine::IndexPreLoad(GRD_DB *&db, const char *collectionNa } return E_OK; } -} // namespace DistributedDB \ No newline at end of file +} // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_storage_executor.cpp b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_storage_executor.cpp index 1c7c6b1241f..941ae663603 100755 --- a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_storage_executor.cpp +++ b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_single_ver_storage_executor.cpp @@ -79,7 +79,7 @@ int RdSingleVerStorageExecutor::OpenResultSet(const Key &beginKey, const Key &en { int errCode = RdKVRangeScan(db_, SYNC_COLLECTION_NAME.c_str(), beginKey, endKey, resultSet); if (errCode != E_OK) { - LOGE("Can not open rd result set."); + LOGE("[RdSingleVerStorageExecutor][OpenResultSet] Can not open rd result set."); } return errCode; } @@ -306,7 +306,7 @@ int RdSingleVerStorageExecutor::GetEntriesPrepare(GRD_DB *db, const GRD_KvScanMo return -E_INVALID_ARGS; } if (ret != E_OK) { - LOGE("[RdSingleVerStorageExecutor][GetEntries]ERROR %d", ret); + LOGE("[RdSingleVerStorageExecutor][GetEntriesPrepare]ERROR %d", ret); return ret; } entries.clear(); -- Gitee