From a6cc4d79f8da17a73680ad6a6a3d76a80b9cc7bb Mon Sep 17 00:00:00 2001 From: LeiiYB Date: Sat, 13 Sep 2025 17:10:10 +0800 Subject: [PATCH] add notify Signed-off-by: LeiiYB --- frameworks/native/rdb/src/connection_pool.cpp | 5 +-- .../native/rdb/src/rdb_store_config.cpp | 10 ++++++ .../inner_api/rdb/include/rdb_store_config.h | 19 +++++++--- .../rdb/mock/include/rdb_store_config.h | 3 ++ .../ets/test/RdbStoreTransaction.test.ets | 35 +++++++++++++++++++ 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/frameworks/native/rdb/src/connection_pool.cpp b/frameworks/native/rdb/src/connection_pool.cpp index a2a3b4805..b0329150c 100644 --- a/frameworks/native/rdb/src/connection_pool.cpp +++ b/frameworks/native/rdb/src/connection_pool.cpp @@ -164,7 +164,7 @@ std::pair> ConnPool::Init(bool isAttach, bo if (errCode != E_OK) { return result; } - trans_.InitMembers(create, MAX_TRANS, 0, false); + trans_.InitMembers(create, MAX_TRANS, config.GetTransactionTime(), false); } isAttach_ = isAttach; maxReader_ = GetMaxReaders(config); @@ -438,7 +438,7 @@ int ConnPool::RestartConns() const RdbStoreConfig &config = isAttach_ ? attachConfig_ : config_; return Connection::Create(config, true); }, - MAX_TRANS, 0, false); + MAX_TRANS, config.GetTransactionTime(), false); return errCode; } @@ -687,6 +687,7 @@ void ConnPool::Container::InitMembers(Creator creator, int32_t max, int32_t time max_ = max; creator_ = creator; timeout_ = std::chrono::seconds(timeout); + cond_.notify_all(); } std::pair> ConnPool::Container::Initialize( diff --git a/frameworks/native/rdb/src/rdb_store_config.cpp b/frameworks/native/rdb/src/rdb_store_config.cpp index cce7a123d..03f21b45d 100644 --- a/frameworks/native/rdb/src/rdb_store_config.cpp +++ b/frameworks/native/rdb/src/rdb_store_config.cpp @@ -521,6 +521,16 @@ void RdbStoreConfig::SetWriteTime(int timeout) writeTimeout_ = std::max(MIN_TIMEOUT, std::min(MAX_TIMEOUT, timeout)); } +int RdbStoreConfig::GetTransactionTime() const +{ + return transactionTimeout_; +} + +void RdbStoreConfig::SetTransactionTime(int timeout) +{ + transactionTimeout_ = std::max(MIN_TIMEOUT, std::min(MAX_TIMEOUT, timeout)); +} + bool RdbStoreConfig::IsCustomEncryptParam() const { return customEncryptParam_; diff --git a/interfaces/inner_api/rdb/include/rdb_store_config.h b/interfaces/inner_api/rdb/include/rdb_store_config.h index 6fcda5644..ded36d299 100644 --- a/interfaces/inner_api/rdb/include/rdb_store_config.h +++ b/interfaces/inner_api/rdb/include/rdb_store_config.h @@ -738,23 +738,33 @@ public: void SetSearchable(bool searchable); /** - * @brief Sets the timeout to get write connection for the object. + * @brief Gets the timeout to get write connection for the object. */ int GetWriteTime() const; /** - * @brief Gets the timeout to get write connection for the object. + * @brief Sets the timeout to get write connection for the object. */ void SetWriteTime(int timeout); /** - * @brief Sets the timeout to get read connection for the object. + * @brief Gets the timeout to get transaction connection for the object. */ - int GetReadTime() const; + int GetTransactionTime() const; + + /** + * @brief Sets the timeout to get transaction connection for the object. + */ + void SetTransactionTime(int timeout); /** * @brief Gets the timeout to get read connection for the object. */ + int GetReadTime() const; + + /** + * @brief Sets the timeout to get read connection for the object. + */ void SetReadTime(int timeout); void SetRoleType(RoleType role); @@ -851,6 +861,7 @@ private: int32_t readConSize_ = 4; int32_t area_ = 0; int32_t writeTimeout_ = 2; // seconds + int32_t transactionTimeout_ = 2; // seconds int32_t readTimeout_ = 1; // seconds int32_t dbType_ = DB_SQLITE; int32_t haMode_ = HAMode::SINGLE; diff --git a/interfaces/inner_api/rdb/mock/include/rdb_store_config.h b/interfaces/inner_api/rdb/mock/include/rdb_store_config.h index 22c21a751..648251556 100644 --- a/interfaces/inner_api/rdb/mock/include/rdb_store_config.h +++ b/interfaces/inner_api/rdb/mock/include/rdb_store_config.h @@ -337,6 +337,8 @@ public: void SetSearchable(bool searchable); int GetWriteTime() const; void SetWriteTime(int timeout); + int GetTransactionTime() const; + void SetTransactionTime(int timeout); int GetReadTime() const; void SetReadTime(int timeout); void SetRoleType(RoleType role); @@ -397,6 +399,7 @@ private: int32_t readConSize_ = 4; int32_t area_ = 0; int32_t writeTimeout_ = 2; // seconds + int32_t transactionTimeout_ = 2; // seconds int32_t readTimeout_ = 1; // seconds int32_t dbType_ = DB_SQLITE; int32_t haMode_ = HAMode::SINGLE; diff --git a/test/ets/relational_store/entry/src/main/ets/test/RdbStoreTransaction.test.ets b/test/ets/relational_store/entry/src/main/ets/test/RdbStoreTransaction.test.ets index 0170d9e87..23dd8db02 100644 --- a/test/ets/relational_store/entry/src/main/ets/test/RdbStoreTransaction.test.ets +++ b/test/ets/relational_store/entry/src/main/ets/test/RdbStoreTransaction.test.ets @@ -2724,6 +2724,41 @@ export default function () { done() console.log(TAG + "************* testSqliteLocked0011 end *************"); }) + + /** + * @tc.number testConcurrentTransction0001 + * @tc.name testConcurrentTransction + * @tc.desc Concurrent of creating transaction and executing DDL + */ + it('testConcurrentTransction0001', 0, async function (done) { + console.log(TAG + "************* testConcurrentTransction0001 start *************"); + + const CREATE_TABLE_SQL_PRE = "CREATE TABLE IF NOT EXISTS "; + const CREATE_TABLE_SQL_SUF = " (id INTEGER PRIMARY KEY, " + + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; + const CONFIG = { + name: "ConcurrentTransction.db", + securityLevel: data_relationalStore.SecurityLevel.S1, + } + let transaction: relationalStore.Transaction; + try { + let store = await data_relationalStore.getRdbStore(context, CONFIG); + for (let i = 0; i < 1000; i++) { + store.execute(CREATE_TABLE_SQL_PRE + "test" + i + CREATE_TABLE_SQL_SUF); + store.execute('DROP TABLE IF EXISTS test' + i); + let transaction = await store.createTransaction(); + await transaction.commit(); + } + console.error(TAG + 'testConcurrentTransction0001 success'); + } catch (err) { + console.info(TAG + 'err code: ' + err.code + 'err message: ' + err.message); + console.info(TAG + "testConcurrentTransction0001 failed"); + expect(null).assertFail() + } + await data_relationalStore.deleteRdbStore(context, CONFIG); + done() + console.log(TAG + "************* testConcurrentTransction0001 end *************"); + }) console.log(TAG + "*************Unit Test End*************"); }) } \ No newline at end of file -- Gitee