From 30c18e91a5b7f4eed5b8ba74d6e2c10ca576ce11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=9C=A3?= Date: Sat, 10 May 2025 19:17:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=AB=AF=E4=BA=91=E3=80=91=E3=80=90bu?= =?UTF-8?q?gfix=E3=80=91=E8=AE=BE=E7=BD=AE=E5=88=86=E5=B8=83=E5=BC=8Fschem?= =?UTF-8?q?a=E6=97=B6=E6=A3=80=E6=9F=A5=E6=98=AF=E4=B8=8D=E6=98=AF?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E8=A1=A8=E4=BB=A5=E5=88=9B=E5=BB=BA=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E7=9A=84=E8=A7=A6=E5=8F=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 谭凯圣 --- .../relational/log_table_manager_factory.cpp | 15 +++++++++------ .../sqlite/relational/log_table_manager_factory.h | 3 ++- .../sqlite_relational_database_upgrader.cpp | 2 +- .../sqlite_single_relational_storage_engine.cpp | 1 + .../sqlite_single_relational_storage_engine.h | 2 +- ...ite_single_ver_relational_storage_executor.cpp | 10 +++------- ...gle_ver_relational_storage_extend_executor.cpp | 2 +- .../distributeddb_interfaces_log_test.cpp | 3 ++- ...ddb_relational_cloud_syncable_storage_test.cpp | 3 ++- 9 files changed, 22 insertions(+), 19 deletions(-) diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.cpp index a6f613f1b95..6967950aab1 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.cpp @@ -16,19 +16,22 @@ #include "log_table_manager_factory.h" #include "cloud_sync_log_table_manager.h" #include "collaboration_log_table_manager.h" +#include "device_tracker_log_table_manager.h" #include "split_device_log_table_manager.h" namespace DistributedDB { -std::unique_ptr LogTableManagerFactory::GetTableManager(DistributedTableMode mode, - TableSyncType syncType) +std::unique_ptr LogTableManagerFactory::GetTableManager(const TableInfo &tableInfo, + DistributedTableMode mode, TableSyncType syncType) { if (syncType == CLOUD_COOPERATION) { return std::make_unique(); - } else { - if (mode == DistributedTableMode::COLLABORATION) { - return std::make_unique(); - } + } + if (!tableInfo.GetTrackerTable().IsEmpty()) { + return std::make_unique(); + } + if (mode == DistributedTableMode::SPLIT_BY_DEVICE) { return std::make_unique(); } + return std::make_unique(); } } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.h index b31f9d508ad..623f7852b16 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/log_table_manager_factory.h @@ -24,7 +24,8 @@ namespace DistributedDB { class LogTableManagerFactory final { public: - static std::unique_ptr GetTableManager(DistributedTableMode mode, TableSyncType syncType); + static std::unique_ptr GetTableManager(const TableInfo &tableInfo, + DistributedTableMode mode, TableSyncType syncType); private: LogTableManagerFactory() {} diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp index 9c25c59b2ad..5f6d1d8d489 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp @@ -128,7 +128,7 @@ int SqliteRelationalDatabaseUpgrader::UpgradeTrigger(const std::string &logTable TableInfo tableInfo = table.second; tableInfo.SetTrackerTable(trackerSchemaObj.GetTrackerTable(table.first)); tableInfo.SetDistributedTable(schemaObj.GetDistributedTable(table.first)); - auto manager = LogTableManagerFactory::GetTableManager(mode, tableInfo.GetTableSyncType()); + auto manager = LogTableManagerFactory::GetTableManager(tableInfo, mode, tableInfo.GetTableSyncType()); errCode = manager->AddRelationalLogTableTrigger(db_, tableInfo, ""); if (errCode != E_OK) { LOGE("[Relational][Upgrade] recreate distributed trigger failed. err:%d", errCode); 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 d75cb372593..195205e110e 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 @@ -1165,6 +1165,7 @@ int SQLiteSingleRelationalStorageEngine::SetDistributedSchemaInTraction(Relation continue; } TableInfo tableInfo = schemaObj.GetTable(table.tableName); + tableInfo.SetTrackerTable(GetTrackerSchema().GetTrackerTable(table.tableName)); if (tableInfo.Empty()) { continue; } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h index 4e82a5899b9..7f98adb6e1d 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h @@ -128,7 +128,7 @@ private: int SetDistributedSchemaInner(RelationalSchemaObject &schemaObj, const DistributedSchema &schema, const std::string &localIdentity, bool isForceUpgrade); - static int SetDistributedSchemaInTraction(RelationalSchemaObject &schemaObj, const DistributedSchema &schema, + int SetDistributedSchemaInTraction(RelationalSchemaObject &schemaObj, const DistributedSchema &schema, const std::string &localIdentity, bool isForceUpgrade, SQLiteSingleVerRelationalStorageExecutor &handle); RelationalSchemaObject schema_; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp index ece7e590b35..1ac223e2973 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp @@ -220,11 +220,7 @@ int SQLiteSingleVerRelationalStorageExecutor::CreateRelationalLogTable(Distribut { // create log table std::unique_ptr tableManager; - if (!table.GetTrackerTable().IsEmpty() && table.GetTableSyncType() == TableSyncType::DEVICE_COOPERATION) { - tableManager = std::make_unique(); - } else { - tableManager = LogTableManagerFactory::GetTableManager(mode, table.GetTableSyncType()); - } + tableManager = LogTableManagerFactory::GetTableManager(table, mode, table.GetTableSyncType()); if (tableManager == nullptr) { LOGE("[CreateRelationalLogTable] get table manager failed"); return -E_INVALID_DB; @@ -1910,7 +1906,7 @@ int SQLiteSingleVerRelationalStorageExecutor::UpdateHashKey(DistributedTableMode if (tableInfo.GetIdentifyKey().size() == 1u && tableInfo.GetIdentifyKey().at(0) == "rowid") { return UpdateHashKeyWithOutPk(mode, tableInfo, syncType, localIdentity); } - auto tableManager = LogTableManagerFactory::GetTableManager(mode, syncType); + auto tableManager = LogTableManagerFactory::GetTableManager(tableInfo, mode, syncType); auto logName = DBCommon::GetLogTableName(tableInfo.GetTableName()); std::string sql = "UPDATE OR REPLACE " + logName + " SET hash_key = hash_key || '_old' where data_key in " + "(select _rowid_ from '" + tableInfo.GetTableName() + "') AND device IS NULL;"; @@ -1928,7 +1924,7 @@ int SQLiteSingleVerRelationalStorageExecutor::UpdateHashKey(DistributedTableMode int SQLiteSingleVerRelationalStorageExecutor::UpdateHashKeyWithOutPk( DistributedTableMode mode, const TableInfo &tableInfo, TableSyncType syncType, const std::string &localIdentity) { - auto tableManager = LogTableManagerFactory::GetTableManager(mode, syncType); + auto tableManager = LogTableManagerFactory::GetTableManager(tableInfo, mode, syncType); auto logName = DBCommon::GetLogTableName(tableInfo.GetTableName()); std::string extendStr = "_tmp"; std::string tmpTable = logName + extendStr; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp index 7e1ee410f7a..d3ec3f3a3e1 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp @@ -1124,7 +1124,7 @@ int SQLiteSingleVerRelationalStorageExecutor::BindStmtWithCloudGidInner(const st int SQLiteSingleVerRelationalStorageExecutor::RenewTableTrigger(DistributedTableMode mode, const TableInfo &tableInfo, TableSyncType syncType, const std::string &localIdentity) { - auto tableManager = LogTableManagerFactory::GetTableManager(mode, syncType); + auto tableManager = LogTableManagerFactory::GetTableManager(tableInfo, mode, syncType); return tableManager->AddRelationalLogTableTrigger(dbHandle_, tableInfo, localIdentity); } diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_log_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_log_test.cpp index c64cfb6ca2d..b07666e671c 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_log_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_log_test.cpp @@ -60,7 +60,8 @@ HWTEST_F(DistributedDBInterfacesLogTest, DBFactoryTest001, TestSize.Level1) { DistributedTableMode mode = DistributedTableMode::COLLABORATION; TableSyncType tableSyncType = TableSyncType::DEVICE_COOPERATION; - auto tableManager = LogTableManagerFactory::GetTableManager(mode, tableSyncType); + TableInfo tableInfo; + auto tableManager = LogTableManagerFactory::GetTableManager(tableInfo, mode, tableSyncType); EXPECT_TRUE(tableManager != nullptr); } diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp index 6ac776f9d11..390ae384144 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp @@ -95,7 +95,8 @@ void CreateLogTable(const std::string &tableName) sqlite3 *db = nullptr; ASSERT_EQ(sqlite3_open(g_storePath.c_str(), &db), SQLITE_OK); auto tableManager = - LogTableManagerFactory::GetTableManager(DistributedTableMode::COLLABORATION, TableSyncType::CLOUD_COOPERATION); + LogTableManagerFactory::GetTableManager(table, DistributedTableMode::COLLABORATION, + TableSyncType::CLOUD_COOPERATION); int errCode = tableManager->CreateRelationalLogTable(db, table); EXPECT_EQ(errCode, E_OK); sqlite3_close(db); -- Gitee