mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-23 07:00:41 +00:00
correct error codes
Signed-off-by: lobty <butaoyu@huawei.com>
This commit is contained in:
parent
c8f00eef41
commit
d30eec7087
@ -2557,7 +2557,7 @@ int RdbStoreImpl::InterruptBackup()
|
||||
slaveStatus_ = SlaveStatus::BACKUP_INTERRUPT;
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_INTERRUPT;
|
||||
return E_CANCEL;
|
||||
}
|
||||
|
||||
int32_t RdbStoreImpl::GetBackupStatus() const
|
||||
|
@ -1341,7 +1341,7 @@ int SqliteConnection::ExchangeSlaverToMaster(bool isRestore, SlaveStatus &curSta
|
||||
do {
|
||||
if (!isRestore && curStatus == SlaveStatus::BACKUP_INTERRUPT) {
|
||||
LOG_INFO("backup slave was interrupt!");
|
||||
rc = E_BACKUP_INTERRUPT;
|
||||
rc = E_CANCEL;
|
||||
break;
|
||||
}
|
||||
rc = sqlite3_backup_step(pBackup, BACKUP_PAGES_PRE_STEP);
|
||||
@ -1363,7 +1363,7 @@ int SqliteConnection::ExchangeSlaverToMaster(bool isRestore, SlaveStatus &curSta
|
||||
}
|
||||
curStatus = SlaveStatus::BACKUP_INTERRUPT;
|
||||
}
|
||||
return rc == E_BACKUP_INTERRUPT ? E_BACKUP_INTERRUPT : SQLiteError::ErrNo(rc);
|
||||
return rc == E_CANCEL ? E_CANCEL : SQLiteError::ErrNo(rc);
|
||||
}
|
||||
rc = isRestore ? TryCheckPoint(true) : slaveConnection_->TryCheckPoint(true);
|
||||
if (rc != E_OK && config_.GetHaMode() == HAMode::MANUAL_TRIGGER) {
|
||||
@ -1388,7 +1388,7 @@ ExchangeStrategy SqliteConnection::GenerateExchangeStrategy(const SlaveStatus &s
|
||||
}
|
||||
static const std::string querySql = "SELECT COUNT(*) FROM sqlite_master WHERE type='table';";
|
||||
auto [mRet, mObj] = ExecuteForValue(querySql);
|
||||
if (mRet != E_OK) {
|
||||
if (mRet == E_SQLITE_CORRUPT) {
|
||||
LOG_WARN("main abnormal, err:%{public}d", mRet);
|
||||
return ExchangeStrategy::RESTORE;
|
||||
}
|
||||
@ -1398,7 +1398,7 @@ ExchangeStrategy SqliteConnection::GenerateExchangeStrategy(const SlaveStatus &s
|
||||
return mCount == 0 ? ExchangeStrategy::RESTORE : ExchangeStrategy::NOT_HANDLE;
|
||||
}
|
||||
auto [sRet, sObj] = slaveConnection_->ExecuteForValue(querySql);
|
||||
if (sRet != E_OK) {
|
||||
if (sRet == E_SQLITE_CORRUPT) {
|
||||
LOG_WARN("slave db abnormal, need backup, err:%{public}d", sRet);
|
||||
return ExchangeStrategy::BACKUP;
|
||||
}
|
||||
@ -1464,13 +1464,13 @@ int SqliteConnection::IsRepairable()
|
||||
}
|
||||
if (SqliteUtils::TryAccessSlaveLock(config_.GetPath(), false, false, false)) {
|
||||
LOG_ERROR("unavailable slave, %{public}s", config_.GetName().c_str());
|
||||
return E_DB_RESTORE_NOT_ALLOWED;
|
||||
return E_SQLITE_CORRUPT;
|
||||
}
|
||||
std::string querySql = "SELECT COUNT(*) FROM sqlite_master WHERE type='table';";
|
||||
auto [qRet, qObj] = slaveConnection_->ExecuteForValue(querySql);
|
||||
if (qRet != E_OK || (static_cast<int64_t>(qObj) == 0L)) {
|
||||
if (qRet == E_SQLITE_CORRUPT || (static_cast<int64_t>(qObj) == 0L)) {
|
||||
LOG_INFO("cancel repair, ret:%{public}d", qRet);
|
||||
return E_DB_RESTORE_NOT_ALLOWED;
|
||||
return E_SQLITE_CORRUPT;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
@ -1504,7 +1504,7 @@ int SqliteConnection::ExchangeVerify(bool isRestore)
|
||||
}
|
||||
if (SqliteUtils::TryAccessSlaveLock(config_.GetPath(), false, false, true)) {
|
||||
LOG_ERROR("incomplete slave, %{public}s", config_.GetName().c_str());
|
||||
return E_DB_RESTORE_NOT_ALLOWED;
|
||||
return E_NOT_SUPPORTED;
|
||||
}
|
||||
} else {
|
||||
auto [cRet, cObj] = ExecuteForValue(INTEGRITIES[1]); // 1 is quick_check
|
||||
|
@ -401,19 +401,9 @@ static constexpr int E_SERVICE_NOT_FOUND = (E_BASE + 0x47);
|
||||
static constexpr int E_SQLITE_SCHEMA = (E_BASE + 0x48);
|
||||
|
||||
/**
|
||||
* @brief Database backup was interrupted.
|
||||
* @brief Operation cancel.
|
||||
*/
|
||||
static constexpr int E_BACKUP_INTERRUPT = (E_BASE + 0x49);
|
||||
|
||||
/**
|
||||
* @brief Backup interrupt operation is invalid.
|
||||
*/
|
||||
static constexpr int E_INVALID_INTERRUPT = (E_BASE + 0x4a);
|
||||
|
||||
/**
|
||||
* @brief Restore is not allowed.
|
||||
*/
|
||||
static constexpr int E_DB_RESTORE_NOT_ALLOWED = (E_BASE + 0x4b);
|
||||
static constexpr int E_CANCEL = (E_BASE + 0x49);
|
||||
|
||||
/**
|
||||
* @brief Do not use except relational_store
|
||||
|
366
test/native/rdb/unittest/rdb_double_write_concurrent_test.cpp
Normal file
366
test/native/rdb/unittest/rdb_double_write_concurrent_test.cpp
Normal file
@ -0,0 +1,366 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define LOG_TAG "RdbDoubleWriteConcurrentTest"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "sys/types.h"
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "logger.h"
|
||||
#include "common.h"
|
||||
#include "sqlite_utils.h"
|
||||
#include "file_ex.h"
|
||||
#include "rdb_common.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_open_callback.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::NativeRdb;
|
||||
using namespace OHOS::Rdb;
|
||||
|
||||
class RdbDoubleWriteConcurrentTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
void CheckNumber(std::shared_ptr<RdbStore> &store, int num, int errCode = E_OK,
|
||||
const std::string &tableName = "test");
|
||||
void Insert(int64_t start, int count, bool isSlave = false, int dataSize = 0);
|
||||
void WaitForBackupFinish(int32_t expectStatus, int maxTimes = 400);
|
||||
void TryInterruptBackup();
|
||||
void InitDb();
|
||||
|
||||
protected:
|
||||
const std::string DATABASE_NAME = RDB_TEST_PATH + "dual_concurrent.db";
|
||||
const std::string SLAVE_DATABASE_NAME = RDB_TEST_PATH + "dual_concurrent_slave.db";
|
||||
std::shared_ptr<RdbStore> store = nullptr;
|
||||
std::shared_ptr<RdbStore> slaveStore = nullptr;
|
||||
|
||||
class Callback : public RdbOpenCallback {
|
||||
public:
|
||||
int OnCreate(RdbStore &store) override;
|
||||
int OnUpgrade(RdbStore &store, int oldVersion, int newVersion) override;
|
||||
|
||||
protected:
|
||||
const std::string CREATE_TABLE_TEST =
|
||||
"CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
"name TEXT NOT NULL, age INTEGER, salary "
|
||||
"REAL, blobType BLOB)";
|
||||
};
|
||||
|
||||
enum SlaveStatus : uint32_t {
|
||||
UNDEFINED,
|
||||
DB_NOT_EXITS,
|
||||
BACKING_UP,
|
||||
BACKUP_INTERRUPT,
|
||||
BACKUP_FINISHED,
|
||||
};
|
||||
};
|
||||
|
||||
int RdbDoubleWriteConcurrentTest::Callback::OnCreate(RdbStore &store)
|
||||
{
|
||||
return store.ExecuteSql(CREATE_TABLE_TEST);
|
||||
}
|
||||
|
||||
int RdbDoubleWriteConcurrentTest::Callback::OnUpgrade(RdbStore &store, int oldVersion, int newVersion)
|
||||
{
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
void RdbDoubleWriteConcurrentTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void RdbDoubleWriteConcurrentTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void RdbDoubleWriteConcurrentTest::SetUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void RdbDoubleWriteConcurrentTest::TearDown(void)
|
||||
{
|
||||
store = nullptr;
|
||||
slaveStore = nullptr;
|
||||
RdbHelper::DeleteRdbStore(RdbDoubleWriteConcurrentTest::DATABASE_NAME);
|
||||
}
|
||||
|
||||
void RdbDoubleWriteConcurrentTest::InitDb()
|
||||
{
|
||||
int errCode = E_OK;
|
||||
RdbStoreConfig config(RdbDoubleWriteConcurrentTest::DATABASE_NAME);
|
||||
config.SetHaMode(HAMode::MAIN_REPLICA);
|
||||
RdbDoubleWriteConcurrentTest::Callback helper;
|
||||
RdbDoubleWriteConcurrentTest::store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteConcurrentTest::store, nullptr);
|
||||
|
||||
RdbStoreConfig slaveConfig(RdbDoubleWriteConcurrentTest::SLAVE_DATABASE_NAME);
|
||||
RdbDoubleWriteConcurrentTest::Callback slaveHelper;
|
||||
RdbDoubleWriteConcurrentTest::slaveStore = RdbHelper::GetRdbStore(slaveConfig, 1, slaveHelper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteConcurrentTest::slaveStore, nullptr);
|
||||
store->ExecuteSql("DELETE FROM test");
|
||||
slaveStore->ExecuteSql("DELETE FROM test");
|
||||
}
|
||||
|
||||
void RdbDoubleWriteConcurrentTest::Insert(int64_t start, int count, bool isSlave, int dataSize)
|
||||
{
|
||||
ValuesBucket values;
|
||||
int64_t id = start;
|
||||
int ret = E_OK;
|
||||
for (int i = 0; i < count; i++) {
|
||||
values.Clear();
|
||||
values.PutInt("id", id);
|
||||
if (dataSize > 0) {
|
||||
values.PutString("name", std::string(dataSize, 'a'));
|
||||
} else {
|
||||
values.PutString("name", std::string("zhangsan"));
|
||||
}
|
||||
values.PutInt("age", 18); // 18 is data
|
||||
values.PutDouble("salary", 100.5); // 100.5 is data
|
||||
values.PutBlob("blobType", std::vector<uint8_t>{ 1, 2, 3 });
|
||||
if (isSlave) {
|
||||
ret = slaveStore->Insert(id, "test", values);
|
||||
} else {
|
||||
ret = store->Insert(id, "test", values);
|
||||
}
|
||||
EXPECT_EQ(ret, E_OK);
|
||||
id++;
|
||||
}
|
||||
}
|
||||
|
||||
void RdbDoubleWriteConcurrentTest::WaitForBackupFinish(int32_t expectStatus, int maxTimes)
|
||||
{
|
||||
int32_t curStatus = store->GetBackupStatus();
|
||||
int tryTimes = 0;
|
||||
while (curStatus != expectStatus && (++tryTimes <= maxTimes)) {
|
||||
usleep(50000); // 50000 delay
|
||||
curStatus = store->GetBackupStatus();
|
||||
}
|
||||
LOG_INFO("----------cur backup Status:%{public}d---------", curStatus);
|
||||
ASSERT_EQ(curStatus, expectStatus);
|
||||
}
|
||||
|
||||
void RdbDoubleWriteConcurrentTest::TryInterruptBackup()
|
||||
{
|
||||
int err = store->InterruptBackup();
|
||||
int tryTimes = 0;
|
||||
while (err != E_OK && (++tryTimes <= 1000)) { // 1000 is try time
|
||||
usleep(10000); // 10000 delay
|
||||
err = store->InterruptBackup();
|
||||
}
|
||||
EXPECT_EQ(err, E_OK);
|
||||
LOG_INFO("----------interrupt backup---------");
|
||||
}
|
||||
|
||||
void RdbDoubleWriteConcurrentTest::CheckNumber(std::shared_ptr<RdbStore> &store, int num, int errCode,
|
||||
const std::string &tableName)
|
||||
{
|
||||
std::shared_ptr<ResultSet> resultSet =
|
||||
store->QuerySql("SELECT * FROM " + tableName);
|
||||
ASSERT_NE(resultSet, nullptr);
|
||||
int countNum;
|
||||
int ret = resultSet->GetRowCount(countNum);
|
||||
EXPECT_EQ(ret, errCode);
|
||||
EXPECT_EQ(num, countNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_DoubleWrite_022
|
||||
* @tc.desc: open SINGLE db, write, close, reopen MAIN_REPLICA db, wait for backup, insert, check count
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbDoubleWriteConcurrentTest, RdbStore_DoubleWrite_022, TestSize.Level1)
|
||||
{
|
||||
int errCode = E_OK;
|
||||
RdbStoreConfig config(RdbDoubleWriteConcurrentTest::DATABASE_NAME);
|
||||
config.SetHaMode(HAMode::SINGLE);
|
||||
RdbDoubleWriteConcurrentTest::Callback helper;
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
|
||||
int64_t id = 10;
|
||||
int strSize = 1024 * 100;
|
||||
int count = 1000;
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_022 insert finish");
|
||||
|
||||
store = nullptr;
|
||||
config.SetHaMode(HAMode::MAIN_REPLICA);
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
ASSERT_NE(store, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_022 reopen db finish");
|
||||
|
||||
WaitForBackupFinish(BACKUP_FINISHED);
|
||||
|
||||
id = 6666;
|
||||
Insert(id, count);
|
||||
LOG_INFO("RdbStore_DoubleWrite_022 insert db finish");
|
||||
|
||||
RdbStoreConfig slaveConfig(RdbDoubleWriteConcurrentTest::SLAVE_DATABASE_NAME);
|
||||
RdbDoubleWriteConcurrentTest::Callback slaveHelper;
|
||||
RdbDoubleWriteConcurrentTest::slaveStore = RdbHelper::GetRdbStore(slaveConfig, 1, slaveHelper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteConcurrentTest::slaveStore, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_022 reopen slave db finish");
|
||||
|
||||
RdbDoubleWriteConcurrentTest::CheckNumber(store, count + count);
|
||||
RdbDoubleWriteConcurrentTest::CheckNumber(slaveStore, count + count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_DoubleWrite_023
|
||||
* @tc.desc: open MANUAL_TRIGGER db, write, backup async, interrupt, backup async, wait finish, check count
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbDoubleWriteConcurrentTest, RdbStore_DoubleWrite_023, TestSize.Level1)
|
||||
{
|
||||
int errCode = E_OK;
|
||||
RdbStoreConfig config(RdbDoubleWriteConcurrentTest::DATABASE_NAME);
|
||||
config.SetHaMode(HAMode::MANUAL_TRIGGER);
|
||||
RdbDoubleWriteConcurrentTest::Callback helper;
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
ASSERT_TRUE(store->IsSlaveDiffFromMaster());
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 reopen finish");
|
||||
|
||||
int64_t id = 10;
|
||||
int strSize = 1024 * 100;
|
||||
int count = 1000;
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 insert finish");
|
||||
|
||||
std::thread thread([this]() {
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 t1 backup begin");
|
||||
EXPECT_EQ(store->Backup(std::string(""), {}), E_CANCEL);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 t1 backup end");
|
||||
});
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 begin interrupt");
|
||||
TryInterruptBackup();
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 interrupt end");
|
||||
EXPECT_EQ(store->GetBackupStatus(), SlaveStatus::BACKUP_INTERRUPT);
|
||||
thread.join();
|
||||
|
||||
std::thread thread1([this]() {
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 t2 backup begin");
|
||||
EXPECT_EQ(store->Backup(std::string(""), {}), E_OK);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 t2 backup end");
|
||||
});
|
||||
WaitForBackupFinish(BACKUP_FINISHED);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 wait finish");
|
||||
thread1.join();
|
||||
|
||||
RdbStoreConfig slaveConfig(RdbDoubleWriteConcurrentTest::SLAVE_DATABASE_NAME);
|
||||
RdbDoubleWriteConcurrentTest::Callback slaveHelper;
|
||||
RdbDoubleWriteConcurrentTest::slaveStore = RdbHelper::GetRdbStore(slaveConfig, 1, slaveHelper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteConcurrentTest::slaveStore, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 reopen slave db finish");
|
||||
|
||||
RdbDoubleWriteConcurrentTest::CheckNumber(store, count);
|
||||
RdbDoubleWriteConcurrentTest::CheckNumber(slaveStore, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_DoubleWrite_024
|
||||
* @tc.desc: open SINGLE db, write, close, reopen MAIN_REPLICA db, wait for backup, insert, check count
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbDoubleWriteConcurrentTest, RdbStore_DoubleWrite_024, TestSize.Level1)
|
||||
{
|
||||
int errCode = E_OK;
|
||||
RdbStoreConfig config(RdbDoubleWriteConcurrentTest::DATABASE_NAME);
|
||||
config.SetHaMode(HAMode::SINGLE);
|
||||
RdbDoubleWriteConcurrentTest::Callback helper;
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
|
||||
int64_t id = 10;
|
||||
int strSize = 1024 * 100;
|
||||
int count = 1000;
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 insert finish");
|
||||
|
||||
store = nullptr;
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 close finish");
|
||||
config.SetHaMode(HAMode::MAIN_REPLICA);
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
ASSERT_NE(store, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 reopen db finish");
|
||||
|
||||
usleep(200000); // 200000 us delay
|
||||
store = nullptr;
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 close again");
|
||||
|
||||
RdbStoreConfig slaveConfig(RdbDoubleWriteConcurrentTest::SLAVE_DATABASE_NAME);
|
||||
RdbDoubleWriteConcurrentTest::Callback slaveHelper;
|
||||
RdbDoubleWriteConcurrentTest::slaveStore = RdbHelper::GetRdbStore(slaveConfig, 1, slaveHelper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteConcurrentTest::slaveStore, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 reopen slave");
|
||||
RdbDoubleWriteConcurrentTest::CheckNumber(slaveStore, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_DoubleWrite_025
|
||||
* @tc.desc: open SINGLE db, write, close, reopen MAIN_REPLICA db, insert, wait for backup, check count
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbDoubleWriteConcurrentTest, RdbStore_DoubleWrite_025, TestSize.Level1)
|
||||
{
|
||||
int errCode = E_OK;
|
||||
RdbStoreConfig config(RdbDoubleWriteConcurrentTest::DATABASE_NAME);
|
||||
config.SetHaMode(HAMode::SINGLE);
|
||||
RdbDoubleWriteConcurrentTest::Callback helper;
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
|
||||
int64_t id = 10;
|
||||
int strSize = 1024 * 100;
|
||||
int count = 1000;
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 insert finish");
|
||||
|
||||
store = nullptr;
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 close finish");
|
||||
config.SetHaMode(HAMode::MAIN_REPLICA);
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
ASSERT_NE(store, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 reopen db finish");
|
||||
|
||||
id = 6666;
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 begin insert");
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 insert end");
|
||||
|
||||
WaitForBackupFinish(BACKUP_FINISHED, 1000); // 1000 is max retry time
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 wait finish");
|
||||
|
||||
RdbStoreConfig slaveConfig(RdbDoubleWriteConcurrentTest::SLAVE_DATABASE_NAME);
|
||||
RdbDoubleWriteConcurrentTest::Callback slaveHelper;
|
||||
RdbDoubleWriteConcurrentTest::slaveStore = RdbHelper::GetRdbStore(slaveConfig, 1, slaveHelper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteConcurrentTest::slaveStore, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 reopen slave");
|
||||
|
||||
RdbDoubleWriteConcurrentTest::CheckNumber(store, count + count);
|
||||
std::shared_ptr<ResultSet> resultSet = slaveStore->QuerySql("SELECT * FROM test");
|
||||
ASSERT_NE(resultSet, nullptr);
|
||||
int countNum;
|
||||
EXPECT_EQ(resultSet->GetRowCount(countNum), errCode);
|
||||
EXPECT_GT(countNum, count);
|
||||
EXPECT_LE(countNum, count + count);
|
||||
}
|
@ -911,189 +911,6 @@ HWTEST_F(RdbDoubleWriteTest, RdbStore_DoubleWrite_019, TestSize.Level1)
|
||||
ASSERT_FALSE(isFlagFileExists);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_DoubleWrite_022
|
||||
* @tc.desc: open SINGLE db, write, close, reopen MAIN_REPLICA db, wait for backup, insert, check count
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbDoubleWriteTest, RdbStore_DoubleWrite_022, TestSize.Level1)
|
||||
{
|
||||
int errCode = E_OK;
|
||||
RdbStoreConfig config(RdbDoubleWriteTest::DATABASE_NAME);
|
||||
config.SetHaMode(HAMode::SINGLE);
|
||||
DoubleWriteTestOpenCallback helper;
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
|
||||
int64_t id = 10;
|
||||
int strSize = 1024 * 100;
|
||||
int count = 2000;
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_022 insert finish");
|
||||
|
||||
store = nullptr;
|
||||
config.SetHaMode(HAMode::MAIN_REPLICA);
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
ASSERT_NE(store, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_022 reopen db finish");
|
||||
|
||||
WaitForBackupFinish(BACKUP_FINISHED);
|
||||
|
||||
id = 6666;
|
||||
Insert(id, count);
|
||||
LOG_INFO("RdbStore_DoubleWrite_022 insert db finish");
|
||||
|
||||
RdbStoreConfig slaveConfig(RdbDoubleWriteTest::SLAVE_DATABASE_NAME);
|
||||
DoubleWriteTestOpenCallback slaveHelper;
|
||||
RdbDoubleWriteTest::slaveStore = RdbHelper::GetRdbStore(slaveConfig, 1, slaveHelper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteTest::slaveStore, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_022 reopen slave db finish");
|
||||
|
||||
RdbDoubleWriteTest::CheckNumber(store, count + count);
|
||||
RdbDoubleWriteTest::CheckNumber(slaveStore, count + count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_DoubleWrite_023
|
||||
* @tc.desc: open MANUAL_TRIGGER db, write, backup async, interrupt, backup async, wait finish, check count
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbDoubleWriteTest, RdbStore_DoubleWrite_023, TestSize.Level1)
|
||||
{
|
||||
int errCode = E_OK;
|
||||
RdbStoreConfig config(RdbDoubleWriteTest::DATABASE_NAME);
|
||||
config.SetHaMode(HAMode::MANUAL_TRIGGER);
|
||||
DoubleWriteTestOpenCallback helper;
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
ASSERT_TRUE(store->IsSlaveDiffFromMaster());
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 reopen finish");
|
||||
|
||||
int64_t id = 10;
|
||||
int strSize = 1024 * 100;
|
||||
int count = 2000;
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 insert finish");
|
||||
|
||||
std::thread thread([this]() {
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 t1 backup begin");
|
||||
EXPECT_EQ(store->Backup(std::string(""), {}), E_BACKUP_INTERRUPT);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 t1 backup end");
|
||||
});
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 begin interrupt");
|
||||
TryInterruptBackup();
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 interrupt end");
|
||||
EXPECT_EQ(store->GetBackupStatus(), SlaveStatus::BACKUP_INTERRUPT);
|
||||
thread.join();
|
||||
|
||||
std::thread thread1([this]() {
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 t2 backup begin");
|
||||
EXPECT_EQ(store->Backup(std::string(""), {}), E_OK);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 t2 backup end");
|
||||
});
|
||||
WaitForBackupFinish(BACKUP_FINISHED);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 wait finish");
|
||||
thread1.join();
|
||||
|
||||
RdbStoreConfig slaveConfig(RdbDoubleWriteTest::SLAVE_DATABASE_NAME);
|
||||
DoubleWriteTestOpenCallback slaveHelper;
|
||||
RdbDoubleWriteTest::slaveStore = RdbHelper::GetRdbStore(slaveConfig, 1, slaveHelper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteTest::slaveStore, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_023 reopen slave db finish");
|
||||
|
||||
RdbDoubleWriteTest::CheckNumber(store, count);
|
||||
RdbDoubleWriteTest::CheckNumber(slaveStore, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_DoubleWrite_024
|
||||
* @tc.desc: open SINGLE db, write, close, reopen MAIN_REPLICA db, wait for backup, insert, check count
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbDoubleWriteTest, RdbStore_DoubleWrite_024, TestSize.Level1)
|
||||
{
|
||||
int errCode = E_OK;
|
||||
RdbStoreConfig config(RdbDoubleWriteTest::DATABASE_NAME);
|
||||
config.SetHaMode(HAMode::SINGLE);
|
||||
DoubleWriteTestOpenCallback helper;
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
|
||||
int64_t id = 10;
|
||||
int strSize = 1024 * 200;
|
||||
int count = 1000;
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 insert finish");
|
||||
|
||||
store = nullptr;
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 close finish");
|
||||
config.SetHaMode(HAMode::MAIN_REPLICA);
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
ASSERT_NE(store, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 reopen db finish");
|
||||
|
||||
usleep(200000); // 200000 us delay
|
||||
store = nullptr;
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 close again");
|
||||
|
||||
RdbStoreConfig slaveConfig(RdbDoubleWriteTest::SLAVE_DATABASE_NAME);
|
||||
DoubleWriteTestOpenCallback slaveHelper;
|
||||
RdbDoubleWriteTest::slaveStore = RdbHelper::GetRdbStore(slaveConfig, 1, slaveHelper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteTest::slaveStore, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_024 reopen slave");
|
||||
RdbDoubleWriteTest::CheckNumber(slaveStore, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_DoubleWrite_025
|
||||
* @tc.desc: open SINGLE db, write, close, reopen MAIN_REPLICA db, insert, wait for backup, check count
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbDoubleWriteTest, RdbStore_DoubleWrite_025, TestSize.Level1)
|
||||
{
|
||||
int errCode = E_OK;
|
||||
RdbStoreConfig config(RdbDoubleWriteTest::DATABASE_NAME);
|
||||
config.SetHaMode(HAMode::SINGLE);
|
||||
DoubleWriteTestOpenCallback helper;
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
|
||||
int64_t id = 10;
|
||||
int strSize = 1024 * 200;
|
||||
int count = 1000;
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 insert finish");
|
||||
|
||||
store = nullptr;
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 close finish");
|
||||
config.SetHaMode(HAMode::MAIN_REPLICA);
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
ASSERT_NE(store, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 reopen db finish");
|
||||
|
||||
id = 6666;
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 begin insert");
|
||||
Insert(id, count, false, strSize);
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 insert end");
|
||||
|
||||
WaitForBackupFinish(BACKUP_FINISHED, 1000); // 1000 is max retry time
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 wait finish");
|
||||
|
||||
RdbStoreConfig slaveConfig(RdbDoubleWriteTest::SLAVE_DATABASE_NAME);
|
||||
DoubleWriteTestOpenCallback slaveHelper;
|
||||
RdbDoubleWriteTest::slaveStore = RdbHelper::GetRdbStore(slaveConfig, 1, slaveHelper, errCode);
|
||||
EXPECT_NE(RdbDoubleWriteTest::slaveStore, nullptr);
|
||||
LOG_INFO("RdbStore_DoubleWrite_025 reopen slave");
|
||||
|
||||
RdbDoubleWriteTest::CheckNumber(store, count + count);
|
||||
std::shared_ptr<ResultSet> resultSet = slaveStore->QuerySql("SELECT * FROM test");
|
||||
ASSERT_NE(resultSet, nullptr);
|
||||
int countNum;
|
||||
EXPECT_EQ(resultSet->GetRowCount(countNum), errCode);
|
||||
EXPECT_GT(countNum, count);
|
||||
EXPECT_LE(countNum, count + count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_DoubleWrite_026
|
||||
* @tc.desc: open MANUAL_TRIGGER db, write, restore, insert, check count
|
||||
|
Loading…
Reference in New Issue
Block a user