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 0e4e9275489229e7fb99b53230616fb187e54241..6784b71ff871d83ba1353dbea5db589bd68db64e 100644 --- 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 @@ -600,7 +600,6 @@ int RdSingleVerNaturalStoreConnection::SaveEntryNormally(const Entry &entry, boo RdSingleVerStorageExecutor *RdSingleVerNaturalStoreConnection::GetExecutor(bool isWrite, int &errCode) const { - LOGD("[RdSingleVerNaturalStoreConnection] Getting Executor "); RdSingleVerNaturalStore *naturalStore = GetDB(); if (naturalStore == nullptr) { errCode = -E_NOT_INIT; diff --git a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_utils.cpp b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_utils.cpp index 26184bf0d148edbf5f61787ee29e07603866c0a5..c085079129645a31fea5662e39e501a071cbd18b 100644 --- a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_utils.cpp +++ b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_utils.cpp @@ -97,7 +97,7 @@ int TransferGrdErrno(int err) return -E_INTERNAL_ERROR; } -std::vector KvItemToBlob(GRD_KVItemT &item) +static inline std::vector KvItemToBlob(GRD_KVItemT &item) { return std::vector((uint8_t *)item.data, (uint8_t *)item.data + item.dataLen); } diff --git a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_utils.h b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_utils.h index 703ae25c5d085e82061320d15e42236fc141f364..d1b660bea2e88c02f47a4041355bf1ee14b46881 100644 --- a/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_utils.h +++ b/frameworks/libs/distributeddb/storage/src/gaussdb_rd/rd_utils.h @@ -37,8 +37,6 @@ std::string InitRdConfig(); int TransferGrdErrno(int err); -std::vector KvItemToBlob(GRD_KVItemT &item); - int GetCollNameFromType(SingleVerDataType type, std::string &collName); int RdKVPut(GRD_DB *db, const char *collectionName, const Key &key, const Value &value); diff --git a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp index 587ad476ef72e2a9b60a3f5656d26b85695fa194..8737bca33b264f53f030a07d325c330161f4e712 100644 --- a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp @@ -136,6 +136,8 @@ SQLiteSingleVerRelationalStorageExecutor *RelationalSyncAbleStorage::GetHandle(b storageEngine_->FindExecutor(isWrite, perm, errCode)); if (handle == nullptr) { TriggerCloseAutoLaunchConn(storageEngine_->GetProperties()); + } else { + LOGD("Get executor[%d] from [%.3s]", isWrite, storageEngine_->GetHashIdentifier().c_str()); } return handle; } @@ -152,6 +154,9 @@ SQLiteSingleVerRelationalStorageExecutor *RelationalSyncAbleStorage::GetHandleEx } auto handle = static_cast( storageEngine_->FindExecutor(isWrite, perm, errCode)); + if (handle != nullptr) { + LOGD("Get executor[%d] from [%.3s]", isWrite, storageEngine_->GetHashIdentifier().c_str()); + } if (errCode != E_OK) { ReleaseHandle(handle); handle = nullptr; @@ -165,6 +170,10 @@ void RelationalSyncAbleStorage::ReleaseHandle(SQLiteSingleVerRelationalStorageEx return; } StorageExecutor *databaseHandle = handle; + if (databaseHandle != nullptr) { + LOGD("Recycle executor[%d] for id[%.6s]", databaseHandle->GetWritable(), + storageEngine_->GetHashIdentifier().c_str()); + } storageEngine_->Recycle(databaseHandle); std::function listener = nullptr; { @@ -412,6 +421,8 @@ int RelationalSyncAbleStorage::GetSyncDataForQuerySync(std::vector &da OperatePerm::NORMAL_PERM, errCode)); if (handle == nullptr) { goto ERROR; + } else { + LOGD("Get executor[%d] from [%.3s]", false, storageEngine_->GetHashIdentifier().c_str()); } do { @@ -1035,6 +1046,9 @@ int RelationalSyncAbleStorage::StartTransaction(TransactType type) if (handle == nullptr) { ReleaseHandle(handle); return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", type == TransactType::IMMEDIATE, + storageEngine_->GetHashIdentifier().c_str()); } errCode = handle->StartTransaction(type); if (errCode != E_OK) { @@ -1404,6 +1418,8 @@ int RelationalSyncAbleStorage::FillCloudLogAndAsset(const OpType opType, const C storageEngine_->FindExecutor(true, OperatePerm::NORMAL_PERM, errCode)); if (writeHandle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, storageEngine_->GetHashIdentifier().c_str()); } errCode = writeHandle->StartTransaction(TransactType::IMMEDIATE); if (errCode != E_OK) { @@ -2164,6 +2180,8 @@ int RelationalSyncAbleStorage::ReviseLocalModTime(const std::string &tableName, if (writeHandle == nullptr) { LOGE("[ReviseLocalModTime] Get write handle fail: %d", errCode); return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, storageEngine_->GetHashIdentifier().c_str()); } errCode = writeHandle->StartTransaction(TransactType::IMMEDIATE); if (errCode != E_OK) { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp index d063d53e586d762be99c01ca965a1c96ce2a1d9f..738c3372696dd6dfe6880391eb9f341e53b5ad9e 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp @@ -322,8 +322,12 @@ SQLiteSingleVerRelationalStorageExecutor *SQLiteRelationalStore::GetHandle(bool return nullptr; } - return static_cast( + auto handle = static_cast( sqliteStorageEngine_->FindExecutor(isWrite, OperatePerm::NORMAL_PERM, errCode)); + if (handle != nullptr) { + LOGD("Get executor[%d] from [%.3s]", isWrite, sqliteStorageEngine_->GetHashIdentifier().c_str()); + } + return handle; } void SQLiteRelationalStore::ReleaseHandle(SQLiteSingleVerRelationalStorageExecutor *&handle) const { @@ -333,6 +337,10 @@ void SQLiteRelationalStore::ReleaseHandle(SQLiteSingleVerRelationalStorageExecut if (sqliteStorageEngine_ != nullptr) { StorageExecutor *databaseHandle = handle; + if (databaseHandle != nullptr) { + LOGD("Recycle executor[%d] for id[%.6s]", databaseHandle->GetWritable(), + sqliteStorageEngine_->GetHashIdentifier().c_str()); + } sqliteStorageEngine_->Recycle(databaseHandle); handle = nullptr; } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp index f4c49cbe40a2b7a97840ce32f1e239bf957e903e..0455bca366059febde9be821134ed5313ddb5e87 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp @@ -128,6 +128,9 @@ int SQLiteSingleRelationalStorageEngine::ReleaseExecutor(SQLiteSingleVerRelation return E_OK; } StorageExecutor *databaseHandle = handle; + if (databaseHandle != nullptr) { + LOGD("Recycle executor[%d] for id[%.6s]", databaseHandle->GetWritable(), GetHashIdentifier().c_str()); + } Recycle(databaseHandle); handle = nullptr; return E_OK; @@ -270,6 +273,8 @@ int SQLiteSingleRelationalStorageEngine::CreateDistributedTable(const std::strin errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } ResFinalizer finalizer([&handle, this] { this->ReleaseExecutor(handle); }); @@ -343,6 +348,8 @@ int SQLiteSingleRelationalStorageEngine::UpgradeDistributedTable(const std::stri errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } errCode = handle->StartTransaction(TransactType::IMMEDIATE); @@ -384,6 +391,8 @@ int SQLiteSingleRelationalStorageEngine::CleanDistributedDeviceTable(std::vector errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } std::lock_guard lock(schemaMutex_); @@ -444,6 +453,8 @@ int SQLiteSingleRelationalStorageEngine::SetTrackerTable(const TrackerSchema &sc errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } errCode = handle->StartTransaction(TransactType::IMMEDIATE); @@ -499,6 +510,8 @@ int SQLiteSingleRelationalStorageEngine::CheckAndCacheTrackerSchema(const Tracke OperatePerm::NORMAL_PERM, errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } RelationalSchemaObject tracker = trackerSchema_; if (!tracker.GetTrackerTable(schema.tableName).IsChanging(schema)) { // LCOV_EXCL_BR_LINE @@ -533,6 +546,8 @@ int SQLiteSingleRelationalStorageEngine::GetOrInitTrackerSchemaFromMeta() errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } errCode = handle->GetOrInitTrackerSchemaFromMeta(trackerSchema); if (errCode != E_OK) { @@ -569,6 +584,8 @@ int SQLiteSingleRelationalStorageEngine::SaveTrackerSchema(const std::string &ta errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } RelationalSchemaObject tracker = trackerSchema_; errCode = SaveTrackerSchemaToMetaTable(handle, tracker); @@ -588,6 +605,8 @@ int SQLiteSingleRelationalStorageEngine::ExecuteSql(const SqlCondition &conditio OperatePerm::NORMAL_PERM, errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", !condition.readOnly, GetHashIdentifier().c_str()); } errCode = handle->ExecuteSql(condition, records); if (errCode != E_OK) { @@ -682,6 +701,8 @@ int SQLiteSingleRelationalStorageEngine::CleanTrackerData(const std::string &tab errCode)); if (handle == nullptr) { // LCOV_EXCL_BR_LINE return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } errCode = handle->CleanTrackerData(tableName, cursor); ReleaseExecutor(handle); @@ -697,6 +718,8 @@ int SQLiteSingleRelationalStorageEngine::UpgradeSharedTable(const DataBaseSchema errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } errCode = handle->StartTransaction(TransactType::IMMEDIATE); if (errCode != E_OK) { @@ -1004,6 +1027,8 @@ int SQLiteSingleRelationalStorageEngine::GenLogInfoForUpgrade(const std::string OperatePerm::NORMAL_PERM, errCode)); if (handle == nullptr) { return errCode; + } else { + LOGD("Get executor[%d] from [%.3s]", true, GetHashIdentifier().c_str()); } ResFinalizer finalizer([&handle, this] { this->ReleaseExecutor(handle); }); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp index e0b9f1093c253dc68e05ee98cf194587cfd6cfbe..affa03a9a0f86277447c8b0dadcdebe0b86d9782 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp @@ -1135,6 +1135,8 @@ SQLiteSingleVerStorageExecutor *SQLiteSingleVerNaturalStore::GetHandle(bool isWr auto handle = storageEngine_->FindExecutor(isWrite, perm, errCode); if (handle == nullptr) { engineMutex_.unlock_shared(); // unlock when get handle failed. + } else { + LOGD("Get executor[%d] from [%.3s]", isWrite, storageEngine_->GetHashIdentifier().c_str()); } return static_cast(handle); } @@ -1148,6 +1150,10 @@ void SQLiteSingleVerNaturalStore::ReleaseHandle(SQLiteSingleVerStorageExecutor * if (storageEngine_ != nullptr) { bool isCorrupted = handle->GetCorruptedStatus(); StorageExecutor *databaseHandle = handle; + if (databaseHandle != nullptr) { + LOGD("Recycle executor[%d] for id[%.6s]", databaseHandle->GetWritable(), + storageEngine_->GetHashIdentifier().c_str()); + } storageEngine_->Recycle(databaseHandle); handle = nullptr; if (isCorrupted) { 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 724260e9cb1710fab1c652a08df14329035e6e87..17438f22c984a4dde1af2d7fbc088f2d1765bbb7 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 @@ -130,6 +130,9 @@ int SQLiteSingleVerStorageEngine::EraseDeviceWaterMark(SQLiteSingleVerStorageExe LOGE("Migrate sync data fail, Can not get available executor, errCode = [%d]", errCode); return errCode; } + if (handle != nullptr) { + LOGD("Get executor[%d] from [%.3s]", true, hashIdentifier_.c_str()); + } } } return errCode; @@ -206,6 +209,9 @@ int SQLiteSingleVerStorageEngine::ReleaseHandleTransiently(SQLiteSingleVerStorag LOGE("Migrate sync data fail, Can not get available executor, errCode = [%d]", errCode); return errCode; } + if (handle != nullptr) { + LOGD("Get executor[%d] from [%.3s]", true, hashIdentifier_.c_str()); + } return errCode; } @@ -222,6 +228,9 @@ int SQLiteSingleVerStorageEngine::AddSubscribeToMainDBInMigrate() LOGE("Get available executor for add subscribe failed. %d", errCode); return errCode; } + if (handle != nullptr) { + LOGD("Get executor[%d] from [%.3s]", true, hashIdentifier_.c_str()); + } errCode = handle->StartTransaction(TransactType::IMMEDIATE); if (errCode != E_OK) { // LCOV_EXCL_BR_LINE goto END; @@ -249,6 +258,9 @@ int SQLiteSingleVerStorageEngine::MigrateSyncData(SQLiteSingleVerStorageExecutor LOGE("Migrate sync data fail, Can not get available executor, errCode = [%d]", errCode); return errCode; } + if (handle != nullptr) { + LOGD("Get executor[%d] from [%.3s]", true, hashIdentifier_.c_str()); + } } LOGD("Begin migrate sync data, need migrate version[%" PRIu64 "]", GetCacheRecordVersion()); @@ -356,6 +368,9 @@ int SQLiteSingleVerStorageEngine::ReleaseExecutor(SQLiteSingleVerStorageExecutor } StorageExecutor *databaseHandle = handle; isCorrupted_ = isCorrupted_ || handle->GetCorruptedStatus(); + if (databaseHandle != nullptr) { + LOGD("Recycle executor[%d] for id[%.6s]", databaseHandle->GetWritable(), GetHashIdentifier().c_str()); + } Recycle(databaseHandle); handle = nullptr; if (isCorrupted_) { @@ -472,6 +487,9 @@ int SQLiteSingleVerStorageEngine::ExecuteMigrate() LOGE("Migrate data fail, Can not get available executor, errCode = [%d]", errCode); return errCode; } + if (handle != nullptr) { + LOGD("Get executor[%d] from [%.3s]", true, hashIdentifier_.c_str()); + } isMigrating_.store(true); LOGD("Migrate start."); diff --git a/frameworks/libs/distributeddb/storage/src/storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/storage_engine.cpp index 8531beb7a9e01bc6bc63bf33bd5894befd994671..adce83a2d5d617ba2b4203cee95175c8f3b890b0 100644 --- a/frameworks/libs/distributeddb/storage/src/storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/storage_engine.cpp @@ -97,6 +97,10 @@ int StorageEngine::InitReadWriteExecutors() return E_OK; } +std::string StorageEngine::GetHashIdentifier() +{ + return hashIdentifier_; +} int StorageEngine::Init() { @@ -234,7 +238,6 @@ void StorageEngine::Recycle(StorageExecutor *&handle) if (handle == nullptr) { return; } - LOGD("Recycle executor[%d] for id[%.6s]", handle->GetWritable(), hashIdentifier_.c_str()); if (handle->GetWritable()) { std::unique_lock lock(writeMutex_); auto iter = std::find(writeUsingList_.begin(), writeUsingList_.end(), handle); @@ -456,7 +459,6 @@ StorageExecutor *StorageEngine::FetchStorageExecutor(bool isWrite, std::list