From 971ba75c591508a4f696d2d70f22c7d049b7b5fa Mon Sep 17 00:00:00 2001 From: suyuchen Date: Mon, 1 Jun 2026 18:45:57 +0800 Subject: [PATCH] verify not empty when mapping matrix file Signed-off-by: suyuchen --- .../common/include/matrix_file.h | 50 +++++++ .../include/relational/data_donation_utils.h | 5 +- .../distributeddb/common/src/matrix_file.cpp | 141 ++++++++++++++++++ .../src/relational/data_donation_utils.cpp | 114 +++++--------- .../libs/distributeddb/distributeddb.gni | 2 + .../rdb/distributeddb_basic_rdb_test.cpp | 82 +++++++--- .../distributeddb_data_donation_sql_test.cpp | 13 +- 7 files changed, 303 insertions(+), 104 deletions(-) create mode 100644 frameworks/libs/distributeddb/common/include/matrix_file.h create mode 100644 frameworks/libs/distributeddb/common/src/matrix_file.cpp diff --git a/frameworks/libs/distributeddb/common/include/matrix_file.h b/frameworks/libs/distributeddb/common/include/matrix_file.h new file mode 100644 index 0000000000..ef44428788 --- /dev/null +++ b/frameworks/libs/distributeddb/common/include/matrix_file.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2026 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. + */ + +#ifndef MATRIX_FILE_H +#define MATRIX_FILE_H + +#include +#include +#include + +namespace DistributedDB { + +class MatrixFile { +public: + MatrixFile(); + ~MatrixFile(); + + int AcquireWithRetry(const std::string &path); + + int MapMatrixFile(); + + int WriteMatrixFile(const std::vector &indexes) const; + + uint64_t GetValueByIndex(uint64_t index) const; + + static constexpr size_t MAX_SLOT_NUM = 100; + static constexpr size_t MATRIX_FILE_SLOT_SIZE = sizeof(uint64_t); + static constexpr size_t MATRIX_FILE_SIZE = MAX_SLOT_NUM * MATRIX_FILE_SLOT_SIZE; + +private: + int GetAndCheckRealPath(const std::string &src, std::string &out) const; + + int fd_ = -1; + uint64_t *filePtr_ = nullptr; +}; + +} // DistributedDB +#endif // MATRIX_FILE_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/common/include/relational/data_donation_utils.h b/frameworks/libs/distributeddb/common/include/relational/data_donation_utils.h index 689d55dd2a..0fafd3c68c 100644 --- a/frameworks/libs/distributeddb/common/include/relational/data_donation_utils.h +++ b/frameworks/libs/distributeddb/common/include/relational/data_donation_utils.h @@ -21,6 +21,7 @@ #include "cloud/cloud_store_types.h" #include "data_donation_types.h" #include "data_donation_schema.h" +#include "matrix_file.h" #include "sqlite3sym.h" namespace DistributedDB { @@ -69,7 +70,7 @@ public: static int SetTrackerMatrixInfo(sqlite3 *db, const MatrixFileInfo &info); static int UnsetTrackerMatrixInfo(sqlite3 *db); static int FindMatrixFileInfo(const std::string &hashFileName, MatrixFileInfo &fileInfo); - static uint64_t *MmapMatrixFile(const std::string &path, size_t mmapSize, int32_t &fileFd); + static std::pair> MmapMatrixFile(const std::string &path); static int UpdateMatrixFile(const MatrixFileInfo &fileInfo, const std::vector &changedData, const MatrixFileUpdateConfig &config); @@ -99,7 +100,7 @@ private: static std::string GetSelectFieldName(const std::string &tableName, const std::string &columnName); static std::vector GetMatrixTableIndexs(const MatrixFileInfo &matrixFileInfo, - const std::vector &changedData); + const std::vector &changedData, const MatrixFileUpdateConfig &config); static bool IsFilePathValid(const std::string &path); diff --git a/frameworks/libs/distributeddb/common/src/matrix_file.cpp b/frameworks/libs/distributeddb/common/src/matrix_file.cpp new file mode 100644 index 0000000000..1c52db1df7 --- /dev/null +++ b/frameworks/libs/distributeddb/common/src/matrix_file.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2026 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. + */ + +#include "matrix_file.h" + +#include +#include +#include +#include +#include +#include + +#include "db_common.h" +#include "db_errno.h" +#include "log_print.h" + +namespace DistributedDB { + +MatrixFile::MatrixFile() +{} + +MatrixFile::~MatrixFile() +{ + if (fd_ >= 0) { + close(fd_); // close file to trigger event + LOGD("[MatrixFile] Trigger close event"); + fd_ = -1; + } + + if (filePtr_ != nullptr) { + munmap(filePtr_, MATRIX_FILE_SIZE); + filePtr_ = nullptr; + } +} + +int MatrixFile::AcquireWithRetry(const std::string &path) +{ + std::string realPath; + int errCode = GetAndCheckRealPath(path, realPath); + if (errCode != E_OK) { + LOGE("[AcquireWithRetry] Get real path err: %d, %s", errCode, + DBCommon::StringMiddleMaskingWithLen(path).c_str()); + return errCode; + } + + int fd = open(realPath.c_str(), O_RDWR); + if (fd < 0) { + LOGE("[AcquireWithRetry] Open matrix file err: %d, %s", errno, + DBCommon::StringMiddleMaskingWithLen(path).c_str()); + return -E_INVALID_FILE; + } + fd_ = fd; + return E_OK; +} + +int MatrixFile::WriteMatrixFile(const std::vector &indexes) const +{ + if (filePtr_ == nullptr) { + return -E_INVALID_FILE; + } + + for (const uint64_t index : indexes) { + if (index < MAX_SLOT_NUM) { + filePtr_[index] += 1; + } + } + + if (msync(filePtr_, MATRIX_FILE_SIZE, MS_SYNC) != 0) { + LOGE("[WriteMatrixFile] msync err: %d", errno); + return -E_SYSTEM_API_FAIL; + } + return E_OK; +} + +int MatrixFile::MapMatrixFile() +{ + if (filePtr_ != nullptr) { + return E_OK; + } + if (fd_ < 0) { + return -E_INVALID_FILE; + } + void *statusData = mmap(nullptr, MATRIX_FILE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0); + if (statusData == MAP_FAILED) { + LOGE("[MapMatrixFile] mmap err: %d, size: %zu", errno, MATRIX_FILE_SIZE); + return -E_SYSTEM_API_FAIL; + } + + int errCode = madvise(statusData, MATRIX_FILE_SIZE, MADV_RANDOM); + if (errCode != 0) { + LOGE("[MapMatrixFile] madvise err: %d", errno); + munmap(statusData, MATRIX_FILE_SIZE); + return -E_SYSTEM_API_FAIL; + } + + filePtr_ = static_cast(statusData); + return E_OK; +} + +uint64_t MatrixFile::GetValueByIndex(uint64_t index) const +{ + if (filePtr_ == nullptr || index >= MAX_SLOT_NUM) { + return 0u; + } + return filePtr_[index]; +} + +int MatrixFile::GetAndCheckRealPath(const std::string &src, std::string &out) const +{ + std::filesystem::path realPath = std::filesystem::weakly_canonical(src); + if (!std::filesystem::is_regular_file(realPath)) { + LOGE("[GetAndCheckRealPath] Path is not a file."); + return -E_INVALID_FILE; + } + + out = realPath.string(); + struct stat st; + if (stat(out.c_str(), &st) == -1) { + LOGE("[GetAndCheckRealPath] Check file stat err: %d", errno); + return -E_INVALID_FILE; + } + + if (st.st_size != static_cast(MATRIX_FILE_SIZE)) { + LOGE("[GetAndCheckRealPath] File size err, expected: %zu, actual: %ld", MATRIX_FILE_SIZE, st.st_size); + return -E_INVALID_FILE; + } + return E_OK; +} +} // DistributedDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/common/src/relational/data_donation_utils.cpp b/frameworks/libs/distributeddb/common/src/relational/data_donation_utils.cpp index 220f71f575..65f8f142bc 100644 --- a/frameworks/libs/distributeddb/common/src/relational/data_donation_utils.cpp +++ b/frameworks/libs/distributeddb/common/src/relational/data_donation_utils.cpp @@ -16,11 +16,8 @@ #ifdef RELATIONAL_STORE #include "data_donation_utils.h" -#include #include #include -#include -#include #include #include @@ -34,10 +31,6 @@ namespace DistributedDB { -constexpr size_t MAX_SLOT_NUM = 100; -constexpr size_t MATRIX_FILE_SLOT_SIZE = sizeof(uint64_t); -constexpr size_t MATRIX_FILE_SIZE = MAX_SLOT_NUM * MATRIX_FILE_SLOT_SIZE; - constexpr int MAX_MONITOR_TABLE_COUNT = 10; constexpr int MAX_MONITOR_COLUMN_COUNT = 100; @@ -305,64 +298,51 @@ int DataDonationUtils::GetCursorByPkColumn(const VBucket &bucket, const BinlogCh return found ? E_OK : -E_NOT_FOUND; } -uint64_t *DataDonationUtils::MmapMatrixFile(const std::string &path, size_t mmapSize, int32_t &fileFd) +std::pair> DataDonationUtils::MmapMatrixFile(const std::string &path) { - if (mmapSize > MATRIX_FILE_SIZE) { - LOGE("[DataDonationUtils] mapped size exceed limit, size: %zu", mmapSize); - return nullptr; - } - - char *canonicalPath = realpath(path.c_str(), nullptr); - if (canonicalPath == nullptr) { - LOGE("[DataDonationUtils] File path is wrong"); - return nullptr; + std::shared_ptr matrixFile = std::make_shared(); + int errCode = matrixFile->AcquireWithRetry(path); + if (errCode != E_OK) { + LOGE("[MmapMatrixFile] Acquire matrix file err: %d, errno: %d", errCode, errno); + return std::make_pair(errCode, nullptr); } - std::string realFilePath(canonicalPath); - free(canonicalPath); - canonicalPath = nullptr; - - int fd = open(realFilePath.c_str(), O_RDWR); - if (fd < 0) { - LOGE("[DataDonationUtils] Open matrix file err: %d", errno); - return nullptr; - } - void *statusData = mmap(nullptr, mmapSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (statusData == MAP_FAILED) { - LOGE("[DataDonationUtils] mmap err: %d, size: %zu", errno, mmapSize); - close(fd); - return nullptr; - } - int errCode = madvise(statusData, mmapSize, MADV_RANDOM); - if (errCode != 0) { - LOGE("[DataDonationUtils] madvise err: %d", errno); - munmap(statusData, mmapSize); - close(fd); - return nullptr; + errCode = matrixFile->MapMatrixFile(); + if (errCode != E_OK) { + LOGE("[MmapMatrixFile] Map matrix file err: %d", errCode); + return std::make_pair(errCode, nullptr); } - fileFd = fd; - return static_cast(statusData); + return std::make_pair(E_OK, matrixFile); } std::vector DataDonationUtils::GetMatrixTableIndexs(const MatrixFileInfo &matrixFileInfo, - const std::vector &changedData) + const std::vector &changedData, const MatrixFileUpdateConfig &config) { std::vector indexList; for (const auto &tableName : changedData) { auto it = matrixFileInfo.matrixTables.find(tableName); if (it == matrixFileInfo.matrixTables.end()) { - LOGW("[DataDonationUtils] Table not registered, %s", + LOGW("[GetMatrixTableIndexs] Table not registered, %s", DBCommon::StringMiddleMaskingWithLen(tableName).c_str()); continue; } uint64_t index = it->second; - if (index >= MAX_SLOT_NUM) { - LOGW("[DataDonationUtils] Table index out of range %zu, limit: %zu, table: %s", index, MAX_SLOT_NUM, - DBCommon::StringMiddleMaskingWithLen(tableName).c_str()); + if (index >= MatrixFile::MAX_SLOT_NUM) { + LOGW("[GetMatrixTableIndexs] Table index out of range %zu, limit: %zu, table: %s", index, + MatrixFile::MAX_SLOT_NUM, DBCommon::StringMiddleMaskingWithLen(tableName).c_str()); continue; } indexList.push_back(index); } + + if (config.isFullSync) { + if (matrixFileInfo.fullSyncOffset >= MatrixFile::MAX_SLOT_NUM) { + LOGW("[GetMatrixTableIndexs] isFull offset: %zu out of range %zu", + matrixFileInfo.fullSyncOffset, MatrixFile::MAX_SLOT_NUM); + } else { + indexList.push_back(matrixFileInfo.fullSyncOffset); + } + } return indexList; } @@ -380,43 +360,27 @@ int DataDonationUtils::FindMatrixFileInfo(const std::string &hashFileName, Matri int DataDonationUtils::UpdateMatrixFile(const MatrixFileInfo &fileInfo, const std::vector &changedData, const MatrixFileUpdateConfig &config) { - std::lock_guard autoLock(g_matrixOperateMutex); - std::vector indexList = DataDonationUtils::GetMatrixTableIndexs(fileInfo, changedData); - if (indexList.empty() && !config.isFullSync) { - LOGI("[DataDonationUtils] No change, Index list empty:%d, isFull:%d", indexList.empty(), config.isFullSync); + std::vector indexList = DataDonationUtils::GetMatrixTableIndexs(fileInfo, changedData, config); + if (indexList.empty()) { + LOGI("[UpdateMatrixFile] No change, changed data size:%zu, isFull:%d", changedData.size(), config.isFullSync); return E_OK; } - int fd = -1; - uint64_t *matrixMapPtr = MmapMatrixFile(fileInfo.matrixFilePath, MATRIX_FILE_SIZE, fd); - if (matrixMapPtr == nullptr) { - LOGE("[DataDonationUtils] Matrix map ptr is null"); - return -E_SYSTEM_API_FAIL; - } - ResFinalizer finalizer([matrixMapPtr, fd]() { - close(fd); // close file to trigger event - if (munmap(matrixMapPtr, MATRIX_FILE_SIZE) != 0) { - LOGW("[DataDonationUtils] munmap err: %d", errno); + { + std::lock_guard autoLock(g_matrixOperateMutex); + auto [errCode, matrixFile] = MmapMatrixFile(fileInfo.matrixFilePath); + if (matrixFile == nullptr) { + LOGE("[UpdateMatrixFile] Matrix map ptr is null, err: %d", errCode); + return errCode; } - }); - // update matrix file content - for (const auto index : indexList) { - matrixMapPtr[index] += 1; - } - if (config.isFullSync) { - if (fileInfo.fullSyncOffset >= MAX_SLOT_NUM) { - LOGW("[DataDonationUtils] isFull offset: %zu out of range %zu", fileInfo.fullSyncOffset, MAX_SLOT_NUM); - } else { - matrixMapPtr[fileInfo.fullSyncOffset] += 1; + errCode = matrixFile->WriteMatrixFile(indexList); + if (errCode != E_OK) { + LOGE("[UpdateMatrixFile] Sync to matrix file err: %d", errCode); + return errCode; } } - int errCode = E_OK; - if (msync(matrixMapPtr, MATRIX_FILE_SIZE, MS_SYNC) != 0) { - LOGE("[DataDonationUtils] msync err: %d", errno); - errCode = -E_SYSTEM_API_FAIL; - } - return errCode; + return E_OK; } bool DataDonationUtils::GetDbFileName(sqlite3 *db, std::string &fileName) diff --git a/frameworks/libs/distributeddb/distributeddb.gni b/frameworks/libs/distributeddb/distributeddb.gni index cf77e8e757..f827780533 100755 --- a/frameworks/libs/distributeddb/distributeddb.gni +++ b/frameworks/libs/distributeddb/distributeddb.gni @@ -42,6 +42,7 @@ distributeddb_src = [ "${distributeddb_path}/common/src/json_object.cpp", "${distributeddb_path}/common/src/lock_status_observer.cpp", "${distributeddb_path}/common/src/log_print.cpp", + "${distributeddb_path}/common/src/matrix_file.cpp", "${distributeddb_path}/common/src/notification_chain.cpp", "${distributeddb_path}/common/src/param_check_utils.cpp", "${distributeddb_path}/common/src/param_check_utils_client.cpp", @@ -325,6 +326,7 @@ distributeddb_base_src = [ "${distributeddb_path}/common/src/db_common_client.cpp", "${distributeddb_path}/common/src/json_object.cpp", "${distributeddb_path}/common/src/log_print.cpp", + "${distributeddb_path}/common/src/matrix_file.cpp", "${distributeddb_path}/common/src/param_check_utils_client.cpp", "${distributeddb_path}/common/src/platform_specific.cpp", "${distributeddb_path}/common/src/relational/relational_schema_object.cpp", diff --git a/frameworks/libs/distributeddb/test/unittest/common/store_test/rdb/distributeddb_basic_rdb_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/store_test/rdb/distributeddb_basic_rdb_test.cpp index 4fccc570e0..96fb61f254 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/store_test/rdb/distributeddb_basic_rdb_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/store_test/rdb/distributeddb_basic_rdb_test.cpp @@ -44,6 +44,7 @@ public: static UtTableSchemaInfo GetTableSchema(const std::string &table, bool noPk = false); void PrepareRemoveDataStore(StoreInfo &info1, StoreInfo &info2, StoreInfo &info3, int count); std::string InitMatrixFile(); + std::string InitZeroSizeMatrixFile(); protected: static constexpr const char *DEVICE_SYNC_TABLE = "DEVICE_SYNC_TABLE"; static constexpr const char *CLOUD_SYNC_TABLE = "CLOUD_SYNC_TABLE"; @@ -98,6 +99,19 @@ std::string DistributedDBBasicRDBTest::InitMatrixFile() return matrixFilePath; } +std::string DistributedDBBasicRDBTest::InitZeroSizeMatrixFile() +{ + std::string matrixFilePath = GetTestDir() + "/matrixFile"; + + int fd = open(matrixFilePath.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0660); + if (fd == -1) { + return ""; + } + + close(fd); + return matrixFilePath; +} + void DistributedDBBasicRDBTest::PrepareRemoveDataStore(StoreInfo &info1, StoreInfo &info2, StoreInfo &info3, int count) { ASSERT_EQ(BasicUnitTest::InitDelegate(info1, g_deviceA), E_OK); @@ -701,22 +715,17 @@ HWTEST_F(DistributedDBBasicRDBTest, UpdateMatrixFileTest001, TestSize.Level0) MatrixFileUpdateConfig config = {.isFullSync = false}; EXPECT_EQ(UpdateMatrixFile(db, {"table1"}, config), OK); - int fd = -1; - uint64_t *filePtr = DataDonationUtils::MmapMatrixFile(info.matrixFilePath, MATRIX_FILE_SIZE, fd); + auto [errCode, filePtr] = DataDonationUtils::MmapMatrixFile(info.matrixFilePath); ASSERT_NE(filePtr, nullptr); - EXPECT_NE(fd, -1); - EXPECT_EQ(filePtr[0], 1u); - EXPECT_EQ(filePtr[1], 0u); - EXPECT_EQ(filePtr[2], 0u); + EXPECT_EQ(filePtr->GetValueByIndex(0), 1u); + EXPECT_EQ(filePtr->GetValueByIndex(1), 0u); + EXPECT_EQ(filePtr->GetValueByIndex(2), 0u); /** * @tc.steps: step5. Clean up. * @tc.expected: step5. OK */ - munmap(filePtr, MATRIX_FILE_SIZE); filePtr = nullptr; - - close(fd); unlink(matrixFilePath.c_str()); } @@ -762,22 +771,17 @@ HWTEST_F(DistributedDBBasicRDBTest, UpdateMatrixFileTest002, TestSize.Level0) MatrixFileUpdateConfig config = {.isFullSync = true}; EXPECT_EQ(UpdateMatrixFile(db, {"table1", "table2"}, config), OK); - int fd = -1; - uint64_t *filePtr = DataDonationUtils::MmapMatrixFile(info.matrixFilePath, MATRIX_FILE_SIZE, fd); + auto [errCode, filePtr] = DataDonationUtils::MmapMatrixFile(info.matrixFilePath); ASSERT_NE(filePtr, nullptr); - EXPECT_NE(fd, -1); - EXPECT_EQ(filePtr[0], 1u); - EXPECT_EQ(filePtr[1], 1u); - EXPECT_EQ(filePtr[2], 1u); + EXPECT_EQ(filePtr->GetValueByIndex(0), 1u); + EXPECT_EQ(filePtr->GetValueByIndex(1), 1u); + EXPECT_EQ(filePtr->GetValueByIndex(2), 1u); /** * @tc.steps: step5. Clean up. * @tc.expected: step5. OK */ - munmap(filePtr, MATRIX_FILE_SIZE); filePtr = nullptr; - - close(fd); unlink(matrixFilePath.c_str()); } @@ -813,6 +817,48 @@ HWTEST_F(DistributedDBBasicRDBTest, UpdateMatrixFileTest003, TestSize.Level0) EXPECT_EQ(UpdateMatrixFile(nullptr, {"table1", "table2"}, config), INVALID_ARGS); } +/** + * @tc.name: UpdateMatrixFileTest004 + * @tc.desc: Test update matrix file when file size is 0 + * @tc.type: FUNC + * @tc.author: suyuchen + */ +HWTEST_F(DistributedDBBasicRDBTest, UpdateMatrixFileTest004, TestSize.Level0) +{ + /** + * @tc.steps: step1. Init database. + * @tc.expected: step1. Ok + */ + auto info1 = GetStoreInfo1(); + ASSERT_EQ(InitDatabase(info1), E_OK); + auto db = GetSqliteHandle(info1); + ASSERT_NE(db, nullptr); + + /** + * @tc.steps: step2. Init zero size matrix file. + * @tc.expected: step2. OK + */ + std::string matrixFilePath = InitZeroSizeMatrixFile(); + ASSERT_FALSE(matrixFilePath.empty()); + + /** + * @tc.steps: step3. Set matrix info. + * @tc.expected: step3. OK + */ + std::map matrixTables = {{"table1", 0u}}; + MatrixFileInfo info = {.matrixFilePath = matrixFilePath, .matrixTables = matrixTables, .fullSyncOffset = 1u}; + EXPECT_EQ(SetTrackerMatrixInfo(db, info), OK); + + /** + * @tc.steps: step4. Update matrix file for table1. + * @tc.expected: step4. INVALID_FILE + */ + MatrixFileUpdateConfig config = {.isFullSync = true}; + EXPECT_EQ(UpdateMatrixFile(db, {"table1"}, config), INVALID_FILE); + + unlink(matrixFilePath.c_str()); +} + /** * @tc.name: SetBinlogEnabled002 * @tc.desc: Test disable binlog. diff --git a/frameworks/libs/distributeddb/test/unittest/common/store_test/rdb/distributeddb_data_donation_sql_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/store_test/rdb/distributeddb_data_donation_sql_test.cpp index a7493eb698..bae7c40f26 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/store_test/rdb/distributeddb_data_donation_sql_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/store_test/rdb/distributeddb_data_donation_sql_test.cpp @@ -902,18 +902,13 @@ HWTEST_F(DataDonationSqlGeneratorTest, DISABLED_BinlogDataChangeObserverTest001, std::vector dataOut; ASSERT_EQ(delegate->ExecuteSql(condition, dataOut), OK); - int fd = -1; - uint64_t *filePtr = DataDonationUtils::MmapMatrixFile(filePath, MATRIX_FILE_SIZE, fd); + auto [errCode, filePtr] = DataDonationUtils::MmapMatrixFile(info.matrixFilePath); ASSERT_NE(filePtr, nullptr); - ASSERT_NE(fd, -1); - EXPECT_EQ(filePtr[0], 1u); - EXPECT_EQ(filePtr[1], 0u); - EXPECT_EQ(filePtr[2], 0u); + EXPECT_EQ(filePtr->GetValueByIndex(0), 1u); + EXPECT_EQ(filePtr->GetValueByIndex(1), 0u); + EXPECT_EQ(filePtr->GetValueByIndex(2), 0u); - munmap(filePtr, MATRIX_FILE_SIZE); filePtr = nullptr; - - close(fd); unlink(filePath.c_str()); } -- Gitee