diff --git a/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp b/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp index abab11deda167fbba1933372dee7a5620b8dee1c..7e87b6f4db7b8b2cd627d993f30b1dc2324aa74f 100755 --- a/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp +++ b/framework/innerkitsimpl/test/unittest/udmf_client_test.cpp @@ -888,6 +888,37 @@ HWTEST_F(UdmfClientTest, SetData015, TestSize.Level1) LOG_INFO(UDMF_TEST, "SetData015 end."); } +/** +* @tc.name: SetData016 +* @tc.desc: Set 512 records with valid params and get data +* @tc.type: FUNC +*/ +HWTEST_F(UdmfClientTest, SetData016, TestSize.Level1) +{ + LOG_INFO(UDMF_TEST, "SetData016 begin."); + + CustomOption customOption = {.intention = Intention::UD_INTENTION_DRAG}; + std::string key; + UnifiedData inputData; + std::vector> inputRecords; + for (int32_t i = 0; i < 512; ++i) { + inputRecords.emplace_back(std::make_shared()); + } + inputData.SetRecords(inputRecords); + + auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key); + ASSERT_EQ(status, E_OK); + + QueryOption queryOption = { .key = key }; + UnifiedData outputData; + status = UdmfClient::GetInstance().GetData(queryOption, outputData); + ASSERT_EQ(status, E_OK); + auto outputRecords = outputData.GetRecords(); + ASSERT_EQ(inputRecords.size(), outputRecords.size()); + + LOG_INFO(UDMF_TEST, "SetData016 end."); +} + /** * @tc.name: GetData001 * @tc.desc: Get data with invalid key diff --git a/framework/manager/store/runtime_store.cpp b/framework/manager/store/runtime_store.cpp index e8a2bcaa7167447dc54bba5c402993465b937ccc..11df620ff34a04ac161304803686aa6c7ecc3778 100755 --- a/framework/manager/store/runtime_store.cpp +++ b/framework/manager/store/runtime_store.cpp @@ -28,7 +28,6 @@ using namespace DistributedKv; const AppId RuntimeStore::APP_ID = { "distributeddata" }; const std::string RuntimeStore::DATA_PREFIX = "udmf://"; const std::string RuntimeStore::BASE_DIR = "/data/service/el1/public/database/distributeddata"; -const std::int32_t RuntimeStore::SLASH_COUNT_IN_KEY = 4; RuntimeStore::RuntimeStore(std::string storeId) : storeId_({ storeId }) { @@ -70,12 +69,8 @@ Status RuntimeStore::Put(const UnifiedData &unifiedData) } Entry entry = { Key(unifiedKey), Value(runtimeBytes) }; entries.push_back(entry); - DistributedKv::Status status = kvStore_->PutBatch(entries); - if (status != DistributedKv::Status::SUCCESS) { - LOG_ERROR(UDMF_SERVICE, "KvStore putBatch failed, status: %{public}d.", status); - return E_DB_ERROR; - } - return E_OK; + auto status = PutEntries(entries); + return status; } Status RuntimeStore::Get(const std::string &key, UnifiedData &unifiedData) @@ -155,12 +150,8 @@ Status RuntimeStore::Delete(const std::string &key) for (const auto &entry : entries) { keys.push_back(entry.key); } - DistributedKv::Status status = kvStore_->DeleteBatch(keys); - if (status != DistributedKv::Status::SUCCESS) { - LOG_ERROR(UDMF_SERVICE, "DeleteBatch kvStore failed, status: %{public}d.", status); - return E_DB_ERROR; - } - return E_OK; + auto status = DeleteEntries(keys); + return status; } Status RuntimeStore::DeleteBatch(std::vector timeoutKeys) @@ -248,5 +239,37 @@ std::vector RuntimeStore::GetEntries(const std::string &dataPrefix) } return entries; } + +Status RuntimeStore::PutEntries(const std::vector &entries) +{ + auto size = entries.size(); + DistributedKv::Status status; + for (int32_t index = 0; index < size; index += MAX_BATCH_SIZE) { + std::vector batchEntries(entries.begin() + index, + entries.begin() + std::min(index + MAX_BATCH_SIZE, static_cast(size))); + status = kvStore_->PutBatch(batchEntries); + if (status != DistributedKv::Status::SUCCESS) { + LOG_ERROR(UDMF_SERVICE, "KvStore putBatch failed, status: %{public}d.", status); + return E_DB_ERROR; + } + } + return E_OK; +} + +Status RuntimeStore::DeleteEntries(const std::vector &keys) +{ + auto size = keys.size(); + DistributedKv::Status status; + for (int32_t index = 0; index < size; index += MAX_BATCH_SIZE) { + std::vector batchKeys(keys.begin() + index, + keys.begin() + std::min(index + MAX_BATCH_SIZE, static_cast(size))); + status = kvStore_->DeleteBatch(batchKeys); + if (status != DistributedKv::Status::SUCCESS) { + LOG_ERROR(UDMF_SERVICE, "KvStore deleteBatch failed, status: %{public}d.", status); + return E_DB_ERROR; + } + } + return E_OK; +} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/framework/manager/store/runtime_store.h b/framework/manager/store/runtime_store.h index dde13c3eb365624177d6ef101cc02553fa6be635..51605b5ed5b092d6382d6e99eaa9a141053e362d 100755 --- a/framework/manager/store/runtime_store.h +++ b/framework/manager/store/runtime_store.h @@ -42,12 +42,15 @@ private: static const DistributedKv::AppId APP_ID; static const std::string DATA_PREFIX; static const std::string BASE_DIR; - static const std::int32_t SLASH_COUNT_IN_KEY; + static constexpr std::int32_t SLASH_COUNT_IN_KEY = 4; + static constexpr std::int32_t MAX_BATCH_SIZE = 128; DistributedKv::DistributedKvDataManager dataManager_; std::shared_ptr kvStore_; DistributedKv::StoreId storeId_; std::vector GetEntries(const std::string &dataPrefix); + Status PutEntries(const std::vector &entries); + Status DeleteEntries(const std::vector &keys); }; } // namespace UDMF } // namespace OHOS -#endif //UDMF_RUNTIMESTORE_H +#endif //UDMF_RUNTIMESTORE_H \ No newline at end of file