diff --git a/frameworks/libs/distributeddb/common/include/db_common.h b/frameworks/libs/distributeddb/common/include/db_common.h index 2775893abecef39db12a01aa13839e8a072ac1db..414ff7474c6f234badbed06fe59f726de7152888 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 f7950a032c7277ccdd6be834d2deb759169dfe40..ee169b38ceaa28fe1092d40d2eee1b324f7d17e9 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 21384e5d10d2917c6002161b6de65581e653ef94..f8603dde22aba4519cf81b94b5be6008f618838c 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 cbc0a1f3b51bef9466cf42b00972ad51a06d2b45..e80c048168ba8fd8f2d2626b19868b11fca6cc97 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 327994d14d9a7a33ca27188608ae986b88680551..aa4e90ad1907362d112f67c4f4c27994b5d2cf81 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 b7ea5bad0040c22d36058ca87b9cfedf2ebab86e..eb77269c873063ffa9277820d8b5807d3721a3e0 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 1c7c6b1241f491d8866da0604b4d33bad543eb78..941ae66360399b70f635f85df98483f6b2ee0419 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();