diff --git a/BUILD.gn b/BUILD.gn index ffdc42dd56d080c298ecba03c068f98b8eac3345..613ec6ea70fcfcdbe564fa63baa9e546f608f132 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -25,6 +25,7 @@ group("build_native_test") { deps = [ "frameworks/innerkitsimpl/distributeddatafwk/test:unittest", "frameworks/libs/distributeddb/test:unittest", + "frameworks/libs/distributeddb/test/moduletest:moduletest", ] } @@ -34,6 +35,23 @@ group("unittest") { deps = [] deps += [ "frameworks/innerkitsimpl/kvdb/test:unittest", - "test/unittest:unittest", + "test/unittest/distributedKVStore:unittest", + "test/unittest/distributeddata:unittest", ] } + +############################################################################### + +group("fuzztest") { + testonly = true + deps = [] + deps += [ + "test/fuzztest/blob_fuzzer:fuzztest", + "test/fuzztest/devicekvstore_fuzzer:fuzztest", + "test/fuzztest/distributedkvdatamanager_fuzzer:fuzztest", + "test/fuzztest/singlekvstore_fuzzer:fuzztest", + "test/fuzztest/taskscheduler_fuzzer:fuzztest", + "test/fuzztest/typesutil_fuzzer:fuzztest", + ] +} +############################################################################### diff --git a/bundle.json b/bundle.json index 7885218b4f24dd0cf3985b43f4ed8bfb324f0c6e..0350e49246fcb6d0a2720e2c48eb425aa7a6a011 100644 --- a/bundle.json +++ b/bundle.json @@ -119,7 +119,9 @@ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test:distributeddatamgr_fuzztest", "//foundation/distributeddatamgr/kv_store:distributedtest", "//foundation/distributeddatamgr/kv_store:build_native_test", - "//foundation/distributeddatamgr/kv_store/test/unittest:unittest", + "//foundation/distributeddatamgr/kv_store:fuzztest", + "//foundation/distributeddatamgr/kv_store/test/unittest/distributeddata:unittest", + "//foundation/distributeddatamgr/kv_store/test/unittest/distributedKVStore:unittest", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/test:unittest" ] } diff --git a/frameworks/common/dds_trace.h b/frameworks/common/dds_trace.h new file mode 100644 index 0000000000000000000000000000000000000000..a80b19d71b76afeba433918f0ae12aecb04d5f3e --- /dev/null +++ b/frameworks/common/dds_trace.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 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 DDS_TRACE_H +#define DDS_TRACE_H + +#include +#include +#include +#include +#include +#include "hitrace/trace.h" +#include "hitrace_meter.h" +namespace OHOS { +namespace DistributedDataDfx { +enum TraceSwitch { + DEBUG_CLOSE = 0x00, + BYTRACE_ON = 0x01, + API_PERFORMANCE_TRACE_ON = 0x02, + TRACE_CHAIN_ON = 0x04, +}; +class __attribute__((visibility("hidden"))) DdsTrace { +public: + using Action = std::function; + using System = std::chrono::system_clock; + DdsTrace(const std::string &value, unsigned int option = BYTRACE_ON, Action action = nullptr) + { + traceSwitch_ = option; + traceValue_ = value; + action_ = action; + static std::atomic_bool enable = false; + if (!enable.exchange(true)) { + UpdateTraceLabel(); + } + Start(value); + } + + ~DdsTrace() + { + Finish(traceValue_); + } + +private: + void Start(const std::string &value) + { + if ((traceSwitch_ & BYTRACE_ON) == BYTRACE_ON) { + StartTrace(HITRACE_TAG_DISTRIBUTEDDATA, value); + } + if ((traceSwitch_ & TRACE_CHAIN_ON) == TRACE_CHAIN_ON) { + traceId_ = OHOS::HiviewDFX::HiTraceChain::Begin(value, HITRACE_FLAG_DEFAULT); + } + if ((traceSwitch_ & API_PERFORMANCE_TRACE_ON) == API_PERFORMANCE_TRACE_ON) { + lastTime_ = System::now(); + } + } + void Finish(const std::string &value) + { + if ((traceSwitch_ & BYTRACE_ON) == BYTRACE_ON) { + FinishTrace(HITRACE_TAG_DISTRIBUTEDDATA); + } + if ((traceSwitch_ & TRACE_CHAIN_ON) == TRACE_CHAIN_ON) { + OHOS::HiviewDFX::HiTraceChain::End(traceId_); + } + if ((traceSwitch_ & API_PERFORMANCE_TRACE_ON) == API_PERFORMANCE_TRACE_ON && action_) { + action_(value, std::chrono::duration_cast(System::now() - lastTime_).count()); + } + } + Action action_; + std::string traceValue_{ }; + HiviewDFX::HiTraceId traceId_; + uint32_t traceSwitch_{ 0 }; + System::time_point lastTime_; +}; +} // namespace DistributedDataDfx +} // namespace OHOS +#endif diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h index 2d391111b63d5aae5b430645f1769e8b9b102642..ca6cbbc75e79701a8138d3fb7bb5da18ae24f1cb 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h +++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h @@ -19,6 +19,7 @@ #include "iremote_broker.h" #include "iremote_proxy.h" #include "iremote_stub.h" +#include "visibility.h" namespace OHOS { namespace DistributedKv { @@ -28,10 +29,9 @@ public: }; class KvStoreClientDeathObserverStub : public IRemoteStub { -public: }; -class KvStoreClientDeathObserverProxy : public IRemoteProxy { +class API_EXPORT KvStoreClientDeathObserverProxy : public IRemoteProxy { public: explicit KvStoreClientDeathObserverProxy(const sptr &impl); ~KvStoreClientDeathObserverProxy() = default; diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h index e6f280d64598dc5086725907d58224d475357140..b67e248d2ec29ac689d7ebcaa2f40d46c6eb0b54 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h +++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h @@ -54,7 +54,7 @@ protected: class KvStoreDataServiceStub : public IRemoteStub { public: - int OnRemoteRequest(uint32_t code, MessageParcel &data, + int API_EXPORT OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: @@ -78,7 +78,7 @@ private: }; }; -class KvStoreDataServiceProxy : public IRemoteProxy { +class API_EXPORT KvStoreDataServiceProxy : public IRemoteProxy { public: explicit KvStoreDataServiceProxy(const sptr &impl); ~KvStoreDataServiceProxy() = default; diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h index 2dd19b74890d81b39e89ae48af339427ecfd5bdb..4f18454afcedb4fc46237e6e22b9671ca8ecf55b 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h +++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h @@ -39,7 +39,7 @@ public: MessageParcel &reply, MessageOption &option) override; }; -class KvStoreObserverProxy : public IRemoteProxy { +class API_EXPORT KvStoreObserverProxy : public IRemoteProxy { public: explicit KvStoreObserverProxy(const sptr &impl); ~KvStoreObserverProxy() = default; diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_sync_callback.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_sync_callback.h index 832650285ce067f7f3c291dddbd541e233f3ffc7..94742c1ee06fe0c8a0504c71545d9c1b1572d8b0 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_sync_callback.h +++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_sync_callback.h @@ -21,6 +21,7 @@ #include "iremote_proxy.h" #include "iremote_stub.h" #include "types.h" +#include "visibility.h" namespace OHOS { namespace DistributedKv { @@ -36,7 +37,7 @@ public: MessageParcel &reply, MessageOption &option) override; }; -class KvStoreSyncCallbackProxy : public IRemoteProxy { +class API_EXPORT KvStoreSyncCallbackProxy : public IRemoteProxy { public: explicit KvStoreSyncCallbackProxy(const sptr &impl); ~KvStoreSyncCallbackProxy() = default; diff --git a/frameworks/innerkitsimpl/distributeddatafwk/src/distributed_kv_data_manager.cpp b/frameworks/innerkitsimpl/distributeddatafwk/src/distributed_kv_data_manager.cpp index 8a4db228cdfbd406f00cc60b2bf99fddb9920eeb..c3a3485aa6ebf3d7a466c2b56ef0ec51fe7a8730 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/src/distributed_kv_data_manager.cpp +++ b/frameworks/innerkitsimpl/distributeddatafwk/src/distributed_kv_data_manager.cpp @@ -168,26 +168,26 @@ void DistributedKvDataManager::UnRegisterKvStoreServiceDeathRecipient( Status DistributedKvDataManager::GetLocalDevice(DeviceInfo &localDevice) { - auto dvInfo = DevManager::GetInstance().GetLocalDevice(); - if (dvInfo.networkId.empty()) { + auto devInfo = DevManager::GetInstance().GetLocalDevice(); + if (devInfo.networkId.empty()) { ZLOGE("deviceId empty!"); return Status::ERROR; } - localDevice.deviceId = dvInfo.networkId; - localDevice.deviceName = dvInfo.deviceName; - localDevice.deviceType = dvInfo.deviceType; + localDevice.deviceId = devInfo.networkId; return Status::SUCCESS; } Status DistributedKvDataManager::GetDeviceList(std::vector &deviceInfoList, DeviceFilterStrategy strategy) { - auto dvInfos = DevManager::GetInstance().GetRemoteDevices(); - for (const auto &info : dvInfos) { + auto devInfos = DevManager::GetInstance().GetRemoteDevices(); + for (const auto &info : devInfos) { if (info.networkId.empty()) { ZLOGW("deviceId empty!"); continue; } - DeviceInfo devInfo = { info.networkId, info.deviceName, info.deviceType }; + DeviceInfo devInfo = { + .deviceId = info.networkId, + }; deviceInfoList.emplace_back(devInfo); } ZLOGI("strategy is:%{public}d", strategy); diff --git a/frameworks/innerkitsimpl/distributeddatafwk/src/kvstore_client_death_observer.h b/frameworks/innerkitsimpl/distributeddatafwk/src/kvstore_client_death_observer.h index 88f1db22654262a1bc569e199a84fcee67f608cd..b027cfea5d0abe52338dcc3640db95f8ab72dc1f 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/src/kvstore_client_death_observer.h +++ b/frameworks/innerkitsimpl/distributeddatafwk/src/kvstore_client_death_observer.h @@ -20,7 +20,7 @@ namespace OHOS { namespace DistributedKv { -class KvStoreClientDeathObserver : public KvStoreClientDeathObserverStub { +class API_EXPORT KvStoreClientDeathObserver : public KvStoreClientDeathObserverStub { public: KvStoreClientDeathObserver(); diff --git a/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn b/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn index 58252a4496a6e808a13a6ad548ccf9a92eb71dc7..42c1aace83c688a609cb4664ecbe9640e8d91ed0 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn +++ b/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn @@ -20,17 +20,86 @@ config("module_private_config") { include_dirs = [ "../include/", + "../src/", "../../kvdb/include/", - "../../../../interfaces/innerkits/distributeddata/", + "../../kvdb/src/", + "../../../common/", + "../../../../interfaces/innerkits/distributeddata/include/", # for ipc_core interfaces. "//commonlibrary/c_utils/base/include", "//foundation/distributeddatamgr/data_share/interfaces/inner_api/common/include", "//foundation/distributeddatamgr/data_share/interfaces/inner_api/provider/include", "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", + "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/mod_securitylabel", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp/include", + "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include", ] } +############################################################################### +ohos_source_set("distributeddatafwk_src_file") { + testonly = true + + old_sources = [ + "../src/blob.cpp", + "../src/change_notification.cpp", + "../src/data_query.cpp", + "../src/device_status_change_listener_client.cpp", + "../src/distributed_kv_data_manager.cpp", + "../src/ikvstore_client_death_observer.cpp", + "../src/ikvstore_data_service.cpp", + "../src/ikvstore_observer.cpp", + "../src/ikvstore_sync_callback.cpp", + "../src/kv_utils.cpp", + "../src/kvstore_client_death_observer.cpp", + "../src/kvstore_datashare_bridge.cpp", + "../src/kvstore_observer_client.cpp", + "../src/kvstore_service_death_notifier.cpp", + "../src/kvstore_sync_callback_client.cpp", + "../src/sync_observer.cpp", + ] + + kvdb_sources = [ + "../../kvdb/src/auto_sync_timer.cpp", + "../../kvdb/src/backup_manager.cpp", + "../../kvdb/src/convertor.cpp", + "../../kvdb/src/dev_manager.cpp", + "../../kvdb/src/device_convertor.cpp", + "../../kvdb/src/kv_types_util.cpp", + "../../kvdb/src/kvdb_service_client.cpp", + "../../kvdb/src/observer_bridge.cpp", + "../../kvdb/src/security_manager.cpp", + "../../kvdb/src/single_store_impl.cpp", + "../../kvdb/src/store_factory.cpp", + "../../kvdb/src/store_manager.cpp", + "../../kvdb/src/store_result_set.cpp", + "../../kvdb/src/store_util.cpp", + "../../kvdb/src/system_api.cpp", + "../../kvdb/src/task_executor.cpp", + ] + + sources = old_sources + kvdb_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", + ] + external_deps = [ + "c_utils:utils", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hitrace_native:libhitracechain", + "hiviewdfx_hilog_native:libhilog", + "huks:libhukssdk", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + part_name = "kv_store" +} + ohos_unittest("DistributedKvDataManagerTest") { module_out_path = module_output_path @@ -46,8 +115,8 @@ ohos_unittest("DistributedKvDataManagerTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -67,8 +136,8 @@ ohos_unittest("DistributedKvDataManagerEncryptTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -88,8 +157,8 @@ ohos_unittest("LocalSubscribeStoreTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -109,8 +178,8 @@ ohos_unittest("LocalSubscribeDeviceStoreTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -130,8 +199,8 @@ ohos_unittest("SingleKvStoreClientQueryTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -151,8 +220,8 @@ ohos_unittest("SingleKvStoreClientTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -172,8 +241,8 @@ ohos_unittest("DeviceKvStoreTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -186,8 +255,8 @@ ohos_unittest("BlobTest") { configs = [ ":module_private_config" ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] @@ -205,8 +274,8 @@ ohos_unittest("TypesUtilTest") { configs = [ ":module_private_config" ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] @@ -224,8 +293,8 @@ ohos_unittest("KvUtilTest") { configs = [ ":module_private_config" ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] @@ -243,8 +312,8 @@ ohos_unittest("KvstoreDatashareBridgeTest") { configs = [ ":module_private_config" ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] diff --git a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_test.cpp b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_test.cpp index 5bc33a0aa9fdd5f67b3a2112f896d4852e831cf8..15ac2f5b21c7ded32289aa9aadf8fb6c07072e30 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_test.cpp +++ b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_test.cpp @@ -743,15 +743,15 @@ HWTEST_F(DistributedKvDataManagerTest, UnRegisterKvStoreServiceDeathRecipient001 * @tc.require: * @tc.author: zuojiangjiang */ -HWTEST_F(DistributedKvDataManagerTest, GetLocalDevice001, TestSize.Level1) +HWTEST_F(DistributedKvDataManagerTest, GetLocalDevice, TestSize.Level1) { - ZLOGI("GetLocalDevice001 begin."); - DeviceInfo dvInfo; - Status status = manager.GetLocalDevice(dvInfo); + ZLOGI("GetLocalDevice begin."); + DeviceInfo devInfo; + Status status = manager.GetLocalDevice(devInfo); EXPECT_EQ(status, Status::SUCCESS); - EXPECT_EQ(dvInfo.deviceId.empty(), false); - EXPECT_EQ(dvInfo.deviceName.empty(), false); - EXPECT_EQ(dvInfo.deviceType.empty(), false); + EXPECT_EQ(devInfo.deviceId.empty(), false); + EXPECT_EQ(devInfo.deviceName.empty(), true); + EXPECT_EQ(devInfo.deviceType.empty(), true); } /** @@ -761,11 +761,11 @@ HWTEST_F(DistributedKvDataManagerTest, GetLocalDevice001, TestSize.Level1) * @tc.require: * @tc.author: zuojiangjiang */ -HWTEST_F(DistributedKvDataManagerTest, GetDeviceList001, TestSize.Level1) +HWTEST_F(DistributedKvDataManagerTest, GetDeviceList, TestSize.Level1) { - ZLOGI("GetDeviceList001 begin."); - std::vector dvInfos; - Status status = manager.GetDeviceList(dvInfos, DeviceFilterStrategy::NO_FILTER); + ZLOGI("GetDeviceList begin."); + std::vector devInfos; + Status status = manager.GetDeviceList(devInfos, DeviceFilterStrategy::NO_FILTER); EXPECT_EQ(status, Status::SUCCESS); } @@ -776,9 +776,9 @@ HWTEST_F(DistributedKvDataManagerTest, GetDeviceList001, TestSize.Level1) * @tc.require: * @tc.author: zuojiangjiang */ -HWTEST_F(DistributedKvDataManagerTest, WatchDeviceChange001, TestSize.Level1) +HWTEST_F(DistributedKvDataManagerTest, WatchDeviceChange, TestSize.Level1) { - ZLOGI("GetDeviceList001 begin."); + ZLOGI("GetDeviceList begin."); std::shared_ptr observer = nullptr; Status status = manager.StartWatchDeviceChange(observer); EXPECT_EQ(status, Status::SUCCESS); diff --git a/frameworks/innerkitsimpl/kvdb/include/auto_sync_timer.h b/frameworks/innerkitsimpl/kvdb/include/auto_sync_timer.h index 1e3c918278575789fb92faa6cacb34a84867b90f..b6053a403378adc20951f777fc609180c110defb 100644 --- a/frameworks/innerkitsimpl/kvdb/include/auto_sync_timer.h +++ b/frameworks/innerkitsimpl/kvdb/include/auto_sync_timer.h @@ -15,6 +15,7 @@ #ifndef SDB_AUTO_SYNC_TIMER_H #define SDB_AUTO_SYNC_TIMER_H #include +#include #include "concurrent_map.h" #include "kvdb_service.h" @@ -32,13 +33,13 @@ private: static constexpr size_t SYNC_STORE_NUM = 10; AutoSyncTimer() = default; ~AutoSyncTimer() = default; - std::map> GetStoreIds(); + std::map> GetStoreIds(); std::function ProcessTask(); void StartTimer(); void StopTimer(); void AddSyncStores(const std::string &appId, std::set storeIds); bool HasSyncStores(); - ConcurrentMap> stores_; + ConcurrentMap> stores_; TaskScheduler::TaskId delaySyncTaskId_; TaskScheduler::TaskId forceSyncTaskId_; std::mutex mutex_; diff --git a/frameworks/innerkitsimpl/kvdb/include/dev_manager.h b/frameworks/innerkitsimpl/kvdb/include/dev_manager.h index c6e18d9cdb9ac2960a1ed473299b121046030c7f..d04cf321267daa64d14626c85a1a03332d671684 100644 --- a/frameworks/innerkitsimpl/kvdb/include/dev_manager.h +++ b/frameworks/innerkitsimpl/kvdb/include/dev_manager.h @@ -24,14 +24,13 @@ public: static constexpr size_t MAX_ID_LEN = 64; struct DetailInfo { std::string uuid; - std::string udid; std::string networkId; std::string deviceName; std::string deviceType; }; static DevManager &GetInstance(); - std::string ToUUID(const std::string &networkId) const; - std::string ToNetworkId(const std::string &uuid) const; + std::string ToUUID(const std::string &networkId); + std::string ToNetworkId(const std::string &uuid); const DetailInfo &GetLocalDevice(); std::vector GetRemoteDevices() const; class Observer { @@ -55,6 +54,8 @@ private: void OnChanged(const std::string &networkId); void OnReady(const std::string &networkId); void RegisterDevCallback(); + void UpdateBucket(); + DetailInfo GetDevInfoFromBucket(const std::string &id); int32_t Init(); std::function Retry(); diff --git a/frameworks/innerkitsimpl/kvdb/include/kv_types_util.h b/frameworks/innerkitsimpl/kvdb/include/kv_types_util.h index dbe7cf8dea2fc1b06c9fe80507c667b407e6a8fb..1a0211b598e2a130e67e8d973b5e1b667b11a9e5 100644 --- a/frameworks/innerkitsimpl/kvdb/include/kv_types_util.h +++ b/frameworks/innerkitsimpl/kvdb/include/kv_types_util.h @@ -16,6 +16,7 @@ #ifndef OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_KV_TYPES_UTIL_H #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_KV_TYPES_UTIL_H #include "change_notification.h" +#include "kvdb_service.h" #include "itypes_util.h" #include "types.h" namespace OHOS::ITypesUtil { @@ -28,47 +29,52 @@ using StoreId = DistributedKv::StoreId; using DeviceInfo = DistributedKv::DeviceInfo; using ChangeNotification = DistributedKv::ChangeNotification; using Options = DistributedKv::Options; -using Options = DistributedKv::Options; using SyncPolicy = DistributedKv::SyncPolicy; +using DevBrief = DistributedKv::KVDBService::DevBrief; +template<> +API_EXPORT bool Marshalling(const Blob &input, MessageParcel &data); +template<> +API_EXPORT bool Unmarshalling(Blob &output, MessageParcel &data); + template<> -bool Marshalling(const Blob &input, MessageParcel &data); +API_EXPORT bool Marshalling(const AppId &input, MessageParcel &data); template<> -bool Unmarshalling(Blob &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(AppId &output, MessageParcel &data); template<> -bool Marshalling(const AppId &input, MessageParcel &data); +API_EXPORT bool Marshalling(const StoreId &input, MessageParcel &data); template<> -bool Unmarshalling(AppId &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(StoreId &output, MessageParcel &data); template<> -bool Marshalling(const StoreId &input, MessageParcel &data); +API_EXPORT bool Marshalling(const Entry &input, MessageParcel &data); template<> -bool Unmarshalling(StoreId &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(Entry &output, MessageParcel &data); template<> -bool Marshalling(const Entry &input, MessageParcel &data); +API_EXPORT bool Marshalling(const DeviceInfo &input, MessageParcel &data); template<> -bool Unmarshalling(Entry &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(DeviceInfo &output, MessageParcel &data); template<> -bool Marshalling(const DeviceInfo &input, MessageParcel &data); +API_EXPORT bool Marshalling(const ChangeNotification ¬ification, MessageParcel &parcel); template<> -bool Unmarshalling(DeviceInfo &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(ChangeNotification &output, MessageParcel &parcel); template<> -bool Marshalling(const ChangeNotification ¬ification, MessageParcel &parcel); +API_EXPORT bool Marshalling(const Options &input, MessageParcel &data); template<> -bool Unmarshalling(ChangeNotification &output, MessageParcel &parcel); +API_EXPORT bool Unmarshalling(Options &output, MessageParcel &data); template<> -bool Marshalling(const Options &input, MessageParcel &data); +API_EXPORT bool Marshalling(const SyncPolicy &input, MessageParcel &data); template<> -bool Unmarshalling(Options &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(SyncPolicy &output, MessageParcel &data); template<> -bool Marshalling(const SyncPolicy &input, MessageParcel &data); +API_EXPORT bool Marshalling(const DevBrief &input, MessageParcel &data); template<> -bool Unmarshalling(SyncPolicy &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(DevBrief &output, MessageParcel &data); int64_t GetTotalSize(const std::vector &entries); int64_t GetTotalSize(const std::vector &entries); diff --git a/frameworks/innerkitsimpl/kvdb/include/kvdb_service.h b/frameworks/innerkitsimpl/kvdb/include/kvdb_service.h index 3332366ec47b07dbc77d8439faa67fab368e7e58..74af08fbfad879815cf8eb389cb7c83e11d66a66 100644 --- a/frameworks/innerkitsimpl/kvdb/include/kvdb_service.h +++ b/frameworks/innerkitsimpl/kvdb/include/kvdb_service.h @@ -33,6 +33,10 @@ public: std::vector devices; std::string query; }; + struct DevBrief { + std::string uuid; + std::string networkId; + }; DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.KVFeature"); API_EXPORT KVDBService() = default; @@ -59,6 +63,8 @@ public: virtual Status Unsubscribe(const AppId &appId, const StoreId &storeId, sptr observer) = 0; virtual Status GetBackupPassword( const AppId &appId, const StoreId &storeId, std::vector &password) = 0; + virtual DevBrief GetLocalDevice() = 0; + virtual std::vector GetRemoteDevices() = 0; protected: enum TransId : int32_t { @@ -80,7 +86,11 @@ protected: TRANS_SUB, TRANS_UNSUB, TRANS_GET_PASSWORD, - TRANS_BUTT, + TRANS_NO_APPID_BEGIN, + TRANS_GET_LOCAL_DEVICE = TRANS_NO_APPID_BEGIN, + TRANS_GET_REMOTE_DEVICES, + TRANS_NO_APPID_END, + TRANS_BUTT = TRANS_NO_APPID_END, }; }; } // namespace OHOS::DistributedKv diff --git a/frameworks/innerkitsimpl/kvdb/include/kvdb_service_client.h b/frameworks/innerkitsimpl/kvdb/include/kvdb_service_client.h index 94adb55561963498c423e79cef4042ae73ceb4ce..b38c055a8fc4011af087389df79a9b0335777985 100644 --- a/frameworks/innerkitsimpl/kvdb/include/kvdb_service_client.h +++ b/frameworks/innerkitsimpl/kvdb/include/kvdb_service_client.h @@ -48,6 +48,8 @@ public: Status Subscribe(const AppId &appId, const StoreId &storeId, sptr observer) override; Status Unsubscribe(const AppId &appId, const StoreId &storeId, sptr observer) override; Status GetBackupPassword(const AppId &appId, const StoreId &storeId, std::vector &password) override; + DevBrief GetLocalDevice() override; + std::vector GetRemoteDevices() override; sptr GetSyncAgent(const AppId &appId); protected: diff --git a/frameworks/innerkitsimpl/kvdb/src/auto_sync_timer.cpp b/frameworks/innerkitsimpl/kvdb/src/auto_sync_timer.cpp index 8e2051fba565018e7e6e32e831476f688258edd3..02277982d6f56e91fe5aee2ea95a393fc655d252 100644 --- a/frameworks/innerkitsimpl/kvdb/src/auto_sync_timer.cpp +++ b/frameworks/innerkitsimpl/kvdb/src/auto_sync_timer.cpp @@ -48,8 +48,13 @@ void AutoSyncTimer::DoAutoSync(const std::string &appId, std::set store void AutoSyncTimer::AddSyncStores(const std::string &appId, std::set storeIds) { - stores_.Compute(appId, [&storeIds](const auto &key, std::set &value) { - value.merge(std::move(storeIds)); + stores_.Compute(appId, [&storeIds](const auto &key, std::vector &value) { + std::set tempStores(value.begin(), value.end()); + for (auto it = storeIds.begin(); it != storeIds.end(); it++) { + if (tempStores.count(*it) == 0) { + value.push_back(*it); + } + } return !value.empty(); }); } @@ -59,11 +64,11 @@ bool AutoSyncTimer::HasSyncStores() return !stores_.Empty(); } -std::map> AutoSyncTimer::GetStoreIds() +std::map> AutoSyncTimer::GetStoreIds() { - std::map> stores; + std::map> stores; int count = SYNC_STORE_NUM; - stores_.EraseIf([&stores, &count](const std::string &key, std::set &value) { + stores_.EraseIf([&stores, &count](const std::string &key, std::vector &value) { int size = value.size(); if (size <= count) { stores.insert({ key, std::move(value) }); @@ -71,11 +76,13 @@ std::map> AutoSyncTimer::GetStoreIds() return true; } auto &innerStore = stores[key]; - for (auto it = value.begin(); it != value.end() && count > 0;) { - innerStore.insert(*it); - it = value.erase(it); + auto it = value.begin(); + while (it != value.end() && count > 0) { + innerStore.push_back(*it); + it++; count--; } + value.erase(value.begin(),it); return value.empty(); }); return stores; diff --git a/frameworks/innerkitsimpl/kvdb/src/dev_manager.cpp b/frameworks/innerkitsimpl/kvdb/src/dev_manager.cpp index 0beb71ff4fb79c1c21346914dcc368ca4bb5dc8d..544d883b649802759b8c13164ba7da0385d88865 100644 --- a/frameworks/innerkitsimpl/kvdb/src/dev_manager.cpp +++ b/frameworks/innerkitsimpl/kvdb/src/dev_manager.cpp @@ -19,6 +19,7 @@ #include "device_manager.h" #include "device_manager_callback.h" #include "dm_device_info.h" +#include "kvdb_service_client.h" #include "log_print.h" #include "store_util.h" #include "task_executor.h" @@ -118,44 +119,43 @@ DevManager &DevManager::GetInstance() return instance; } -std::string DevManager::ToUUID(const std::string &networkId) const +std::string DevManager::ToUUID(const std::string &networkId) { - DetailInfo deviceInfo; - if (deviceInfos_.Get(networkId, deviceInfo)) { - return deviceInfo.uuid; - } + return GetDevInfoFromBucket(networkId).uuid; +} - std::string uuid; - std::string udid; - auto &deviceManager = DeviceManager::GetInstance(); - deviceManager.GetUuidByNetworkId(PKG_NAME, networkId, uuid); - deviceManager.GetUdidByNetworkId(PKG_NAME, networkId, udid); - if (uuid.empty() || udid.empty() || networkId.empty()) { - return ""; +std::string DevManager::ToNetworkId(const std::string &uuid) +{ + return GetDevInfoFromBucket(uuid).networkId; +} + +DevManager::DetailInfo DevManager::GetDevInfoFromBucket(const std::string &id) +{ + DetailInfo detailInfo; + if (!deviceInfos_.Get(id, detailInfo)) { + UpdateBucket(); + deviceInfos_.Get(id, detailInfo); } - deviceInfo = { uuid, std::move(udid), networkId, "", "" }; - deviceInfos_.Set(networkId, deviceInfo); - deviceInfos_.Set(uuid, deviceInfo); - return uuid; + if (detailInfo.uuid.empty()) { + ZLOGE("id:%{public}s", StoreUtil::Anonymous(id).c_str()); + } + return detailInfo; } -std::string DevManager::ToNetworkId(const std::string &uuid) const +void DevManager::UpdateBucket() { - DetailInfo deviceInfo; - if (deviceInfos_.Get(uuid, deviceInfo)) { - return deviceInfo.networkId; + auto detailInfos = GetRemoteDevices(); + if (detailInfos.empty()) { + ZLOGD("no remote device"); } - auto infos = GetRemoteDevices(); - for (auto &info : infos) { - if (info.uuid == uuid) { - deviceInfos_.Set(info.uuid, info); - deviceInfos_.Set(info.networkId, info); - return info.networkId; + detailInfos.emplace_back(GetLocalDevice()); + for (const auto &detailInfo : detailInfos) { + if (detailInfo.uuid.empty() || detailInfo.networkId.empty()) { + continue; } + deviceInfos_.Set(detailInfo.uuid, detailInfo); + deviceInfos_.Set(detailInfo.networkId, detailInfo); } - - std::lock_guard lockGuard(mutex_); - return (localInfo_.uuid == uuid) ? localInfo_.networkId : ""; } const DevManager::DetailInfo &DevManager::GetLocalDevice() @@ -164,51 +164,42 @@ const DevManager::DetailInfo &DevManager::GetLocalDevice() if (!localInfo_.uuid.empty()) { return localInfo_; } - - DmDeviceInfo info; - auto &deviceManager = DeviceManager::GetInstance(); - int32_t ret = deviceManager.GetLocalDeviceInfo(PKG_NAME, info); - if (ret != DM_OK) { - ZLOGE("GetLocalNodeDeviceInfo error"); + auto service = KVDBServiceClient::GetInstance(); + if (service == nullptr) { + ZLOGE("service unavailable"); return invalidDetail_; } - std::string networkId = std::string(info.networkId); - std::string uuid; - deviceManager.GetUuidByNetworkId(PKG_NAME, networkId, uuid); - std::string udid; - deviceManager.GetUdidByNetworkId(PKG_NAME, networkId, udid); - if (uuid.empty() || udid.empty() || networkId.empty()) { + auto device = service->GetLocalDevice(); + if (device.uuid.empty() || device.networkId.empty()) { return invalidDetail_; } - ZLOGI("[LocalDevice] id:%{public}s, name:%{public}s, type:%{public}d", StoreUtil::Anonymous(uuid).c_str(), - info.deviceName, info.deviceTypeId); - localInfo_ = { std::move(uuid), std::move(udid), std::move(networkId), std::string(info.deviceName), - std::string(info.deviceName) }; + localInfo_.networkId = std::move(device.networkId); + localInfo_.uuid = std::move(device.uuid); + ZLOGI("[LocalDevice] uuid:%{public}s, networkId:%{public}s", + StoreUtil::Anonymous(localInfo_.uuid).c_str(), StoreUtil::Anonymous(localInfo_.networkId).c_str()); return localInfo_; } std::vector DevManager::GetRemoteDevices() const { - std::vector devices; - std::vector dmDeviceInfos{}; - auto &deviceManager = DeviceManager::GetInstance(); - int32_t ret = deviceManager.GetTrustedDeviceList(PKG_NAME, "", dmDeviceInfos); - if (ret != DM_OK) { - ZLOGE("GetTrustedDeviceList error"); - return devices; + auto service = KVDBServiceClient::GetInstance(); + if (service == nullptr) { + ZLOGE("service unavailable"); + return {}; } - - for (const auto &dmDeviceInfo : dmDeviceInfos) { - std::string networkId = dmDeviceInfo.networkId; - std::string uuid; - std::string udid; - deviceManager.GetUuidByNetworkId(PKG_NAME, networkId, uuid); - deviceManager.GetUdidByNetworkId(PKG_NAME, networkId, udid); - DetailInfo deviceInfo = { std::move(uuid), std::move(udid), std::move(networkId), - std::string(dmDeviceInfo.deviceName), std::to_string(dmDeviceInfo.deviceTypeId) }; - devices.push_back(std::move(deviceInfo)); + auto devices = service->GetRemoteDevices(); + if (devices.empty()) { + ZLOGD("no remote device"); + return {}; + } + std::vector dtInfos; + for (auto &device : devices) { + DetailInfo dtInfo; + dtInfo.networkId = std::move(device.networkId); + dtInfo.uuid = std::move(device.uuid); + dtInfos.push_back(dtInfo); } - return devices; + return dtInfos; } void DevManager::Online(const std::string &networkId) diff --git a/frameworks/innerkitsimpl/kvdb/src/kv_types_util.cpp b/frameworks/innerkitsimpl/kvdb/src/kv_types_util.cpp index efd5b76a8aabe860488437d8275acf063eb25dec..70045bdb16e5e062213ebc746e1759191d26860b 100644 --- a/frameworks/innerkitsimpl/kvdb/src/kv_types_util.cpp +++ b/frameworks/innerkitsimpl/kvdb/src/kv_types_util.cpp @@ -160,6 +160,18 @@ bool Unmarshalling(SyncPolicy &output, MessageParcel &data) return ITypesUtil::Unmarshal(data, output.type, output.value); } +template<> +bool Marshalling(const DevBrief &input, MessageParcel &data) +{ + return ITypesUtil::Marshal(data, input.uuid, input.networkId); +} + +template<> +bool Unmarshalling(DevBrief &output, MessageParcel &data) +{ + return ITypesUtil::Unmarshal(data, output.uuid, output.networkId); +} + int64_t GetTotalSize(const std::vector &entries) { int64_t bufferSize = 1; diff --git a/frameworks/innerkitsimpl/kvdb/src/kvdb_service_client.cpp b/frameworks/innerkitsimpl/kvdb/src/kvdb_service_client.cpp index 3464c910de2b7deab3002b6b08cbc442a9b21a69..211d9b66582895aaa04f5a05374290ec92b068a9 100644 --- a/frameworks/innerkitsimpl/kvdb/src/kvdb_service_client.cpp +++ b/frameworks/innerkitsimpl/kvdb/src/kvdb_service_client.cpp @@ -290,6 +290,30 @@ Status KVDBServiceClient::GetBackupPassword( return static_cast(status); } +KVDBService::DevBrief KVDBServiceClient::GetLocalDevice() +{ + DevBrief brief; + MessageParcel reply; + int32_t status = IPC_SEND(TRANS_GET_LOCAL_DEVICE, reply); + if (status != SUCCESS) { + ZLOGE("status:0x%{public}x", status); + } + ITypesUtil::Unmarshal(reply, brief); + return brief; +} + +std::vector KVDBServiceClient::GetRemoteDevices() +{ + std::vector briefs; + MessageParcel reply; + int32_t status = IPC_SEND(TRANS_GET_REMOTE_DEVICES, reply); + if (status != SUCCESS) { + ZLOGE("status:0x%{public}x", status); + } + ITypesUtil::Unmarshal(reply, briefs); + return briefs; +} + sptr KVDBServiceClient::GetSyncAgent(const AppId &appId) { std::lock_guard lockGuard(agentMtx_); diff --git a/frameworks/innerkitsimpl/kvdb/test/BUILD.gn b/frameworks/innerkitsimpl/kvdb/test/BUILD.gn index 1fcd673c58c55b9f8b829aebfe9742669d3c1326..e94bd9a18e947584914b522357ed58ab4d8e7b94 100644 --- a/frameworks/innerkitsimpl/kvdb/test/BUILD.gn +++ b/frameworks/innerkitsimpl/kvdb/test/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import("//build/test.gni") +import("//foundation/distributeddatamgr/data_share/datashare.gni") module_output_path = "kv_store/distributeddatafwk" @@ -20,6 +21,9 @@ config("module_private_config") { include_dirs = [ "//commonlibrary/c_utils/base/include", + "${datashare_innerapi_path}/common/include", + "${datashare_innerapi_path}/provider/include", + "//foundation/distributeddatamgr/kv_store/frameworks/common", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/include", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/src", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include", @@ -28,11 +32,77 @@ config("module_private_config") { "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/app_distributeddata/include", "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/include", + "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/mod_securitylabel", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp/include", + "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include", "//test/testfwk/developer_test/aw/distributed", ] lib_dirs = [ "//foundation/appexecfwk/libs" ] } +############################################################################### +ohos_source_set("kvdb_src_file") { + testonly = true + + old_sources = [ + "../../distributeddatafwk/src/blob.cpp", + "../../distributeddatafwk/src/change_notification.cpp", + "../../distributeddatafwk/src/data_query.cpp", + "../../distributeddatafwk/src/device_status_change_listener_client.cpp", + "../../distributeddatafwk/src/distributed_kv_data_manager.cpp", + "../../distributeddatafwk/src/ikvstore_client_death_observer.cpp", + "../../distributeddatafwk/src/ikvstore_data_service.cpp", + "../../distributeddatafwk/src/ikvstore_observer.cpp", + "../../distributeddatafwk/src/ikvstore_sync_callback.cpp", + "../../distributeddatafwk/src/kv_utils.cpp", + "../../distributeddatafwk/src/kvstore_client_death_observer.cpp", + "../../distributeddatafwk/src/kvstore_datashare_bridge.cpp", + "../../distributeddatafwk/src/kvstore_observer_client.cpp", + "../../distributeddatafwk/src/kvstore_service_death_notifier.cpp", + "../../distributeddatafwk/src/kvstore_sync_callback_client.cpp", + "../../distributeddatafwk/src/sync_observer.cpp", + ] + + kvdb_sources = [ + "../src/auto_sync_timer.cpp", + "../src/backup_manager.cpp", + "../src/convertor.cpp", + "../src/dev_manager.cpp", + "../src/device_convertor.cpp", + "../src/kv_types_util.cpp", + "../src/kvdb_service_client.cpp", + "../src/observer_bridge.cpp", + "../src/security_manager.cpp", + "../src/single_store_impl.cpp", + "../src/store_factory.cpp", + "../src/store_manager.cpp", + "../src/store_result_set.cpp", + "../src/store_util.cpp", + "../src/system_api.cpp", + "../src/task_executor.cpp", + ] + + sources = old_sources + kvdb_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", + ] + external_deps = [ + "c_utils:utils", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hitrace_native:libhitracechain", + "hiviewdfx_hilog_native:libhilog", + "huks:libhukssdk", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + part_name = "kv_store" +} + ohos_unittest("SingleStoreImplTest") { module_out_path = module_output_path @@ -49,9 +119,9 @@ ohos_unittest("SingleStoreImplTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -71,9 +141,9 @@ ohos_unittest("StoreUtilTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -93,9 +163,9 @@ ohos_unittest("BackupManagerTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -116,9 +186,9 @@ ohos_unittest("AutoSyncTimerTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -139,9 +209,9 @@ ohos_unittest("DevManagerTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -162,9 +232,9 @@ ohos_unittest("SingleStoreImplGetTopTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } diff --git a/frameworks/innerkitsimpl/kvdb/test/auto_sync_timer_test.cpp b/frameworks/innerkitsimpl/kvdb/test/auto_sync_timer_test.cpp index 2bd082b4dd06bbaa53e1af8fa09dd4f4df679076..1e8d53bb971daeba1d0ab1dd983e3194aad2507b 100644 --- a/frameworks/innerkitsimpl/kvdb/test/auto_sync_timer_test.cpp +++ b/frameworks/innerkitsimpl/kvdb/test/auto_sync_timer_test.cpp @@ -129,7 +129,7 @@ void AutoSyncTimerTest::TearDown(void) /** * @tc.name: SingleWrite -* @tc.desc: get the store id of the kv store +* @tc.desc: single write * @tc.type: FUNC * @tc.require: I4XVQQ * @tc.author: Yang Qing @@ -151,13 +151,13 @@ HWTEST_F(AutoSyncTimerTest, SingleWrite, TestSize.Level0) } /** -* @tc.name: MultiWrite -* @tc.desc: get the store id of the kv store +* @tc.name: MultiWriteBelowDelayTime +* @tc.desc: write every 40 milliseconds * @tc.type: FUNC * @tc.require: I4XVQQ * @tc.author: Yang Qing */ -HWTEST_F(AutoSyncTimerTest, MultiWrite, TestSize.Level1) +HWTEST_F(AutoSyncTimerTest, MultiWriteBelowDelayTime, TestSize.Level1) { auto *instance = KVDBServiceMock::GetInstance(); ASSERT_NE(instance, nullptr); @@ -169,7 +169,7 @@ HWTEST_F(AutoSyncTimerTest, MultiWrite, TestSize.Level1) std::thread thread([&finished] { while (!finished.load()) { AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { { "ut_test_store" } }); - usleep(40); + std::this_thread::sleep_for(std::chrono::milliseconds(40)); } }); EXPECT_EQ(static_cast(instance->GetCallCount(1)), 1); @@ -182,6 +182,68 @@ HWTEST_F(AutoSyncTimerTest, MultiWrite, TestSize.Level1) ASSERT_EQ(it->second.count("ut_test_store"), 1); } +/** +* @tc.name: MultiWriteOverDelayTime +* @tc.desc: write every 150 milliseconds +* @tc.type: FUNC +* @tc.require: I4XVQQ +* @tc.author: Yang Qing + */ +HWTEST_F(AutoSyncTimerTest, MultiWriteOverDelayTime, TestSize.Level1) +{ + auto *instance = KVDBServiceMock::GetInstance(); + ASSERT_NE(instance, nullptr); + instance->ResetToZero(); + instance->startTime = time_point_cast(system_clock::now()).time_since_epoch().count(); + instance->endTime = 0; + instance->values_.clear(); + std::atomic_bool finished = false; + std::thread thread([&finished] { + while (!finished.load()) { + AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { { "ut_test_store" } }); + std::this_thread::sleep_for(std::chrono::milliseconds(150)); + } + }); + EXPECT_EQ(static_cast(instance->GetCallCount(1)), 1); + ASSERT_LT(instance->endTime - instance->startTime, 100); + finished.store(true); + thread.join(); + auto it = instance->values_.find("ut_test"); + ASSERT_NE(it, instance->values_.end()); + ASSERT_EQ(it->second.count("ut_test_store"), 1); +} + +/** +* @tc.name: MultiWriteOverForceTime +* @tc.desc: write every 400 milliseconds +* @tc.type: FUNC +* @tc.require: I4XVQQ +* @tc.author: Yang Qing + */ +HWTEST_F(AutoSyncTimerTest, MultiWriteOverForceTime, TestSize.Level1) +{ + auto *instance = KVDBServiceMock::GetInstance(); + ASSERT_NE(instance, nullptr); + instance->ResetToZero(); + instance->startTime = time_point_cast(system_clock::now()).time_since_epoch().count(); + instance->endTime = 0; + instance->values_.clear(); + std::atomic_bool finished = false; + std::thread thread([&finished] { + while (!finished.load()) { + AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { { "ut_test_store" } }); + std::this_thread::sleep_for(std::chrono::milliseconds(400)); + } + }); + EXPECT_EQ(static_cast(instance->GetCallCount(1)), 1); + ASSERT_LT(instance->endTime - instance->startTime, 100); + finished.store(true); + thread.join(); + auto it = instance->values_.find("ut_test"); + ASSERT_NE(it, instance->values_.end()); + ASSERT_EQ(it->second.count("ut_test_store"), 1); +} + /** * @tc.name: SingleWriteOvertenKVStores * @tc.desc: single write over ten kv stores @@ -227,4 +289,123 @@ HWTEST_F(AutoSyncTimerTest, SingleWriteOvertenKVStores, TestSize.Level1) ASSERT_EQ(it->second.count("ut_test_store9"), 1); ASSERT_EQ(it->second.count("ut_test_store10"), 1); } -} \ No newline at end of file + +/** +* @tc.name: MultiWriteOvertenKVStores +* @tc.desc: mulity wirte +* @tc.type: FUNC +* @tc.require: I4XVQQ +* @tc.author: YangQing +*/ +HWTEST_F(AutoSyncTimerTest, MultiWriteOvertenKVStores, TestSize.Level1) +{ + auto *instance = KVDBServiceMock::GetInstance(); + ASSERT_NE(instance, nullptr); + instance->ResetToZero(); + instance->startTime = time_point_cast(system_clock::now()).time_since_epoch().count(); + instance->endTime = 0; + instance->values_.clear(); + std::atomic_bool finished = false; + std::thread thread([&finished] { + while (!finished.load()) { + AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { + { "ut_test_store0" }, + { "ut_test_store1" }, + { "ut_test_store2" }, + { "ut_test_store3" }, + { "ut_test_store4" }, + { "ut_test_store5" }, + { "ut_test_store6" }, + { "ut_test_store7" }, + { "ut_test_store8" }, + { "ut_test_store9" }, + { "ut_test_store10" }, + }); + usleep(40); + } + }); + EXPECT_EQ(static_cast(instance->GetCallCount(1)), 1); + ASSERT_GE(instance->endTime - instance->startTime, 200); + ASSERT_LT(instance->endTime - instance->startTime, 250); + finished.store(true); + thread.join(); + EXPECT_EQ(static_cast(instance->GetCallCount(11)), 11); + auto it = instance->values_.find("ut_test"); + ASSERT_EQ(it->second.count("ut_test_store0"), 1); + ASSERT_EQ(it->second.count("ut_test_store1"), 1); + ASSERT_EQ(it->second.count("ut_test_store2"), 1); + ASSERT_EQ(it->second.count("ut_test_store3"), 1); + ASSERT_EQ(it->second.count("ut_test_store4"), 1); + ASSERT_EQ(it->second.count("ut_test_store5"), 1); + ASSERT_EQ(it->second.count("ut_test_store6"), 1); + ASSERT_EQ(it->second.count("ut_test_store7"), 1); + ASSERT_EQ(it->second.count("ut_test_store8"), 1); + ASSERT_EQ(it->second.count("ut_test_store9"), 1); + ASSERT_EQ(it->second.count("ut_test_store10"), 1); +} + +/** +* @tc.name: DoubleWrite +* @tc.desc: double wirte +* @tc.type: FUNC +* @tc.require: I4XVQQ +* @tc.author: YangQing + */ +HWTEST_F(AutoSyncTimerTest, DoubleWrite, TestSize.Level1) +{ + auto *instance = KVDBServiceMock::GetInstance(); + ASSERT_NE(instance, nullptr); + instance->ResetToZero(); + instance->startTime = time_point_cast(system_clock::now()).time_since_epoch().count(); + instance->endTime = 0; + instance->values_.clear(); + AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { + { "ut_test_store0" }, + { "ut_test_store1" }, + { "ut_test_store2" }, + { "ut_test_store3" }, + { "ut_test_store4" }, + { "ut_test_store5" }, + { "ut_test_store6" }, + { "ut_test_store7" }, + { "ut_test_store8" }, + { "ut_test_store9" }, + { "ut_test_store10" }, + }); + AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { + { "ut_test_store-0" }, + { "ut_test_store-1" }, + { "ut_test_store-2" }, + { "ut_test_store-3" }, + { "ut_test_store-4" }, + { "ut_test_store-5" }, + { "ut_test_store-6" }, + { "ut_test_store-7" }, + { "ut_test_store-8" }, + }); + EXPECT_EQ(static_cast(instance->GetCallCount(1)), 1); + ASSERT_LT(instance->endTime - instance->startTime, 100); + EXPECT_EQ(static_cast(instance->GetCallCount(20)), 20); + auto it = instance->values_.find("ut_test"); + ASSERT_EQ(it->second.count("ut_test_store0"), 1); + ASSERT_EQ(it->second.count("ut_test_store1"), 1); + ASSERT_EQ(it->second.count("ut_test_store2"), 1); + ASSERT_EQ(it->second.count("ut_test_store3"), 1); + ASSERT_EQ(it->second.count("ut_test_store4"), 1); + ASSERT_EQ(it->second.count("ut_test_store5"), 1); + ASSERT_EQ(it->second.count("ut_test_store6"), 1); + ASSERT_EQ(it->second.count("ut_test_store7"), 1); + ASSERT_EQ(it->second.count("ut_test_store8"), 1); + ASSERT_EQ(it->second.count("ut_test_store9"), 1); + ASSERT_EQ(it->second.count("ut_test_store10"), 1); + ASSERT_EQ(it->second.count("ut_test_store-0"), 1); + ASSERT_EQ(it->second.count("ut_test_store-1"), 1); + ASSERT_EQ(it->second.count("ut_test_store-2"), 1); + ASSERT_EQ(it->second.count("ut_test_store-3"), 1); + ASSERT_EQ(it->second.count("ut_test_store-4"), 1); + ASSERT_EQ(it->second.count("ut_test_store-5"), 1); + ASSERT_EQ(it->second.count("ut_test_store-6"), 1); + ASSERT_EQ(it->second.count("ut_test_store-7"), 1); + ASSERT_EQ(it->second.count("ut_test_store-8"), 1); +} +} // namespace OHOS::Test \ No newline at end of file diff --git a/frameworks/innerkitsimpl/kvdb/test/backup_manager_test.cpp b/frameworks/innerkitsimpl/kvdb/test/backup_manager_test.cpp index cd4144505d1145284f8a706b6ddefa9c0674f1c0..4d5aad40b0cdfc43f1efecabfea95d8341494f36 100644 --- a/frameworks/innerkitsimpl/kvdb/test/backup_manager_test.cpp +++ b/frameworks/innerkitsimpl/kvdb/test/backup_manager_test.cpp @@ -23,6 +23,7 @@ #include "store_util.h" #include "sys/stat.h" #include "types.h" +namespace OHOS::Test { using namespace testing::ext; using namespace OHOS::DistributedKv; class BackupManagerTest : public testing::Test { @@ -469,4 +470,5 @@ HWTEST_F(BackupManagerTest, BackUpEntry, TestSize.Level0) ASSERT_EQ(status, SUCCESS); status = StoreManager::GetInstance().Delete(appId, storeId, baseDir); ASSERT_EQ(status, SUCCESS); -} \ No newline at end of file +} +} // namespace OHOS::Test \ No newline at end of file diff --git a/frameworks/innerkitsimpl/kvdb/test/dev_manager_test.cpp b/frameworks/innerkitsimpl/kvdb/test/dev_manager_test.cpp index b143860233b04c2f1355a6125590507e70ceceb0..01bf94431e59a9a61bfdedcfbe4fc7b34d2520b7 100644 --- a/frameworks/innerkitsimpl/kvdb/test/dev_manager_test.cpp +++ b/frameworks/innerkitsimpl/kvdb/test/dev_manager_test.cpp @@ -19,6 +19,7 @@ #include "dev_manager.h" #include "types.h" #include "log_print.h" +namespace OHOS::Test { using namespace testing::ext; using namespace OHOS::DistributedKv; @@ -44,52 +45,67 @@ void DevManagerTest::TearDown(void) {} /** -* @tc.name: GetLocalDevice001 +* @tc.name: GetLocalDevice * @tc.desc: Get local device's infomation * @tc.type: FUNC * @tc.require: * @tc.author: taoyuxin */ -HWTEST_F(DevManagerTest, GetLocalDevice001, TestSize.Level1) +HWTEST_F(DevManagerTest, GetLocalDevice, TestSize.Level1) { - ZLOGI("GetLocalDevice001 begin."); - DevManager &devManager = OHOS::DistributedKv::DevManager::GetInstance(); - DevManager::DetailInfo devInfo = devManager.GetLocalDevice(); - + ZLOGI("GetLocalDevice begin."); + auto devInfo = DevManager::GetInstance().GetLocalDevice(); EXPECT_NE(devInfo.networkId, ""); EXPECT_NE(devInfo.uuid, ""); - EXPECT_NE(devInfo.udid, ""); } /** -* @tc.name: ToUUID001 +* @tc.name: ToUUID * @tc.desc: Get uuid from networkId * @tc.type: FUNC * @tc.require: * @tc.author: taoyuxin */ -HWTEST_F(DevManagerTest, ToUUID001, TestSize.Level1) +HWTEST_F(DevManagerTest, ToUUID, TestSize.Level1) { - ZLOGI("ToUUID001 begin."); - DevManager &devManager = OHOS::DistributedKv::DevManager::GetInstance(); - DevManager::DetailInfo devInfo = devManager.GetLocalDevice(); + ZLOGI("ToUUID begin."); + auto &devMgr = DevManager::GetInstance(); + auto devInfo = devMgr.GetLocalDevice(); EXPECT_NE(devInfo.networkId, ""); - std::string uuid = devManager.ToUUID(devInfo.networkId); + auto uuid = devMgr.ToUUID(devInfo.networkId); EXPECT_NE(uuid, ""); EXPECT_EQ(uuid, devInfo.uuid); } /** -* @tc.name: GetRemoteDevices001 +* @tc.name: ToNetworkId +* @tc.desc: Get networkId from uuid +* @tc.type: FUNC +* @tc.require: +* @tc.author: zuojiangjiang +*/ +HWTEST_F(DevManagerTest, ToNetworkId, TestSize.Level1) +{ + auto &devMgr = DevManager::GetInstance(); + auto devInfo = devMgr.GetLocalDevice(); + EXPECT_NE(devInfo.uuid, ""); + auto networkId = devMgr.ToNetworkId(devInfo.uuid); + EXPECT_NE(networkId, ""); + EXPECT_EQ(networkId, devInfo.networkId); +} + +/** +* @tc.name: GetRemoteDevices * @tc.desc: Get remote devices * @tc.type: FUNC * @tc.require: * @tc.author: taoyuxin */ -HWTEST_F(DevManagerTest, GetRemoteDevices001, TestSize.Level1) +HWTEST_F(DevManagerTest, GetRemoteDevices, TestSize.Level1) { - ZLOGI("GetRemoteDevices001 begin."); + ZLOGI("GetRemoteDevices begin."); DevManager &devManager = OHOS::DistributedKv::DevManager::GetInstance(); - vector devInfo = devManager.GetRemoteDevices(); - EXPECT_EQ(devInfo.size(), 0); + auto devInfos = devManager.GetRemoteDevices(); + EXPECT_EQ(devInfos.size(), 0); } +} // namespace OHOS::Test \ No newline at end of file diff --git a/frameworks/innerkitsimpl/kvdb/test/single_store_impl_get_top_test.cpp b/frameworks/innerkitsimpl/kvdb/test/single_store_impl_get_top_test.cpp index 38ad5f63e249601eeff5805a44a68453cf3f161a..21f09dae8957ce87cb635a391b2720c04f38346d 100644 --- a/frameworks/innerkitsimpl/kvdb/test/single_store_impl_get_top_test.cpp +++ b/frameworks/innerkitsimpl/kvdb/test/single_store_impl_get_top_test.cpp @@ -22,6 +22,7 @@ #include "distributed_kv_data_manager.h" #include "types.h" +namespace OHOS::Test { using namespace testing::ext; using namespace OHOS::DistributedKv; class SingleStoreImplGetTopTest : public testing::Test { @@ -36,7 +37,6 @@ public: static std::shared_ptr singleKvStore; // declare kvstore instance. static Status initStatus; - static int MAX_VALUE_SIZE; }; const std::string VALID_SCHEMA_STRICT_DEFINE = "{\"SCHEMA_VERSION\":\"1.0\"," @@ -49,7 +49,6 @@ const std::string VALID_SCHEMA_STRICT_DEFINE = "{\"SCHEMA_VERSION\":\"1.0\"," std::shared_ptr SingleStoreImplGetTopTest::singleKvStore = nullptr; Status SingleStoreImplGetTopTest::initStatus = Status::ERROR; -int SingleStoreImplGetTopTest::MAX_VALUE_SIZE = 4 * 1024 * 1024; // max value size is 4M. void SingleStoreImplGetTopTest::SetUpTestCase(void) { @@ -283,4 +282,5 @@ HWTEST_F(SingleStoreImplGetTopTest, GetResultSetOrderByWriteTimeNoPrefix, TestSi auto status = singleKvStore->GetResultSet(query, output); ASSERT_EQ(status, NOT_SUPPORT); ASSERT_EQ(output, nullptr); -} \ No newline at end of file +} +} // namespace OHOS::Test \ No newline at end of file diff --git a/frameworks/innerkitsimpl/kvdb/test/single_store_impl_test.cpp b/frameworks/innerkitsimpl/kvdb/test/single_store_impl_test.cpp index b669a2a2ad3ed25aeac5bb0bc02e29db94b55d2f..2c78c47f67c7131c77b65c0bf9af837821e5b9e7 100644 --- a/frameworks/innerkitsimpl/kvdb/test/single_store_impl_test.cpp +++ b/frameworks/innerkitsimpl/kvdb/test/single_store_impl_test.cpp @@ -826,7 +826,7 @@ HWTEST_F(SingleStoreImplTest, RemoveDeviceData, TestSize.Level0) status = store->GetCount({}, count); ASSERT_EQ(status, SUCCESS); ASSERT_EQ(count, 10); - status = store->RemoveDeviceData(DevManager::GetInstance().GetLocalDevice().networkId); + status = store->RemoveDeviceData(DevManager::GetInstance().GetLocalDevice().uuid); ASSERT_EQ(status, SUCCESS); status = store->GetCount({}, count); ASSERT_EQ(status, SUCCESS); @@ -1293,4 +1293,4 @@ HWTEST_F(SingleStoreImplTest, GetKVStoreWithRebuildTrue, TestSize.Level0) status = StoreManager::GetInstance().CloseKVStore(appId, storeId); ASSERT_EQ(status, SUCCESS); } -} \ No newline at end of file +} // namespace OHOS::Test \ No newline at end of file diff --git a/frameworks/innerkitsimpl/kvdb/test/store_util_test.cpp b/frameworks/innerkitsimpl/kvdb/test/store_util_test.cpp index a617931adf3c2f8276d17a0b76a0780498ad603b..0de6157d7acc175a6c6f8c3b1801747ae5700649 100644 --- a/frameworks/innerkitsimpl/kvdb/test/store_util_test.cpp +++ b/frameworks/innerkitsimpl/kvdb/test/store_util_test.cpp @@ -20,6 +20,7 @@ #include "store_manager.h" #include "types.h" +namespace OHOS::Test { using namespace testing::ext; using namespace OHOS::DistributedKv; @@ -127,4 +128,5 @@ HWTEST_F(StoreUtilTest, GetObserverMode, TestSize.Level1) mode = storeUtil_.GetObserverMode(SUBSCRIBE_TYPE_ALL); ASSERT_EQ(mode, DistributedDB::OBSERVER_CHANGES_FOREIGN | DistributedDB::OBSERVER_CHANGES_NATIVE); -} \ No newline at end of file +} +} // namespace OHOS::Test \ No newline at end of file diff --git a/frameworks/innerkitsimpl/object/include/iobject_callback.h b/frameworks/innerkitsimpl/object/include/iobject_callback.h index 1fbb341dc6c9ce6d68eac50fd0d6535f62600424..f37636adde7735c9a95cd1e52821aac34fdc5039 100644 --- a/frameworks/innerkitsimpl/object/include/iobject_callback.h +++ b/frameworks/innerkitsimpl/object/include/iobject_callback.h @@ -31,12 +31,12 @@ public: virtual void Completed(const std::map &results) = 0; }; -class ObjectSaveCallbackStub : public IRemoteStub { +class API_EXPORT ObjectSaveCallbackStub : public IRemoteStub { public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -class ObjectSaveCallbackProxy : public IRemoteProxy { +class API_EXPORT ObjectSaveCallbackProxy : public IRemoteProxy { public: explicit ObjectSaveCallbackProxy(const sptr &impl); ~ObjectSaveCallbackProxy() = default; @@ -52,12 +52,12 @@ public: virtual void Completed(int32_t status) = 0; }; -class ObjectRevokeSaveCallbackStub : public IRemoteStub { +class API_EXPORT ObjectRevokeSaveCallbackStub : public IRemoteStub { public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -class ObjectRevokeSaveCallbackProxy : public IRemoteProxy { +class API_EXPORT ObjectRevokeSaveCallbackProxy : public IRemoteProxy { public: explicit ObjectRevokeSaveCallbackProxy(const sptr &impl); ~ObjectRevokeSaveCallbackProxy() = default; @@ -73,12 +73,12 @@ public: virtual void Completed(const std::map> &results) = 0; }; -class ObjectRetrieveCallbackStub : public IRemoteStub { +class API_EXPORT ObjectRetrieveCallbackStub : public IRemoteStub { public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -class ObjectRetrieveCallbackProxy : public IRemoteProxy { +class API_EXPORT ObjectRetrieveCallbackProxy : public IRemoteProxy { public: explicit ObjectRetrieveCallbackProxy(const sptr &impl); ~ObjectRetrieveCallbackProxy() = default; @@ -94,12 +94,12 @@ public: virtual void Completed(const std::map> &results) = 0; }; -class ObjectChangeCallbackStub : public IRemoteStub { +class API_EXPORT ObjectChangeCallbackStub : public IRemoteStub { public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -class ObjectChangeCallbackProxy : public IRemoteProxy { +class API_EXPORT ObjectChangeCallbackProxy : public IRemoteProxy { public: explicit ObjectChangeCallbackProxy(const sptr &impl); ~ObjectChangeCallbackProxy() = default; @@ -108,7 +108,7 @@ public: private: static inline BrokerDelegator delegator_; }; -} // namespace DistributedKv +} // namespace DistributedObject } // namespace OHOS #endif // I_KVSTORE_SYNC_CALLBACK_H diff --git a/frameworks/innerkitsimpl/object/include/iobject_service.h b/frameworks/innerkitsimpl/object/include/iobject_service.h index cbeb3e75376c36fae6c1feeade22a8b42951fdc7..3f024d8a741a12f73ce5718df25bf3658dd7a6ac 100644 --- a/frameworks/innerkitsimpl/object/include/iobject_service.h +++ b/frameworks/innerkitsimpl/object/include/iobject_service.h @@ -24,5 +24,5 @@ namespace OHOS::DistributedObject { class IObjectService : public ObjectService, public IRemoteBroker { }; -} // namespace OHOS::DistributedRdb +} // namespace OHOS::DistributedObject #endif diff --git a/frameworks/innerkitsimpl/object/include/object_service_proxy.h b/frameworks/innerkitsimpl/object/include/object_service_proxy.h index 1357fa1beb5c1a03f6474ca3e65fed5c4125ee18..7af20003aca4305e774a34617143f986b7f67b94 100644 --- a/frameworks/innerkitsimpl/object/include/object_service_proxy.h +++ b/frameworks/innerkitsimpl/object/include/object_service_proxy.h @@ -22,7 +22,7 @@ #include "iobject_service.h" namespace OHOS::DistributedObject { -class ObjectServiceProxy : public IRemoteProxy { +class API_EXPORT ObjectServiceProxy : public IRemoteProxy { public: explicit ObjectServiceProxy(const sptr &impl); ~ObjectServiceProxy() = default; @@ -40,5 +40,5 @@ public: private: static inline BrokerDelegator delegator_; }; -} // namespace OHOS::DistributedRdb +} // namespace OHOS::DistributedObject #endif diff --git a/frameworks/innerkitsimpl/rdb/include/rdb_notifier.h b/frameworks/innerkitsimpl/rdb/include/rdb_notifier.h deleted file mode 100644 index 7887ec9766cd786ea0611bdcd3ebd98606d82f85..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/rdb/include/rdb_notifier.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2022 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 DISTRIBUTED_RDB_NOTIFIER_H -#define DISTRIBUTED_RDB_NOTIFIER_H - -#include -#include -#include - -#include "rdb_types.h" - -namespace OHOS::DistributedRdb { -class IRdbNotifier : public IRemoteBroker { -public: - enum { - RDB_NOTIFIER_CMD_SYNC_COMPLETE, - RDB_NOTIFIER_CMD_DATA_CHANGE, - RDB_NOTIFIER_CMD_MAX - }; - - virtual int32_t OnComplete(uint32_t seqNum, const SyncResult& result) = 0; - - virtual int32_t OnChange(const std::string& storeName, const std::vector& devices) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedRdb.IRdbNotifier"); -}; - -class RdbNotifierProxy : public IRemoteProxy { -public: - explicit RdbNotifierProxy(const sptr& object); - virtual ~RdbNotifierProxy() noexcept; - - int32_t OnComplete(uint32_t seqNum, const SyncResult& result) override; - - int32_t OnChange(const std::string& storeName, const std::vector& devices) override; - -private: - static inline BrokerDelegator delegator_; -}; - -using RdbSyncCompleteNotifier = std::function; -using RdbDataChangeNotifier = std::function&)>; - -class RdbNotifierStub : public IRemoteStub { -public: - RdbNotifierStub(const RdbSyncCompleteNotifier&, const RdbDataChangeNotifier&); - virtual ~RdbNotifierStub() noexcept; - - int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - - int32_t OnCompleteInner(MessageParcel& data, MessageParcel& reply); - int32_t OnComplete(uint32_t seqNum, const SyncResult& result) override; - - int32_t OnChangeInner(MessageParcel&data, MessageParcel& reply); - int32_t OnChange(const std::string& storeName, const std::vector& devices) override; - -private: - bool CheckInterfaceToken(MessageParcel& data); - - using RequestHandle = int32_t (RdbNotifierStub::*)(MessageParcel&, MessageParcel&); - static constexpr RequestHandle HANDLES[RDB_NOTIFIER_CMD_MAX] = { - [RDB_NOTIFIER_CMD_SYNC_COMPLETE] = &RdbNotifierStub::OnCompleteInner, - [RDB_NOTIFIER_CMD_DATA_CHANGE] = &RdbNotifierStub::OnChangeInner, - }; - - RdbSyncCompleteNotifier completeNotifier_; - RdbDataChangeNotifier changeNotifier_; -}; -} // namespace OHOS::DistributedRdb -#endif diff --git a/frameworks/innerkitsimpl/rdb/include/rdb_service.h b/frameworks/innerkitsimpl/rdb/include/rdb_service.h deleted file mode 100644 index e21c99e0ad581318341c6a9f1a9756844debb2f2..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/rdb/include/rdb_service.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2022 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 DISTRIBUTED_RDB_SERVICE_H -#define DISTRIBUTED_RDB_SERVICE_H - -#include -#include -#include "iremote_broker.h" -#include "iremote_object.h" -#include "rdb_types.h" - -namespace OHOS { -namespace DistributedRdb { -class RdbService { -public: - enum { - RDB_SERVICE_CMD_OBTAIN_TABLE, - RDB_SERVICE_CMD_INIT_NOTIFIER, - RDB_SERVICE_CMD_SET_DIST_TABLE, - RDB_SERVICE_CMD_SYNC, - RDB_SERVICE_CMD_ASYNC, - RDB_SERVICE_CMD_SUBSCRIBE, - RDB_SERVICE_CMD_UNSUBSCRIBE, - RDB_SERVICE_CMD_REMOTE_QUERY, - RDB_SERVICE_CREATE_RDB_TABLE, - RDB_SERVICE_DESTROY_RDB_TABLE, - RDB_SERVICE_CMD_MAX - }; - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedRdb.IRdbService"); - virtual std::string ObtainDistributedTableName(const std::string &device, const std::string &table) = 0; - - virtual int32_t SetDistributedTables(const RdbSyncerParam ¶m, const std::vector &tables) = 0; - - virtual int32_t Sync(const RdbSyncerParam ¶m, const SyncOption &option, const RdbPredicates &predicates, - const SyncCallback &callback) = 0; - - virtual int32_t Subscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, - RdbStoreObserver *observer) = 0; - - virtual int32_t UnSubscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, - RdbStoreObserver *observer) = 0; - - virtual int32_t RemoteQuery(const RdbSyncerParam ¶m, const std::string &device, const std::string &sql, - const std::vector &selectionArgs, sptr &resultSet) = 0; - virtual int32_t CreateRDBTable(const RdbSyncerParam ¶m, const std::string &writePermission, - const std::string &readPermission) = 0; - - virtual int32_t DestroyRDBTable(const RdbSyncerParam ¶m) = 0; - - virtual int32_t InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) = 0; - -protected: - virtual int32_t DoSync(const RdbSyncerParam ¶m, const SyncOption &option, const RdbPredicates &predicates, - SyncResult &result) = 0; - - virtual int32_t DoAsync(const RdbSyncerParam ¶m, uint32_t seqNum, const SyncOption &option, - const RdbPredicates &predicates) = 0; - - virtual int32_t DoSubscribe(const RdbSyncerParam ¶m) = 0; - - virtual int32_t DoUnSubscribe(const RdbSyncerParam ¶m) = 0; -}; -} -} // namespace OHOS::DistributedRdb -#endif diff --git a/frameworks/innerkitsimpl/rdb/include/rdb_types.h b/frameworks/innerkitsimpl/rdb/include/rdb_types.h deleted file mode 100644 index 998260ab248e8eece9924bb73c765c7f4b3685e6..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/rdb/include/rdb_types.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2022 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 DISTRIBUTEDDATAFWK_RDB_TYPES_H -#define DISTRIBUTEDDATAFWK_RDB_TYPES_H - -#include -#include -#include -#include - -namespace OHOS::DistributedRdb { -enum RdbStatus { - RDB_OK, - RDB_ERROR, -}; - -enum RdbDistributedType { - RDB_DEVICE_COLLABORATION = 10, - RDB_DISTRIBUTED_TYPE_MAX -}; - -struct RdbSyncerParam { - std::string bundleName_; - std::string hapName_; - std::string storeName_; - int32_t area_ = 0; - int32_t level_ = 0; - int32_t type_ = RDB_DEVICE_COLLABORATION; - bool isAutoSync_ = false; - bool isEncrypt_ = false; - std::vector password_; -}; - -enum SyncMode : int32_t { - PUSH, - PULL, -}; - -struct SyncOption { - SyncMode mode; - bool isBlock; -}; - -using SyncResult = std::map; // networkId -using SyncCallback = std::function; - -enum RdbPredicateOperator { - EQUAL_TO, - NOT_EQUAL_TO, - AND, - OR, - ORDER_BY, - LIMIT, - OPERATOR_MAX -}; - -struct RdbPredicateOperation { - RdbPredicateOperator operator_; - std::string field_; - std::vector values_; -}; - -struct RdbPredicates { - inline void AddOperation(const RdbPredicateOperator op, const std::string& field, - const std::string& value) - { - operations_.push_back({ op, field, { value } }); - } - inline void AddOperation(const RdbPredicateOperator op, const std::string& field, - const std::vector& values) - { - operations_.push_back({ op, field, values }); - } - - std::string table_; - std::vector devices_; - std::vector operations_; -}; - -enum SubscribeMode { - REMOTE, - SUBSCRIBE_MODE_MAX -}; - -struct SubscribeOption { - SubscribeMode mode; -}; - -class RdbStoreObserver { -public: - virtual void OnChange(const std::vector& devices) = 0; // networkid -}; - -struct DropOption { -}; -} // namespace OHOS::DistributedRdb -#endif diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.cpp b/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.cpp deleted file mode 100644 index bd87ee4029e1d27f5f55a5b2f026bc3894a3e57b..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2022 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 "RdbManagerImpl" - -#include "rdb_manager_impl.h" - -#include -#include "iservice_registry.h" -#include "ipc_skeleton.h" -#include "system_ability_definition.h" - -#include "log_print.h" -#include "ikvstore_data_service.h" -#include "irdb_service.h" -#include "rdb_service_proxy.h" - -namespace OHOS::DistributedRdb { -static sptr GetDistributedDataManager() -{ - int retry = 0; - while (++retry <= RdbManagerImpl::GET_SA_RETRY_TIMES) { - auto manager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (manager == nullptr) { - ZLOGE("get system ability manager failed"); - return nullptr; - } - ZLOGI("get distributed data manager %{public}d", retry); - auto remoteObject = manager->CheckSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); - if (remoteObject == nullptr) { - std::this_thread::sleep_for(std::chrono::seconds(RdbManagerImpl::RETRY_INTERVAL)); - continue; - } - ZLOGI("get distributed data manager success"); - return iface_cast(remoteObject); - } - - ZLOGE("get distributed data manager failed"); - return nullptr; -} - -static void LinkToDeath(const sptr& remote) -{ - auto& manager = RdbManagerImpl::GetInstance(); - sptr deathRecipient = - new(std::nothrow) RdbManagerImpl::ServiceDeathRecipient(&manager); - if (!remote->AddDeathRecipient(deathRecipient)) { - ZLOGE("add death recipient failed"); - } - ZLOGE("success"); -} - -RdbManagerImpl::RdbManagerImpl() -{ - ZLOGI("construct"); -} - -RdbManagerImpl::~RdbManagerImpl() -{ - ZLOGI("destroy"); -} - -RdbManagerImpl& RdbManagerImpl::GetInstance() -{ - static RdbManagerImpl manager; - return manager; -} - -sptr RdbManagerImpl::GetRdbService() -{ - if (distributedDataMgr_ == nullptr) { - distributedDataMgr_ = GetDistributedDataManager(); - } - if (distributedDataMgr_ == nullptr) { - ZLOGE("get distributed data manager failed"); - return nullptr; - } - - auto remote = distributedDataMgr_->GetFeatureInterface("relational_store"); - if (remote == nullptr) { - ZLOGE("get rdb service failed"); - return nullptr; - } - return iface_cast(remote); -} - -std::shared_ptr RdbManagerImpl::GetRdbService(const RdbSyncerParam& param) -{ - std::lock_guard lock(mutex_); - if (rdbService_ != nullptr) { - return rdbService_; - } - auto service = GetRdbService(); - if (service == nullptr) { - return nullptr; - } - if (service->InitNotifier(param) != RDB_OK) { - ZLOGE("init notifier failed"); - return nullptr; - } - sptr serviceBase = service; - LinkToDeath(serviceBase->AsObject().GetRefPtr()); - rdbService_ = std::shared_ptr(service.GetRefPtr(), [holder = service] (const auto*) {}); - bundleName_ = param.bundleName_; - return rdbService_; -} - -void RdbManagerImpl::OnRemoteDied() -{ - ZLOGI("rdb service has dead!!"); - auto proxy = std::static_pointer_cast(rdbService_); - auto observers = proxy->ExportObservers(); - ResetServiceHandle(); - - std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); - RdbSyncerParam param; - param.bundleName_ = bundleName_; - auto service = GetRdbService(param); - if (service == nullptr) { - return; - } - proxy = std::static_pointer_cast(service); - if (proxy == nullptr) { - return; - } - ZLOGI("restore observer"); - proxy->ImportObservers(observers); -} - -void RdbManagerImpl::ResetServiceHandle() -{ - ZLOGI("enter"); - std::lock_guard lock(mutex_); - distributedDataMgr_ = nullptr; - rdbService_ = nullptr; -} -} // namespace OHOS::DistributedRdb diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.h b/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.h deleted file mode 100644 index fd88e514f0e04db2f7ae73d2cf0d909c43eb5ddf..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2022 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 DISTRIBUTED_RDB_MANAGER_IMPL_H -#define DISTRIBUTED_RDB_MANAGER_IMPL_H - -#include -#include -#include - -#include "refbase.h" -#include "iremote_object.h" -#include "concurrent_map.h" -#include "rdb_types.h" - -namespace OHOS::DistributedKv { -class KvStoreDataServiceProxy; -} - -namespace OHOS::DistributedRdb { -class RdbService; -class RdbServiceProxy; -class RdbManagerImpl { -public: - static constexpr int GET_SA_RETRY_TIMES = 3; - static constexpr int RETRY_INTERVAL = 1; - static constexpr int WAIT_TIME = 2; - - static RdbManagerImpl &GetInstance(); - - std::shared_ptr GetRdbService(const RdbSyncerParam& param); - - void OnRemoteDied(); - - class ServiceDeathRecipient : public IRemoteObject::DeathRecipient { - public: - explicit ServiceDeathRecipient(RdbManagerImpl* owner) : owner_(owner) {} - void OnRemoteDied(const wptr &object) override - { - if (owner_ != nullptr) { - owner_->OnRemoteDied(); - } - } - private: - RdbManagerImpl* owner_; - }; - -private: - RdbManagerImpl(); - - ~RdbManagerImpl(); - - sptr GetRdbService(); - - void ResetServiceHandle(); - - std::mutex mutex_; - sptr distributedDataMgr_; - std::shared_ptr rdbService_; - std::string bundleName_; -}; -} // namespace OHOS::DistributedRdb -#endif diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_notifier.cpp b/frameworks/innerkitsimpl/rdb/src/rdb_notifier.cpp deleted file mode 100644 index bffd4c33ec1b6677d3e2e5cc9a547090488dd41b..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/rdb/src/rdb_notifier.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2022 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 "RdbNotifier" - -#include "rdb_notifier.h" -#include -#include "itypes_util.h" -#include "log_print.h" - - -namespace OHOS::DistributedRdb { -RdbNotifierProxy::RdbNotifierProxy(const sptr &object) - : IRemoteProxy(object) -{ - ZLOGI("construct"); -} - -RdbNotifierProxy::~RdbNotifierProxy() noexcept -{ - ZLOGI("destroy"); -} - -int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, const SyncResult &result) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbNotifier::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!data.WriteUint32(seqNum)) { - ZLOGE("write seq num failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshalling(result, data)) { - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (Remote()->SendRequest(RDB_NOTIFIER_CMD_SYNC_COMPLETE, data, reply, option) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - return RDB_OK; -} - -int RdbNotifierProxy::OnChange(const std::string& storeName, const std::vector &devices) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbNotifier::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!data.WriteString(storeName)) { - ZLOGE("write store name failed"); - return RDB_ERROR; - } - if (!data.WriteStringVector(devices)) { - ZLOGE("write devices failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (Remote()->SendRequest(RDB_NOTIFIER_CMD_DATA_CHANGE, data, reply, option) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - return RDB_OK; -} - -RdbNotifierStub::RdbNotifierStub(const RdbSyncCompleteNotifier& completeNotifier, - const RdbDataChangeNotifier& changeNotifier) - : IRemoteStub(), completeNotifier_(completeNotifier), changeNotifier_(changeNotifier) -{ - ZLOGI("construct"); -} - -RdbNotifierStub::~RdbNotifierStub() noexcept -{ - ZLOGI("destroy"); -} - -bool RdbNotifierStub::CheckInterfaceToken(MessageParcel& data) -{ - auto localDescriptor = IRdbNotifier::GetDescriptor(); - auto remoteDescriptor = data.ReadInterfaceToken(); - if (remoteDescriptor != localDescriptor) { - ZLOGE("interface token is not equal"); - return false; - } - return true; -} - -int RdbNotifierStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - ZLOGD("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid()); - if (!CheckInterfaceToken(data)) { - return RDB_ERROR; - } - - if (code >= 0 && code < RDB_NOTIFIER_CMD_MAX) { - return (this->*HANDLES[code])(data, reply); - } - - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -int32_t RdbNotifierStub::OnCompleteInner(MessageParcel &data, MessageParcel &reply) -{ - uint32_t seqNum; - if (!data.ReadUint32(seqNum)) { - ZLOGI("read seq num failed"); - return RDB_ERROR; - } - SyncResult result; - if (!ITypesUtil::Unmarshal(data, result)) { - ZLOGE("read sync result failed"); - return RDB_ERROR; - } - return OnComplete(seqNum, result); -} - -int32_t RdbNotifierStub::OnComplete(uint32_t seqNum, const SyncResult &result) -{ - if (completeNotifier_) { - completeNotifier_(seqNum, result); - } - return RDB_OK; -} - -int32_t RdbNotifierStub::OnChangeInner(MessageParcel &data, MessageParcel &reply) -{ - std::string storeName; - if (!data.ReadString(storeName)) { - ZLOGE("read store name failed"); - return RDB_ERROR; - } - std::vector devices; - if (!data.ReadStringVector(&devices)) { - ZLOGE("read devices failed"); - return RDB_ERROR; - } - return OnChange(storeName, devices); -} - -int32_t RdbNotifierStub::OnChange(const std::string& storeName, const std::vector &devices) -{ - if (changeNotifier_) { - changeNotifier_(storeName, devices); - } - return RDB_OK; -} -} // namespace OHOS::DistributedRdb diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.cpp b/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.cpp deleted file mode 100644 index faee47d6d7a6f4aa4ceffb5c36edc0a1798743e5..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.cpp +++ /dev/null @@ -1,445 +0,0 @@ -/* - * Copyright (c) 2022 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 "RdbServiceProxy" - -#include "rdb_service_proxy.h" -#include "itypes_util.h" -#include "log_print.h" - -namespace OHOS::DistributedRdb { -RdbServiceProxy::RdbServiceProxy(const sptr &object) - : IRemoteProxy(object) -{ - ZLOGI("construct"); -} - -void RdbServiceProxy::OnSyncComplete(uint32_t seqNum, const SyncResult &result) -{ - syncCallbacks_.ComputeIfPresent(seqNum, [&result] (const auto& key, const SyncCallback& callback) { - callback(result); - return true; - }); - syncCallbacks_.Erase(seqNum); -} - -void RdbServiceProxy::OnDataChange(const std::string& storeName, const std::vector &devices) -{ - ZLOGI("%{public}s", storeName.c_str()); - auto name = RemoveSuffix(storeName); - observers_.ComputeIfPresent( - name, [&devices] (const auto& key, const ObserverMapValue& value) { - for (const auto& observer : value.first) { - observer->OnChange(devices); - } - return true; - }); -} - -std::string RdbServiceProxy::ObtainDistributedTableName(const std::string &device, const std::string &table) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return ""; - } - if (!ITypesUtil::Marshal(data, device, table)) { - ZLOGE("write to message parcel failed"); - return ""; - } - - MessageParcel reply; - MessageOption option; - if (Remote()->SendRequest(RDB_SERVICE_CMD_OBTAIN_TABLE, data, reply, option) != 0) { - ZLOGE("send request failed"); - return ""; - } - return reply.ReadString(); -} - -int32_t RdbServiceProxy::InitNotifier(const RdbSyncerParam& param) -{ - notifier_ = new (std::nothrow) RdbNotifierStub( - [this] (uint32_t seqNum, const SyncResult& result) { - OnSyncComplete(seqNum, result); - }, - [this] (const std::string& storeName, const std::vector& devices) { - OnDataChange(storeName, devices); - } - ); - if (notifier_ == nullptr) { - ZLOGE("create notifier failed"); - return RDB_ERROR; - } - - if (InitNotifier(param, notifier_->AsObject().GetRefPtr()) != RDB_OK) { - notifier_ = nullptr; - return RDB_ERROR; - } - - ZLOGI("success"); - return RDB_OK; -} - -int32_t RdbServiceProxy::InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshal(data, param, notifier)) { - ZLOGE("write to message parcel failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption option; - if (Remote()->SendRequest(RDB_SERVICE_CMD_INIT_NOTIFIER, data, reply, option) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - - int32_t res = RDB_ERROR; - return reply.ReadInt32(res) ? res : RDB_ERROR; -} - -uint32_t RdbServiceProxy::GetSeqNum() -{ - return seqNum_++; -} - -int32_t RdbServiceProxy::DoSync(const RdbSyncerParam& param, const SyncOption &option, - const RdbPredicates &predicates, SyncResult& result) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshal(data, param, option, predicates)) { - ZLOGE("write to message parcel failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption opt; - if (Remote()->SendRequest(RDB_SERVICE_CMD_SYNC, data, reply, opt) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - - if (!ITypesUtil::Unmarshal(reply, result)) { - ZLOGE("read result failed"); - return RDB_ERROR; - } - return RDB_OK; -} - -int32_t RdbServiceProxy::DoSync(const RdbSyncerParam& param, const SyncOption &option, - const RdbPredicates &predicates, const SyncCallback& callback) -{ - SyncResult result; - if (DoSync(param, option, predicates, result) != RDB_OK) { - ZLOGI("failed"); - return RDB_ERROR; - } - ZLOGI("success"); - - if (callback != nullptr) { - callback(result); - } - return RDB_OK; -} - -int32_t RdbServiceProxy::DoAsync(const RdbSyncerParam& param, uint32_t seqNum, const SyncOption &option, - const RdbPredicates &predicates) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshal(data, param, seqNum, option, predicates)) { - ZLOGE("write to message parcel failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption opt; - if (Remote()->SendRequest(RDB_SERVICE_CMD_ASYNC, data, reply, opt) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - - int32_t res = RDB_ERROR; - return reply.ReadInt32(res) ? res : RDB_ERROR; -} - -int32_t RdbServiceProxy::DoAsync(const RdbSyncerParam& param, const SyncOption &option, - const RdbPredicates &predicates, const SyncCallback& callback) -{ - uint32_t num = GetSeqNum(); - if (!syncCallbacks_.Insert(num, callback)) { - ZLOGI("insert callback failed"); - return RDB_ERROR; - } - ZLOGI("num=%{public}u", num); - - if (DoAsync(param, num, option, predicates) != RDB_OK) { - ZLOGE("failed"); - syncCallbacks_.Erase(num); - return RDB_ERROR; - } - - ZLOGI("success"); - return RDB_OK; -} - -int32_t RdbServiceProxy::SetDistributedTables(const RdbSyncerParam& param, const std::vector &tables) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshal(data, param, tables)) { - ZLOGE("write to message parcel failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption option; - if (Remote()->SendRequest(RDB_SERVICE_CMD_SET_DIST_TABLE, data, reply, option) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - - int32_t res = RDB_ERROR; - return reply.ReadInt32(res) ? res : RDB_ERROR; -} - -int32_t RdbServiceProxy::Sync(const RdbSyncerParam& param, const SyncOption &option, - const RdbPredicates &predicates, const SyncCallback &callback) -{ - if (option.isBlock) { - return DoSync(param, option, predicates, callback); - } - return DoAsync(param, option, predicates, callback); -} - -std::string RdbServiceProxy::RemoveSuffix(const std::string& name) -{ - std::string suffix(".db"); - auto pos = name.rfind(suffix); - if (pos == std::string::npos || pos < name.length() - suffix.length()) { - return name; - } - return { name, 0, pos }; -} - -int32_t RdbServiceProxy::Subscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, - RdbStoreObserver *observer) -{ - if (option.mode != SubscribeMode::REMOTE) { - ZLOGE("subscribe mode invalid"); - return RDB_ERROR; - } - if (DoSubscribe(param) != RDB_OK) { - ZLOGI("communicate to server failed"); - return RDB_ERROR; - } - auto name = RemoveSuffix(param.storeName_); - observers_.Compute( - name, [observer] (const auto& key, ObserverMapValue& value) { - for (const auto& element : value.first) { - if (element == observer) { - ZLOGE("duplicate observer"); - return true; - } - } - value.first.push_back(observer); - return true; - }); - return RDB_OK; -} - -int32_t RdbServiceProxy::DoSubscribe(const RdbSyncerParam ¶m) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshalling(param, data)) { - ZLOGE("write to message parcel failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption option; - if (Remote()->SendRequest(RDB_SERVICE_CMD_SUBSCRIBE, data, reply, option) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - - int32_t res = RDB_ERROR; - return reply.ReadInt32(res) ? res : RDB_ERROR; -} - -int32_t RdbServiceProxy::UnSubscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, - RdbStoreObserver *observer) -{ - DoUnSubscribe(param); - auto name = RemoveSuffix(param.storeName_); - observers_.ComputeIfPresent( - name, [observer](const auto& key, ObserverMapValue& value) { - ZLOGI("before remove size=%{public}d", static_cast(value.first.size())); - value.first.remove(observer); - ZLOGI("after remove size=%{public}d", static_cast(value.first.size())); - return !(value.first.empty()); - }); - return RDB_OK; -} - -int32_t RdbServiceProxy::DoUnSubscribe(const RdbSyncerParam ¶m) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshalling(param, data)) { - ZLOGE("write to message parcel failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption option; - if (Remote()->SendRequest(RDB_SERVICE_CMD_UNSUBSCRIBE, data, reply, option) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - - int32_t res = RDB_ERROR; - return reply.ReadInt32(res) ? res : RDB_ERROR; -} - -int32_t RdbServiceProxy::RemoteQuery(const RdbSyncerParam& param, const std::string& device, const std::string& sql, - const std::vector& selectionArgs, sptr& resultSet) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshal(data, param, device, sql, selectionArgs)) { - ZLOGE("write to message parcel failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption option; - if (Remote()->SendRequest(RDB_SERVICE_CMD_REMOTE_QUERY, data, reply, option) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - - int32_t status = reply.ReadInt32(); - if (status != RdbStatus::RDB_OK) { - ZLOGE("remote query failed, server side status is %{public}d", status); - return status; - } - - sptr remote = reply.ReadRemoteObject(); - if (remote == nullptr) { - ZLOGE("read remote object is null"); - return RDB_ERROR; - } - resultSet = remote; - return RDB_OK; -} - -RdbServiceProxy::ObserverMap RdbServiceProxy::ExportObservers() -{ - return observers_; -} - -void RdbServiceProxy::ImportObservers(ObserverMap &observers) -{ - ZLOGI("enter"); - SubscribeOption option {SubscribeMode::REMOTE}; - observers.ForEach([this, &option](const std::string& key, const ObserverMapValue& value) { - for (auto& observer : value.first) { - Subscribe(value.second, option, observer); - } - return false; - }); -} -int32_t RdbServiceProxy::CreateRDBTable( - const RdbSyncerParam ¶m, const std::string &writePermission, const std::string &readPermission) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshal(data, param, writePermission, readPermission)) { - ZLOGE("write to message parcel failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption option; - if (Remote()->SendRequest(RDB_SERVICE_CREATE_RDB_TABLE, data, reply, option) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - - int32_t status = reply.ReadInt32(); - if (status != RdbStatus::RDB_OK) { - ZLOGE("remote query failed, server side status is %{public}d", status); - return status; - } - return RDB_OK; -} - -int32_t RdbServiceProxy::DestroyRDBTable(const RdbSyncerParam ¶m) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return RDB_ERROR; - } - if (!ITypesUtil::Marshal(data, param)) { - ZLOGE("write to message parcel failed"); - return RDB_ERROR; - } - - MessageParcel reply; - MessageOption option; - if (Remote()->SendRequest(RDB_SERVICE_DESTROY_RDB_TABLE, data, reply, option) != 0) { - ZLOGE("send request failed"); - return RDB_ERROR; - } - - int32_t status = reply.ReadInt32(); - if (status != RdbStatus::RDB_OK) { - ZLOGE("remote query failed, server side status is %{public}d", status); - return status; - } - return RDB_OK; -} -} // namespace OHOS::DistributedRdb diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.h b/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.h deleted file mode 100644 index f31499107e084c96e793cafef5faafcfe566ee22..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2022 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 DISTRIBUTED_RDB_SERVICE_PROXY_H -#define DISTRIBUTED_RDB_SERVICE_PROXY_H - -#include -#include -#include -#include "irdb_service.h" -#include "rdb_notifier.h" -#include "concurrent_map.h" - -namespace OHOS::DistributedRdb { -class RdbServiceProxy : public IRemoteProxy { -public: - using ObserverMapValue = std::pair, RdbSyncerParam>; - using ObserverMap = ConcurrentMap; - - explicit RdbServiceProxy(const sptr& object); - - std::string ObtainDistributedTableName(const std::string& device, const std::string& table) override; - - int32_t InitNotifier(const RdbSyncerParam& param); - int32_t InitNotifier(const RdbSyncerParam& param, const sptr notifier) override; - - int32_t SetDistributedTables(const RdbSyncerParam& param, const std::vector& tables) override; - - int32_t Sync(const RdbSyncerParam& param, const SyncOption& option, - const RdbPredicates& predicates, const SyncCallback& callback) override; - - int32_t Subscribe(const RdbSyncerParam& param, const SubscribeOption& option, - RdbStoreObserver *observer) override; - - int32_t UnSubscribe(const RdbSyncerParam& param, const SubscribeOption& option, - RdbStoreObserver *observer) override; - int32_t RemoteQuery(const RdbSyncerParam& param, const std::string& device, const std::string& sql, - const std::vector& selectionArgs, sptr& resultSet) override; - - int32_t CreateRDBTable( - const RdbSyncerParam ¶m, const std::string &writePermission, const std::string &readPermission) override; - int32_t DestroyRDBTable(const RdbSyncerParam ¶m) override; - ObserverMap ExportObservers(); - - void ImportObservers(ObserverMap& observers); - -protected: - int32_t DoSync(const RdbSyncerParam& param, const SyncOption& option, - const RdbPredicates& predicates, SyncResult& result) override; - - int32_t DoAsync(const RdbSyncerParam& param, uint32_t seqNum, const SyncOption& option, - const RdbPredicates& predicates) override; - - int32_t DoSubscribe(const RdbSyncerParam& param) override; - - int32_t DoUnSubscribe(const RdbSyncerParam& param) override; - -private: - uint32_t GetSeqNum(); - - int32_t DoSync(const RdbSyncerParam& param, const SyncOption& option, - const RdbPredicates& predicates, const SyncCallback& callback); - - int32_t DoAsync(const RdbSyncerParam& param, const SyncOption& option, - const RdbPredicates& predicates, const SyncCallback& callback); - - void OnSyncComplete(uint32_t seqNum, const SyncResult& result); - - void OnDataChange(const std::string& storeName, const std::vector& devices); - - std::string RemoveSuffix(const std::string& name); - - std::atomic seqNum_ {}; - - ConcurrentMap syncCallbacks_; - ObserverMap observers_; - sptr notifier_; - - static inline BrokerDelegator delegator_; -}; -} // namespace OHOS::DistributedRdb -#endif diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_types_util.cpp b/frameworks/innerkitsimpl/rdb/src/rdb_types_util.cpp deleted file mode 100644 index 1666628e687fd3597177664b5a2c7f503c1e7263..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/rdb/src/rdb_types_util.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2022 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 "rdb_types_util.h" -namespace OHOS::ITypesUtil { -template<> -bool Marshalling(const SyncerParam &input, MessageParcel &data) -{ - return ITypesUtil::Marshal(data, input.bundleName_, input.hapName_, input.storeName_, input.area_, - input.level_, input.type_, input.isAutoSync_, input.isEncrypt_, input.password_); -} -template<> -bool Unmarshalling(SyncerParam &output, MessageParcel &data) -{ - return ITypesUtil::Unmarshal(data, output.bundleName_, output.hapName_, output.storeName_, output.area_, - output.level_, output.type_, output.isAutoSync_, output.isEncrypt_, output.password_); -} - -template<> -bool Marshalling(const SyncOption &input, MessageParcel &data) -{ - return ITypesUtil::Marshal(data, static_cast(input.mode), input.isBlock); -} - -template<> -bool Unmarshalling(SyncOption &output, MessageParcel &data) -{ - int32_t mode = static_cast(output.mode); - auto ret = ITypesUtil::Unmarshal(data, mode, output.isBlock); - output.mode = static_cast(mode); - return ret; -} - -template<> -bool Marshalling(const RdbPredicates &input, MessageParcel &data) -{ - return ITypesUtil::Marshal(data, input.table_, input.devices_, input.operations_); -} -template<> -bool Unmarshalling(RdbPredicates &output, MessageParcel &data) -{ - return ITypesUtil::Unmarshal(data, output.table_, output.devices_, output.operations_); -} - -template<> -bool Marshalling(const RdbOperation &input, MessageParcel &data) -{ - return ITypesUtil::Marshal(data, static_cast(input.operator_), input.field_, input.values_); -} - -template<> -bool Unmarshalling(RdbOperation &output, MessageParcel &data) -{ - int32_t option; - auto ret = ITypesUtil::Unmarshal(data, option, output.field_, output.values_); - output.operator_ = static_cast(option); - return ret; -} -} \ No newline at end of file diff --git a/frameworks/jskitsimpl/distributedkvstore/src/napi_queue.cpp b/frameworks/jskitsimpl/distributedkvstore/src/napi_queue.cpp index d6059434475d41955a2b5b042cc329bd9ad4ff33..45c9c97c8b28564fcbbb8137479147593a0b80a4 100644 --- a/frameworks/jskitsimpl/distributedkvstore/src/napi_queue.cpp +++ b/frameworks/jskitsimpl/distributedkvstore/src/napi_queue.cpp @@ -72,8 +72,6 @@ napi_value NapiQueue::AsyncWork(napi_env env, std::shared_ptr ctxt, NapiAsyncExecute execute, NapiAsyncComplete complete) { ZLOGD("name=%{public}s", name.c_str()); - ctxt->execute = std::move(execute); - ctxt->complete = std::move(complete); napi_value promise = nullptr; if (ctxt->callbackRef == nullptr) { @@ -108,8 +106,10 @@ napi_value NapiQueue::AsyncWork(napi_env env, std::shared_ptr ctxt, GenerateOutput(ctxt); }, reinterpret_cast(ctxt.get()), &ctxt->work); - napi_queue_async_work(ctxt->env, ctxt->work); + ctxt->execute = std::move(execute); + ctxt->complete = std::move(complete); ctxt->hold = ctxt; // save crossing-thread ctxt. + napi_queue_async_work(ctxt->env, ctxt->work); return promise; } @@ -151,6 +151,8 @@ void NapiQueue::GenerateOutput(ContextBase* ctxt) ZLOGD("call callback function"); napi_call_function(ctxt->env, nullptr, callback, RESULT_ALL, result, &callbackResult); } + ctxt->execute = nullptr; + ctxt->complete = nullptr; ctxt->hold.reset(); // release ctxt. } } // namespace OHOS::DistributedKVStore diff --git a/frameworks/libs/distributeddb/BUILD.gn b/frameworks/libs/distributeddb/BUILD.gn index ac93f56b1b312e80bb1b86ee112444dc622a7f1f..5332c33370433711009a82561d0325b1641a612c 100644 --- a/frameworks/libs/distributeddb/BUILD.gn +++ b/frameworks/libs/distributeddb/BUILD.gn @@ -183,6 +183,7 @@ ohos_shared_library("distributeddb") { "storage/src/relationaldb_properties.cpp", "storage/src/result_entries_window.cpp", "storage/src/single_ver_natural_store_commit_notify_data.cpp", + "storage/src/sqlite/cloud_sync_log_table_manager.cpp", "storage/src/sqlite/collaboration_log_table_manager.cpp", "storage/src/sqlite/log_table_manager_factory.cpp", "storage/src/sqlite/query_object.cpp", @@ -200,6 +201,7 @@ ohos_shared_library("distributeddb") { "storage/src/sqlite/sqlite_local_storage_engine.cpp", "storage/src/sqlite/sqlite_local_storage_executor.cpp", "storage/src/sqlite/sqlite_log_table_manager.cpp", + "storage/src/sqlite/sqlite_meta_executor.cpp", "storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", "storage/src/sqlite/sqlite_multi_ver_transaction.cpp", "storage/src/sqlite/sqlite_query_helper.cpp", @@ -222,12 +224,17 @@ ohos_shared_library("distributeddb") { "storage/src/storage_engine.cpp", "storage/src/storage_engine_manager.cpp", "storage/src/storage_executor.cpp", + "storage/src/storage_proxy.cpp", "storage/src/sync_able_engine.cpp", "storage/src/sync_able_kvdb.cpp", "storage/src/sync_able_kvdb_connection.cpp", "storage/src/upgrader/single_ver_database_upgrader.cpp", "storage/src/upgrader/single_ver_schema_database_upgrader.cpp", "syncer/src/ability_sync.cpp", + "syncer/src/cloud/cloud_merge_strategy.cpp", + "syncer/src/cloud/cloud_db_proxy.cpp", + "syncer/src/cloud/cloud_syncer.cpp", + "syncer/src/cloud/strategy_factory.cpp", "syncer/src/commit_history_sync.cpp", "syncer/src/communicator_proxy.cpp", "syncer/src/db_ability.cpp", @@ -280,6 +287,7 @@ ohos_shared_library("distributeddb") { configs += [ "//third_party/jsoncpp:jsoncpp_config" ] ldflags = [ "-Wl,--exclude-libs,ALL" ] + cflags_cc = [ "-fvisibility=hidden" ] deps += [ "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", diff --git a/frameworks/libs/distributeddb/common/include/auto_launch.h b/frameworks/libs/distributeddb/common/include/auto_launch.h index 00075878d7ee04d78c4dad1750e358b6e6ccb0d7..d18731619dd9e6bf53d04e6398dc6abaca46a400 100644 --- a/frameworks/libs/distributeddb/common/include/auto_launch.h +++ b/frameworks/libs/distributeddb/common/include/auto_launch.h @@ -39,7 +39,7 @@ enum class AutoLaunchItemState { IDLE, }; -enum class DBType { +enum class DBTypeInner { DB_KV = 1, DB_RELATION, DB_INVALID, @@ -58,13 +58,13 @@ struct AutoLaunchItem { bool isDisable = false; bool inObserver = false; bool isAutoSync = true; - DBType type = DBType::DB_INVALID; + DBTypeInner type = DBTypeInner::DB_INVALID; StoreObserver *storeObserver = nullptr; }; class AutoLaunch { public: - static int GetAutoLaunchProperties(const AutoLaunchParam ¶m, const DBType &openType, bool checkDir, + static int GetAutoLaunchProperties(const AutoLaunchParam ¶m, const DBTypeInner &openType, bool checkDir, std::shared_ptr &propertiesPtr); AutoLaunch() = default; @@ -83,11 +83,11 @@ public: void GetAutoLaunchSyncDevices(const std::string &identifier, std::vector &devices) const; - void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBType type); + void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBTypeInner type); void Dump(int fd); - void CloseConnection(DBType type, const DBProperties &properties); + void CloseConnection(DBTypeInner type, const DBProperties &properties); protected: static int OpenOneConnection(AutoLaunchItem &autoLaunchItem); @@ -156,7 +156,7 @@ protected: void ExtConnectionLifeCycleCallbackTask(const std::string &identifier, const std::string &userId); - int ExtAutoLaunchRequestCallBack(const std::string &identifier, AutoLaunchParam ¶m, DBType &openType); + int ExtAutoLaunchRequestCallBack(const std::string &identifier, AutoLaunchParam ¶m, DBTypeInner &openType); int RegisterLifeCycleCallback(AutoLaunchItem &autoLaunchItem, const std::string &identifier, bool isExt); @@ -174,6 +174,9 @@ protected: int RegisterRelationalObserver(AutoLaunchItem &autoLaunchItem, const std::string &identifier, bool isExt); + std::string GetAutoLaunchItemUid(const std::string &identifier, const std::string &originalUserId, + bool &handleByCallback); + mutable std::mutex dataLock_; mutable std::mutex communicatorLock_; std::set onlineDevices_; @@ -183,7 +186,7 @@ protected: std::condition_variable cv_; std::mutex extLock_; - std::map autoLaunchRequestCallbackMap_; + std::map autoLaunchRequestCallbackMap_; // key: label, value: std::map> extItemMap_; }; diff --git a/frameworks/libs/distributeddb/common/include/cloud/cloud_db_constant.h b/frameworks/libs/distributeddb/common/include/cloud/cloud_db_constant.h new file mode 100644 index 0000000000000000000000000000000000000000..13bf5dda58b553d587dbadbefdf5b565b859e518 --- /dev/null +++ b/frameworks/libs/distributeddb/common/include/cloud/cloud_db_constant.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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 CLOUD_DB_CONSTANT_H +#define CLOUD_DB_CONSTANT_H + +#include "cloud_store_types.h" +#include + +namespace DistributedDB { +class CloudDbConstant { +public: + static const std::string CLOUD_META_TABLE_PREFIX; + static const std::string GID_FIELD; + static const std::string CREATE_FIELD; + static const std::string MODIFY_FIELD; + static const std::string DELETE_FIELD; + static const std::string CURSOR_FIELD; +}; +} // namespace DistributedDB +#endif // CLOUD_DB_CONSTANT_H diff --git a/frameworks/libs/distributeddb/common/include/cloud/cloud_db_types.h b/frameworks/libs/distributeddb/common/include/cloud/cloud_db_types.h new file mode 100644 index 0000000000000000000000000000000000000000..f56328621cd8f2cb23bac32a436206f2da31f792 --- /dev/null +++ b/frameworks/libs/distributeddb/common/include/cloud/cloud_db_types.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 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 CLOUD_DB_TYPES_H +#define CLOUD_DB_TYPES_H + +#include "cloud_store_types.h" +#include + +namespace DistributedDB { +struct CloudSyncBatch { + std::vector record; + std::vector extend; + std::vector rowid; +}; + +struct CloudSyncData { + std::string tableName; + CloudSyncBatch insData; + CloudSyncBatch updData; + CloudSyncBatch delData; + CloudSyncData() = default; + CloudSyncData(std::string &_tableName) : tableName(_tableName) {}; +}; + +template +struct index_of : std::integral_constant {}; + +template +inline static constexpr size_t index_of_v = index_of::value; + +template +struct index_of + : std::integral_constant ? 0 : index_of_v + 1> {}; + +template +struct variant_size_of { + static constexpr size_t value = sizeof...(Types); +}; + +template +struct variant_index_of { + static constexpr size_t value = index_of_v; +}; + +template +static variant_size_of variant_size_test(const std::variant &); + +template +static variant_index_of variant_index_test(const T &, const std::variant &); + +template +inline constexpr static int32_t TYPE_INDEX = + decltype(variant_index_test(std::declval(), std::declval()))::value; + +inline constexpr static int32_t TYPE_MAX = decltype(variant_size_test(std::declval()))::value; + +} // namespace DistributedDB +#endif // CLOUD_DB_TYPES_H diff --git a/frameworks/libs/distributeddb/common/include/db_common.h b/frameworks/libs/distributeddb/common/include/db_common.h index c43981059ebe737f0813b855f8228775b63971c8..3acf3fe81bd279696cdfc9ece88764df4a687c70 100644 --- a/frameworks/libs/distributeddb/common/include/db_common.h +++ b/frameworks/libs/distributeddb/common/include/db_common.h @@ -31,6 +31,10 @@ public: static void StringToVector(const std::string &src, std::vector &dst); static void VectorToString(const std::vector &src, std::string &dst); + static void Int64ToVector(int64_t val, std::vector &dst); + static void DoubleToVector(double val, std::vector &dst); + static void BoolToVector(bool val, std::vector &dst); + static std::string VectorToHexString(const std::vector &inVec, const std::string &separator = ""); static void PrintHexVector(const std::vector &data, int line = 0, const std::string &tag = ""); @@ -60,6 +64,13 @@ public: static std::string GetDistributedTableName(const std::string &device, const std::string &tableName); + static std::string GetDistributedTableName(const std::string &device, const std::string &tableName, + const StoreInfo &info); + + static std::string GetDistributedTableNameWithHash(const std::string &device, const std::string &tableName); + + static std::string CalDistributedTableName(const std::string &device, const std::string &tableName); + static void GetDeviceFromName(const std::string &deviceTableName, std::string &deviceHash, std::string &tableName); static std::string TrimSpace(const std::string &input); diff --git a/frameworks/libs/distributeddb/common/include/db_constant.h b/frameworks/libs/distributeddb/common/include/db_constant.h index 928a08655105c6315c9eea4c8cce428fb7881f42..ac83b98bce7a1e61a69c32a8a835cabcb6579dbd 100644 --- a/frameworks/libs/distributeddb/common/include/db_constant.h +++ b/frameworks/libs/distributeddb/common/include/db_constant.h @@ -148,6 +148,7 @@ public: static const std::string LOG_TABLE_VERSION_1; static const std::string LOG_TABLE_VERSION_2; + const char *LOG_TABLE_VERSION_3 = "3.0"; static const std::string LOG_TABLE_VERSION_CURRENT; static const std::string LOG_TABLE_VERSION_KEY; @@ -159,6 +160,8 @@ public: static constexpr uint32_t MAX_CONDITION_COUNT = 32; static constexpr uint32_t REMOTE_QUERY_MAX_SQL_LEN = 1000000U; + + static constexpr int HASH_KEY_SIZE = 32; // size of SHA256_DIGEST_LENGTH }; } // namespace DistributedDB #endif // DISTRIBUTEDDB_CONSTANT_H diff --git a/frameworks/libs/distributeddb/common/include/db_errno.h b/frameworks/libs/distributeddb/common/include/db_errno.h index 13a1098cc42bb0be2f621e2ca2ea7c388aa3a787..0ef5f08881dc8acc421dfb740feeadac0541434d 100644 --- a/frameworks/libs/distributeddb/common/include/db_errno.h +++ b/frameworks/libs/distributeddb/common/include/db_errno.h @@ -125,6 +125,11 @@ constexpr int E_NONEXISTENT = (E_BASE + 103); // for result set, nonexistent in constexpr int E_TYPE_MISMATCH = (E_BASE + 104); // for result set, mismatch type constexpr int E_DENIED_SQL = (E_BASE + 105); // denied sql, not permit to execute constexpr int E_USER_CHANGE = (E_BASE + 106); // user change +constexpr int E_CONSTRAINT = (E_BASE + 107); // sql failed with constraint +constexpr int E_CLOUD_ERROR = (E_BASE + 108); // cloud error +constexpr int E_CLOUD_UPLOAD_FAILED = (E_BASE + 109); // upload failed +constexpr int E_INVALID_CLOUD_SYNC_DATA = (E_BASE + 110); // invalid cloud sync data +constexpr int E_REACH_END = (E_BASE + 111); // Indicates that query function has queried last data from cloud // Num 150+ is reserved for schema related errno, since it may be added regularly constexpr int E_JSON_PARSE_FAIL = (E_BASE + 150); // Parse json fail in grammatical level constexpr int E_JSON_INSERT_PATH_EXIST = (E_BASE + 151); // Path already exist before insert @@ -136,6 +141,7 @@ constexpr int E_SCHEMA_UNEQUAL_COMPATIBLE = (E_BASE + 162); // New schema contai constexpr int E_SCHEMA_UNEQUAL_COMPATIBLE_UPGRADE = (E_BASE + 163); // New schema contain more field(index may differ) constexpr int E_SCHEMA_UNEQUAL_INCOMPATIBLE = (E_BASE + 164); // New schema contain more field or index constexpr int E_SCHEMA_VIOLATE_VALUE = (E_BASE + 165); // New schema violate values already exist in dbFile +constexpr int E_SCHEMA_NOT_SET = (E_BASE + 166); // cloud schema has not been set constexpr int E_FLATBUFFER_VERIFY_FAIL = (E_BASE + 170); // Verify flatbuffer content(schema or value) fail. constexpr int E_VALUE_MATCH = (E_BASE + 180); // Value match schema(strict or compatible) without amend constexpr int E_VALUE_MATCH_AMENDED = (E_BASE + 181); // Value match schema(strict or compatible) with amend diff --git a/frameworks/libs/distributeddb/common/include/db_types.h b/frameworks/libs/distributeddb/common/include/db_types.h index 6b836a6fccc7b92afc9385a7033405a53740fe0e..d11ce7412aa920a667b64bcbc76d82b1cafb2e66 100644 --- a/frameworks/libs/distributeddb/common/include/db_types.h +++ b/frameworks/libs/distributeddb/common/include/db_types.h @@ -26,7 +26,10 @@ #include "types_export.h" namespace DistributedDB { +using TableName = std::string; using Timestamp = uint64_t; +using LocalWaterMark = Timestamp; +using CloudWaterMark = std::string; using ContinueToken = void *; using DeviceID = std::string; using TimeOffset = int64_t; @@ -116,6 +119,7 @@ using RawString = const std::string::value_type *; enum class OperatePerm { NORMAL_PERM, + NORMAL_WRITE, REKEY_MONOPOLIZE_PERM, IMPORT_MONOPOLIZE_PERM, DISABLE_PERM, diff --git a/frameworks/libs/distributeddb/common/include/relational/relational_schema_object.h b/frameworks/libs/distributeddb/common/include/relational/relational_schema_object.h index 13741f13fc7f77958010619535e0f88a504ab176..2f6e3965cdc3edebc7fa9e321c80a6c54e9c1f19 100644 --- a/frameworks/libs/distributeddb/common/include/relational/relational_schema_object.h +++ b/frameworks/libs/distributeddb/common/include/relational/relational_schema_object.h @@ -70,6 +70,7 @@ private: int ParseCheckTableDefine(const JsonObject &inJsonObject, TableInfo &resultTable); int ParseCheckTableFieldInfo(const JsonObject &inJsonObject, const FieldPath &path, FieldInfo &table); int ParseCheckTableAutoInc(const JsonObject &inJsonObject, TableInfo &resultTable); + int ParseCheckTableSyncType(const JsonObject &inJsonObject, TableInfo &resultTable); int ParseCheckTableIndex(const JsonObject &inJsonObject, TableInfo &resultTable); int ParseCheckTableUnique(const JsonObject &inJsonObject, TableInfo &resultTable); int ParseCheckTablePrimaryKey(const JsonObject &inJsonObject, TableInfo &resultTable); diff --git a/frameworks/libs/distributeddb/common/include/relational/table_info.h b/frameworks/libs/distributeddb/common/include/relational/table_info.h index d664b4712faab7af79f360be4753370e4dd792a2..2415976f8f3c8c324a14c39da4449686611a6bde 100644 --- a/frameworks/libs/distributeddb/common/include/relational/table_info.h +++ b/frameworks/libs/distributeddb/common/include/relational/table_info.h @@ -19,6 +19,7 @@ #include #include +#include "cloud_store_types.h" #include "db_types.h" #include "schema_constant.h" #include "data_value.h" @@ -68,6 +69,7 @@ class TableInfo { public: const std::string &GetTableName() const; bool GetAutoIncrement() const; + TableSyncType GetTableSyncType() const; const std::string &GetCreateTableSql() const; const FieldInfoMap &GetFields() const; // const IndexInfoMap &GetIndexDefine() const; @@ -76,6 +78,7 @@ public: void SetTableName(const std::string &tableName); void SetAutoIncrement(bool autoInc); + void SetTableSyncType(TableSyncType tableSyncType); void SetCreateTableSql(const std::string &sql); // set 'autoInc_' flag when set sql void AddField(const FieldInfo &field); void AddIndexDefine(const std::string &indexName, const CompositeFields &indexDefine); @@ -120,6 +123,7 @@ private: std::string tableName_; bool autoInc_ = false; // only 'INTEGER PRIMARY KEY' could be defined as 'AUTOINCREMENT' + TableSyncType tableSyncType_ = DEVICE_COOPERATION; std::string sql_; FieldInfoMap fields_; std::map primaryKey_; diff --git a/frameworks/libs/distributeddb/common/include/runtime_context.h b/frameworks/libs/distributeddb/common/include/runtime_context.h index 856c5b31d8a09a284f806dc1356d8dbf79adb08d..36e0bb65909e9b33ad36684f928989830c8c679b 100644 --- a/frameworks/libs/distributeddb/common/include/runtime_context.h +++ b/frameworks/libs/distributeddb/common/include/runtime_context.h @@ -22,8 +22,10 @@ #include "auto_launch.h" #include "auto_launch_export.h" +#include "icloud_data_translate.h" #include "icommunicator_aggregator.h" #include "iprocess_system_api_adapter.h" +#include "ithread_pool.h" #include "kv_store_observer.h" #include "kvdb_properties.h" #include "macro_utils.h" @@ -36,6 +38,7 @@ using TimerAction = std::function; using TimerFinalizer = std::function; using TaskAction = std::function; using TimeChangedAction = std::function; +using TimeFinalizeAction = std::function; using LockStatusNotifier = std::function; using UserChangedAction = std::function; @@ -69,7 +72,8 @@ public: virtual void ShrinkMemory(const std::string &description) = 0; // Register a time changed lister, it will be callback when local time changed. - virtual NotificationChain::Listener *RegisterTimeChangedLister(const TimeChangedAction &action, int &errCode) = 0; + virtual NotificationChain::Listener *RegisterTimeChangedLister(const TimeChangedAction &action, + const TimeFinalizeAction &finalize, int &errCode) = 0; // Get the global context object(singleton), never return nullptr. static RuntimeContext *GetInstance(); @@ -90,7 +94,7 @@ public: virtual void GetAutoLaunchSyncDevices(const std::string &identifier, std::vector &devices) const = 0; - virtual void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBType type) = 0; + virtual void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBTypeInner type) = 0; virtual NotificationChain::Listener *RegisterLockStatusLister(const LockStatusNotifier &action, int &errCode) = 0; @@ -132,7 +136,7 @@ public: virtual void DumpCommonInfo(int fd) = 0; - virtual void CloseAutoLaunchConnection(DBType type, const DBProperties &properties) = 0; + virtual void CloseAutoLaunchConnection(DBTypeInner type, const DBProperties &properties) = 0; virtual int SetPermissionConditionCallback(const PermissionConditionCallback &callback) = 0; @@ -141,6 +145,23 @@ public: virtual void StopTaskPool() = 0; virtual void StopTimeTickMonitorIfNeed() = 0; + + virtual void SetTranslateToDeviceIdCallback(const TranslateToDeviceIdCallback &callback) = 0; + + virtual int TranslateDeviceId(const std::string &deviceId, + const StoreInfo &info, std::string &newDeviceId) = 0; + + virtual bool ExistTranslateDevIdCallback() const = 0; + + virtual void SetThreadPool(const std::shared_ptr &threadPool) = 0; + + virtual std::shared_ptr GetThreadPool() const = 0; + + virtual void SetCloudTranslate(const std::shared_ptr &dataTranslate) = 0; + virtual int AssetToBlob(const Asset &asset, std::vector &blob) = 0; + virtual int AssetsToBlob(const Assets &assets, std::vector &blob) = 0; + virtual int BlobToAsset(const std::vector &blob, Asset &asset) = 0; + virtual int BlobToAssets(std::vector &blob, Assets &assets) = 0; protected: RuntimeContext() = default; virtual ~RuntimeContext() {} diff --git a/frameworks/libs/distributeddb/common/src/auto_launch.cpp b/frameworks/libs/distributeddb/common/src/auto_launch.cpp index da7c4e6fb58261575c907578094221d979154200..c16f8ea16e5ca527e051de2766928321d141792e 100644 --- a/frameworks/libs/distributeddb/common/src/auto_launch.cpp +++ b/frameworks/libs/distributeddb/common/src/auto_launch.cpp @@ -167,7 +167,7 @@ int AutoLaunch::EnableKvStoreAutoLaunch(const KvDBProperties &properties, AutoLa std::shared_ptr ptr = std::make_shared(properties); AutoLaunchItem autoLaunchItem { ptr, notifier, option.observer, option.conflictType, option.notifier }; autoLaunchItem.isAutoSync = option.isAutoSync; - autoLaunchItem.type = DBType::DB_KV; + autoLaunchItem.type = DBTypeInner::DB_KV; int errCode = EnableKvStoreAutoLaunchParmCheck(autoLaunchItem, identifier, dualTupleIdentifier, isDualTupleMode); if (errCode != E_OK) { LOGE("[AutoLaunch] EnableKvStoreAutoLaunch failed errCode:%d", errCode); @@ -272,10 +272,10 @@ void AutoLaunch::TryCloseConnection(AutoLaunchItem &autoLaunchItem) { LOGI("[AutoLaunch] TryCloseConnection"); switch (autoLaunchItem.type) { - case DBType::DB_KV: + case DBTypeInner::DB_KV: TryCloseKvConnection(autoLaunchItem); break; - case DBType::DB_RELATION: + case DBTypeInner::DB_RELATION: TryCloseRelationConnection(autoLaunchItem); break; default: @@ -317,9 +317,9 @@ int AutoLaunch::RegisterObserver(AutoLaunchItem &autoLaunchItem, const std::stri } LOGI("[AutoLaunch] RegisterObserver type=%d", static_cast(autoLaunchItem.type)); switch (autoLaunchItem.type) { - case DBType::DB_RELATION: + case DBTypeInner::DB_RELATION: return RegisterRelationalObserver(autoLaunchItem, identifier, isExt); - case DBType::DB_KV: + case DBTypeInner::DB_KV: return RegisterKvObserver(autoLaunchItem, identifier, isExt); default: return -E_INVALID_ARGS; @@ -512,10 +512,10 @@ int AutoLaunch::OpenOneConnection(AutoLaunchItem &autoLaunchItem) LOGI("[AutoLaunch] GetOneConnection"); int errCode; switch (autoLaunchItem.type) { - case DBType::DB_KV: + case DBTypeInner::DB_KV: errCode = OpenKvConnection(autoLaunchItem); break; - case DBType::DB_RELATION: + case DBTypeInner::DB_RELATION: errCode = OpenRelationalConnection(autoLaunchItem); break; default: @@ -690,21 +690,12 @@ void AutoLaunch::ReceiveUnknownIdentifierCallBackTask(const std::string &identif int AutoLaunch::ReceiveUnknownIdentifierCallBack(const LabelType &label, const std::string &originalUserId) { const std::string identifier(label.begin(), label.end()); + LOGI("[AutoLaunch] ReceiveUnknownIdentifierCallBack identifier=%.6s", STR_TO_HEX(identifier)); // originalUserId size maybe 0 - std::string userId = originalUserId; - { - std::lock_guard autoLock(dataLock_); - if (originalUserId.size() == 0 && autoLaunchItemMap_.count(identifier) != 0 && - autoLaunchItemMap_[identifier].size() > 1) { - LOGE("[AutoLaunch] normal tuple mode userId larger than one userId"); - goto EXT; - } - if (originalUserId.size() == 0 && autoLaunchItemMap_.count(identifier) != 0 && - autoLaunchItemMap_[identifier].size() == 1) { - // normal tuple mode - userId = autoLaunchItemMap_[identifier].begin()->first; - } - LOGI("[AutoLaunch] ReceiveUnknownIdentifierCallBack identifier=%.6s", STR_TO_HEX(identifier)); + bool handleByCallback = false; + std::string userId = GetAutoLaunchItemUid(identifier, originalUserId, handleByCallback); + if (handleByCallback) { + goto EXT; } int errCode; { @@ -739,7 +730,7 @@ EXT: return AutoLaunchExt(identifier, userId); } -void AutoLaunch::SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBType type) +void AutoLaunch::SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBTypeInner type) { LOGI("[AutoLaunch] SetAutoLaunchRequestCallback type[%d]", static_cast(type)); std::lock_guard lock(extLock_); @@ -755,7 +746,7 @@ int AutoLaunch::AutoLaunchExt(const std::string &identifier, const std::string & AutoLaunchParam param; // for non dual tuple mode, userId is "" param.userId = userId; - DBType openType = DBType::DB_INVALID; + DBTypeInner openType = DBTypeInner::DB_INVALID; int errCode = ExtAutoLaunchRequestCallBack(identifier, param, openType); if (errCode != E_OK) { return errCode; // not E_OK is ok for communicator @@ -829,8 +820,7 @@ void AutoLaunch::AutoLaunchExtTask(const std::string &identifier, const std::str return; } std::lock_guard autoLock(extLock_); - extItemMap_[identifier][userId].conn = autoLaunchItem.conn; - extItemMap_[identifier][userId].observerHandle = autoLaunchItem.observerHandle; + extItemMap_[identifier][userId] = autoLaunchItem; // Reassign item to prevent it from being erased extItemMap_[identifier][userId].isWriteOpenNotified = false; LOGI("[AutoLaunch] AutoLaunchExtTask ok"); } @@ -913,7 +903,7 @@ void AutoLaunch::ExtConnectionLifeCycleCallbackTask(const std::string &identifie int AutoLaunch::SetConflictNotifier(AutoLaunchItem &autoLaunchItem) { - if (autoLaunchItem.type != DBType::DB_KV) { + if (autoLaunchItem.type != DBTypeInner::DB_KV) { LOGD("[AutoLaunch] Current Type[%d] Not Support ConflictNotifier Now", static_cast(autoLaunchItem.type)); return E_OK; } @@ -958,24 +948,30 @@ END: return errCode; } -int AutoLaunch::GetAutoLaunchProperties(const AutoLaunchParam ¶m, const DBType &openType, bool checkDir, +int AutoLaunch::GetAutoLaunchProperties(const AutoLaunchParam ¶m, const DBTypeInner &openType, bool checkDir, std::shared_ptr &propertiesPtr) { + int errCode = E_OK; switch (openType) { - case DBType::DB_KV: { + case DBTypeInner::DB_KV: { propertiesPtr = std::make_shared(); std::shared_ptr kvPtr = std::static_pointer_cast(propertiesPtr); - return GetAutoLaunchKVProperties(param, kvPtr, checkDir); + errCode = GetAutoLaunchKVProperties(param, kvPtr, checkDir); + break; } - case DBType::DB_RELATION: { + case DBTypeInner::DB_RELATION: { propertiesPtr = std::make_shared(); std::shared_ptr rdbPtr = std::static_pointer_cast(propertiesPtr); - return GetAutoLaunchRelationProperties(param, rdbPtr); + errCode = GetAutoLaunchRelationProperties(param, rdbPtr); + break; } default: return -E_INVALID_ARGS; } + propertiesPtr->SetIntProp(DBProperties::AUTO_LAUNCH_ID, + static_cast(RuntimeContext::GetInstance()->GenerateSessionId())); + return errCode; } int AutoLaunch::GetAutoLaunchKVProperties(const AutoLaunchParam ¶m, @@ -1032,7 +1028,7 @@ int AutoLaunch::GetAutoLaunchRelationProperties(const AutoLaunchParam ¶m, return E_OK; } -int AutoLaunch::ExtAutoLaunchRequestCallBack(const std::string &identifier, AutoLaunchParam ¶m, DBType &openType) +int AutoLaunch::ExtAutoLaunchRequestCallBack(const std::string &identifier, AutoLaunchParam ¶m, DBTypeInner &openType) { std::lock_guard lock(extLock_); if (autoLaunchRequestCallbackMap_.empty()) { @@ -1054,7 +1050,7 @@ int AutoLaunch::ExtAutoLaunchRequestCallBack(const std::string &identifier, Auto return -E_NOT_FOUND; // not E_OK is ok for communicator } // inner error happened - if (openType >= DBType::DB_INVALID) { + if (openType >= DBTypeInner::DB_INVALID) { LOGW("[AutoLaunch] Unknown DB Type, Ignore the open request"); return -E_NOT_FOUND; // not E_OK is ok for communicator } @@ -1104,10 +1100,10 @@ int AutoLaunch::RegisterLifeCycleCallback(AutoLaunchItem &autoLaunchItem, const this, std::placeholders::_1, std::placeholders::_2); } switch (autoLaunchItem.type) { - case DBType::DB_KV: + case DBTypeInner::DB_KV: errCode = static_cast(autoLaunchItem.conn)->RegisterLifeCycleCallback(notifier); break; - case DBType::DB_RELATION: + case DBTypeInner::DB_RELATION: errCode = static_cast(autoLaunchItem.conn)->RegisterLifeCycleCallback(notifier); break; @@ -1121,7 +1117,7 @@ int AutoLaunch::RegisterLifeCycleCallback(AutoLaunchItem &autoLaunchItem, const int AutoLaunch::PragmaAutoSync(AutoLaunchItem &autoLaunchItem) { int errCode = E_OK; - if (autoLaunchItem.type != DBType::DB_KV) { + if (autoLaunchItem.type != DBTypeInner::DB_KV) { LOGD("[AutoLaunch] Current Type[%d] Not Support AutoSync Now", static_cast(autoLaunchItem.type)); return errCode; } @@ -1290,26 +1286,80 @@ int AutoLaunch::RegisterRelationalObserver(AutoLaunchItem &autoLaunchItem, const return E_OK; } -void AutoLaunch::CloseConnection(DBType type, const DBProperties &properties) +void AutoLaunch::CloseConnection(DBTypeInner type, const DBProperties &properties) { - if (type != DBType::DB_RELATION) { - return; - } std::string identifier = properties.GetStringProp(DBProperties::IDENTIFIER_DATA, ""); - std::lock_guard lock(dataLock_); + int closeId = properties.GetIntProp(DBProperties::AUTO_LAUNCH_ID, 0); + std::lock_guard lock(extLock_); auto itemMapIter = extItemMap_.find(identifier); if (itemMapIter == extItemMap_.end()) { - return; + std::string dualIdentifier = properties.GetStringProp(DBProperties::DUAL_TUPLE_IDENTIFIER_DATA, ""); + itemMapIter = extItemMap_.find(dualIdentifier); // Try find conn in dual tuple mode + if (itemMapIter == extItemMap_.end()) { + LOGD("[AutoLaunch] Abort close because not found id"); + return; + } } std::string userId = properties.GetStringProp(DBProperties::USER_ID, ""); auto itemIter = itemMapIter->second.find(userId); if (itemIter == itemMapIter->second.end()) { + LOGD("[AutoLaunch] Abort close because not found user id"); return; } + if (itemIter->second.propertiesPtr == nullptr) { + LOGD("[AutoLaunch] Abort close because properties is invalid"); + return; + } + int targetId = itemIter->second.propertiesPtr->GetIntProp(DBProperties::AUTO_LAUNCH_ID, 0); + if (closeId != 0 && closeId != targetId) { + LOGD("[AutoLaunch] Abort close because connection has been closed"); + return; + } + if (itemIter->second.type != type) { + LOGE("[AutoLaunch] Not same DB type for close connection"); + return; + } + LOGI("[AutoLaunch] Force close connection"); TryCloseConnection(itemIter->second); + if (itemIter->second.isWriteOpenNotified) { + CloseNotifier(itemIter->second); + } + LOGI("[AutoLaunch] Force close connection finished"); extItemMap_[identifier].erase(userId); if (extItemMap_[identifier].size() == 0) { extItemMap_.erase(identifier); } } + +std::string AutoLaunch::GetAutoLaunchItemUid(const std::string &identifier, const std::string &originalUserId, + bool &handleByCallback) +{ + std::string userId = originalUserId; + std::lock_guard autoLock(dataLock_); + if (autoLaunchItemMap_.find(identifier) == autoLaunchItemMap_.end()) { + LOGE("[AutoLaunch] miss match in white list"); + handleByCallback = true; + return userId; + } + if (originalUserId.empty() && autoLaunchItemMap_[identifier].size() > 1) { + LOGE("[AutoLaunch] normal tuple mode userId larger than one userId"); + handleByCallback = true; + return userId; + } + if (originalUserId.empty() && autoLaunchItemMap_[identifier].size() == 1) { + // normal tuple mode + userId = autoLaunchItemMap_[identifier].begin()->first; + return userId; + } + for (const auto &[uid, item]: autoLaunchItemMap_[identifier]) { + if (item.propertiesPtr == nullptr) { + continue; + } + if (!item.propertiesPtr->GetBoolProp(DBProperties::SYNC_DUAL_TUPLE_MODE, false)) { + userId = uid; + break; + } + } + return userId; +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/common/src/cloud/cloud_db_constant.cpp b/frameworks/libs/distributeddb/common/src/cloud/cloud_db_constant.cpp new file mode 100644 index 0000000000000000000000000000000000000000..203659a003e6286dd379042449344c0378cc4c1d --- /dev/null +++ b/frameworks/libs/distributeddb/common/src/cloud/cloud_db_constant.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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 "cloud/cloud_db_constant.h" + +namespace DistributedDB { + const std::string CloudDbConstant::CLOUD_META_TABLE_PREFIX = "naturalbase_cloud_meta_"; + const std::string CloudDbConstant::GID_FIELD = "GID_FIELD"; + const std::string CloudDbConstant::CREATE_FIELD = "CREATE_FIELD"; + const std::string CloudDbConstant::MODIFY_FIELD = "MODIFY_FIELD"; + const std::string CloudDbConstant::DELETE_FIELD = "DELETE_FIELD"; + const std::string CloudDbConstant::CURSOR_FIELD = "DELETE_FIELD"; +} diff --git a/frameworks/libs/distributeddb/common/src/db_common.cpp b/frameworks/libs/distributeddb/common/src/db_common.cpp index 74bf012ffaf9064336b1b15c1bf5cd472689ffbf..11569f8dbf75870d1ac026010fb44ad9cd3f38c6 100644 --- a/frameworks/libs/distributeddb/common/src/db_common.cpp +++ b/frameworks/libs/distributeddb/common/src/db_common.cpp @@ -21,6 +21,7 @@ #include "db_errno.h" #include "platform_specific.h" #include "hash.h" +#include "runtime_context.h" #include "value_hash_calc.h" namespace DistributedDB { @@ -78,6 +79,25 @@ void DBCommon::VectorToString(const std::vector &src, std::string &dst) dst.assign(src.begin(), src.end()); } +void DBCommon::Int64ToVector(int64_t val, std::vector &dst) +{ + dst.resize(sizeof(int64_t)); + memcpy_s(dst.data(), sizeof(int64_t), &val, sizeof(uint64_t)); +} + +void DBCommon::DoubleToVector(double val, std::vector &dst) +{ + dst.resize(sizeof(double)); + memcpy_s(dst.data(), sizeof(double), &val, sizeof(double)); +} + +void DBCommon::BoolToVector(bool val, std::vector &dst) +{ + dst.resize(sizeof(int)); + int intVal = val ? 1 : 0; + memcpy_s(dst.data(), sizeof(int), &intVal, sizeof(int)); +} + std::string DBCommon::VectorToHexString(const std::vector &inVec, const std::string &separator) { std::string outString; @@ -321,9 +341,32 @@ std::string DBCommon::StringMasking(const std::string &oriStr, size_t remain) } std::string DBCommon::GetDistributedTableName(const std::string &device, const std::string &tableName) +{ + if (!RuntimeContext::GetInstance()->ExistTranslateDevIdCallback()) { + return GetDistributedTableNameWithHash(device, tableName); + } + return CalDistributedTableName(device, tableName); +} + +std::string DBCommon::GetDistributedTableName(const std::string &device, const std::string &tableName, + const StoreInfo &info) +{ + std::string newDeviceId; + if (RuntimeContext::GetInstance()->TranslateDeviceId(device, info, newDeviceId) != E_OK) { + return GetDistributedTableNameWithHash(device, tableName); + } + return CalDistributedTableName(newDeviceId, tableName); +} + +std::string DBCommon::GetDistributedTableNameWithHash(const std::string &device, const std::string &tableName) { std::string deviceHashHex = DBCommon::TransferStringToHex(DBCommon::TransferHashString(device)); - return DBConstant::RELATIONAL_PREFIX + tableName + "_" + deviceHashHex; + return CalDistributedTableName(deviceHashHex, tableName); +} + +std::string DBCommon::CalDistributedTableName(const std::string &device, const std::string &tableName) +{ + return DBConstant::RELATIONAL_PREFIX + tableName + "_" + device; } void DBCommon::GetDeviceFromName(const std::string &deviceTableName, std::string &deviceHash, std::string &tableName) diff --git a/frameworks/libs/distributeddb/common/src/db_constant.cpp b/frameworks/libs/distributeddb/common/src/db_constant.cpp index abba6423e347643728c3a93339acdfd9063c0be2..e19c66836c14b88f83a6ed557d323b19a446a619 100644 --- a/frameworks/libs/distributeddb/common/src/db_constant.cpp +++ b/frameworks/libs/distributeddb/common/src/db_constant.cpp @@ -71,7 +71,7 @@ const std::string DBConstant::TIMESTAMP_ALIAS = "naturalbase_rdb_aux_timestamp"; const std::string DBConstant::LOG_TABLE_VERSION_1 = "1.0"; const std::string DBConstant::LOG_TABLE_VERSION_2 = "2.0"; -const std::string DBConstant::LOG_TABLE_VERSION_CURRENT = "2.0"; +const std::string DBConstant::LOG_TABLE_VERSION_CURRENT = "3.0"; const std::string DBConstant::LOG_TABLE_VERSION_KEY = "log_table_version"; diff --git a/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp b/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp index 18462ad6c0b278cd86303ba575588dd9b0f61d55..075be5bf7a0898d74b586505f6719b6e6a0c38d0 100644 --- a/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp +++ b/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp @@ -335,6 +335,11 @@ int RelationalSchemaObject::ParseCheckTableInfo(const JsonObject &inJsonObject) if (errCode != E_OK) { return errCode; } + + errCode = ParseCheckTableSyncType(inJsonObject, resultTable); + if (errCode != E_OK) { + return errCode; + } errCode = ParseCheckTableIndex(inJsonObject, resultTable); if (errCode != E_OK) { return errCode; @@ -479,6 +484,19 @@ int RelationalSchemaObject::ParseCheckTablePrimaryKey(const JsonObject &inJsonOb return errCode; } +int RelationalSchemaObject::ParseCheckTableSyncType(const JsonObject &inJsonObject, TableInfo &resultTable) +{ + FieldValue fieldValue; + int errCode = GetMemberFromJsonObject(inJsonObject, "TABLE_SYNC_TYPE", FieldType::LEAF_FIELD_INTEGER, + false, fieldValue); + if (errCode == E_OK) { + resultTable.SetTableSyncType(static_cast(fieldValue.integerValue)); + } else if (errCode != -E_NOT_FOUND) { + return errCode; + } + return E_OK; // if there is no "TABLE_SYNC_TYPE" filed, the table_sync_type is DEVICE_COOPERATION +} + int RelationalSchemaObject::ParseCheckTableIndex(const JsonObject &inJsonObject, TableInfo &resultTable) { if (!inJsonObject.IsFieldPathExist(FieldPath {"INDEX"})) { // INDEX is not necessary diff --git a/frameworks/libs/distributeddb/common/src/relational/table_info.cpp b/frameworks/libs/distributeddb/common/src/relational/table_info.cpp index 797d8b457aba7176d8c0839d821852be81c58549..b43a3ca768cdc05b44769162332ac69c6d20ef04 100644 --- a/frameworks/libs/distributeddb/common/src/relational/table_info.cpp +++ b/frameworks/libs/distributeddb/common/src/relational/table_info.cpp @@ -206,6 +206,16 @@ bool TableInfo::GetAutoIncrement() const return autoInc_; } +void TableInfo::SetTableSyncType(TableSyncType tableSyncType) +{ + tableSyncType_ = tableSyncType; +} + +TableSyncType TableInfo::GetTableSyncType() const +{ + return tableSyncType_; +} + const std::string &TableInfo::GetCreateTableSql() const { return sql_; @@ -634,6 +644,7 @@ std::string TableInfo::ToTableInfoString(const std::string &schemaVersion) const attrStr += R"("PRIMARY_KEY": [)" + primaryKey + "]"; } } + attrStr += R"(,"TABLE_SYNC_TYPE": )" + std::to_string(static_cast(tableSyncType_)); AddIndexDefineString(attrStr); attrStr += "}"; return attrStr; diff --git a/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp b/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp index 9fe505aa41dd5af6ae16ea68e7ec21f56e917241..3400b3d27f27e234f8bfc7f70073b0921bb2a233 100644 --- a/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp +++ b/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp @@ -14,6 +14,7 @@ */ #include "runtime_context_impl.h" +#include "db_common.h" #include "db_errno.h" #include "db_dfx_adapter.h" #include "log_print.h" @@ -58,6 +59,7 @@ RuntimeContextImpl::~RuntimeContextImpl() delete lockStatusObserver_; lockStatusObserver_ = nullptr; userChangeMonitor_ = nullptr; + SetThreadPool(nullptr); } // Set the label of this process. @@ -150,9 +152,12 @@ int RuntimeContextImpl::SetTimer(int milliSeconds, const TimerAction &action, if ((milliSeconds < 0) || !action) { return -E_INVALID_ARGS; } - + int errCode = SetTimerByThreadPool(milliSeconds, action, finalizer, true, timerId); + if (errCode != -E_NOT_SUPPORT) { + return errCode; + } IEventLoop *loop = nullptr; - int errCode = PrepareLoop(loop); + errCode = PrepareLoop(loop); if (errCode != E_OK) { LOGE("SetTimer(), prepare loop failed."); return errCode; @@ -201,7 +206,10 @@ int RuntimeContextImpl::ModifyTimer(TimerId timerId, int milliSeconds) if (milliSeconds < 0) { return -E_INVALID_ARGS; } - + int errCode = ModifyTimerByThreadPool(timerId, milliSeconds); + if (errCode != -E_NOT_SUPPORT) { + return errCode; + } std::lock_guard autoLock(timersLock_); auto iter = timers_.find(timerId); if (iter == timers_.end()) { @@ -218,6 +226,7 @@ int RuntimeContextImpl::ModifyTimer(TimerId timerId, int milliSeconds) // Remove the timer. void RuntimeContextImpl::RemoveTimer(TimerId timerId, bool wait) { + RemoveTimerByThreadPool(timerId, wait); IEvent *evTimer = nullptr; { std::lock_guard autoLock(timersLock_); @@ -239,6 +248,9 @@ void RuntimeContextImpl::RemoveTimer(TimerId timerId, bool wait) // Task interfaces. int RuntimeContextImpl::ScheduleTask(const TaskAction &task) { + if (ScheduleTaskByThreadPool(task) == E_OK) { + return E_OK; + } std::lock_guard autoLock(taskLock_); int errCode = PrepareTaskPool(); if (errCode != E_OK) { @@ -251,6 +263,9 @@ int RuntimeContextImpl::ScheduleTask(const TaskAction &task) int RuntimeContextImpl::ScheduleQueuedTask(const std::string &queueTag, const TaskAction &task) { + if (ScheduleTaskByThreadPool(task) == E_OK) { + return E_OK; + } std::lock_guard autoLock(taskLock_); int errCode = PrepareTaskPool(); if (errCode != E_OK) { @@ -269,7 +284,7 @@ void RuntimeContextImpl::ShrinkMemory(const std::string &description) } NotificationChain::Listener *RuntimeContextImpl::RegisterTimeChangedLister(const TimeChangedAction &action, - int &errCode) + const TimeFinalizeAction &finalize, int &errCode) { std::lock_guard autoLock(timeTickMonitorLock_); if (timeTickMonitor_ == nullptr) { @@ -282,7 +297,7 @@ NotificationChain::Listener *RuntimeContextImpl::RegisterTimeChangedLister(const } LOGD("[RuntimeContext] TimeTickMonitor start success"); } - return timeTickMonitor_->RegisterTimeChangedLister(action, errCode); + return timeTickMonitor_->RegisterTimeChangedLister(action, finalize, errCode); } int RuntimeContextImpl::PrepareLoop(IEventLoop *&loop) @@ -336,10 +351,6 @@ int RuntimeContextImpl::PrepareTaskPool() int RuntimeContextImpl::AllocTimerId(IEvent *evTimer, TimerId &timerId) { - if (evTimer == nullptr) { - return -E_INVALID_ARGS; - } - std::lock_guard autoLock(timersLock_); TimerId startId = currentTimerId_; while (++currentTimerId_ != startId) { @@ -416,7 +427,7 @@ void RuntimeContextImpl::GetAutoLaunchSyncDevices(const std::string &identifier, return autoLaunch_.GetAutoLaunchSyncDevices(identifier, devices); } -void RuntimeContextImpl::SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBType type) +void RuntimeContextImpl::SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBTypeInner type) { autoLaunch_.SetAutoLaunchRequestCallback(callback, type); } @@ -548,7 +559,7 @@ bool RuntimeContextImpl::CheckDeviceSecurityAbility(const std::string &devId, co } tempSystemApiAdapter = systemApiAdapter_; } - + return tempSystemApiAdapter->CheckDeviceSecurityAbility(devId, option); } @@ -698,7 +709,7 @@ void RuntimeContextImpl::DumpCommonInfo(int fd) autoLaunch_.Dump(fd); } -void RuntimeContextImpl::CloseAutoLaunchConnection(DBType type, const DBProperties &properties) +void RuntimeContextImpl::CloseAutoLaunchConnection(DBTypeInner type, const DBProperties &properties) { autoLaunch_.CloseConnection(type, properties); } @@ -746,4 +757,217 @@ void RuntimeContextImpl::StopTimeTickMonitorIfNeed() timeTickMonitor_ = nullptr; } } + +void RuntimeContextImpl::SetTranslateToDeviceIdCallback(const TranslateToDeviceIdCallback &callback) +{ + std::lock_guard autoLock(translateToDeviceIdLock_); + translateToDeviceIdCallback_ = callback; + deviceIdCache_.clear(); +} + +int RuntimeContextImpl::TranslateDeviceId(const std::string &deviceId, + const StoreInfo &info, std::string &newDeviceId) +{ + const std::string id = DBCommon::GenerateIdentifierId(info.storeId, info.appId, info.userId); + std::lock_guard autoLock(translateToDeviceIdLock_); + if (translateToDeviceIdCallback_ == nullptr) { + return -E_NOT_SUPPORT; + } + if (deviceIdCache_.find(deviceId) == deviceIdCache_.end() || + deviceIdCache_[deviceId].find(id) == deviceIdCache_[deviceId].end()) { + deviceIdCache_[deviceId][id] = translateToDeviceIdCallback_(deviceId, info); + } + newDeviceId = deviceIdCache_[deviceId][id]; + return E_OK; +} + +bool RuntimeContextImpl::ExistTranslateDevIdCallback() const +{ + std::lock_guard autoLock(translateToDeviceIdLock_); + return translateToDeviceIdCallback_ != nullptr; +} + +void RuntimeContextImpl::SetThreadPool(const std::shared_ptr &threadPool) +{ + std::unique_lock writeLock(threadPoolLock_); + threadPool_ = threadPool; + LOGD("[RuntimeContext] Set thread pool finished"); +} + +std::shared_ptr RuntimeContextImpl::GetThreadPool() const +{ + std::shared_lock readLock(threadPoolLock_); + return threadPool_; +} + +int RuntimeContextImpl::ScheduleTaskByThreadPool(const DistributedDB::TaskAction &task) const +{ + std::shared_ptr threadPool = GetThreadPool(); + if (threadPool == nullptr) { + return -E_NOT_SUPPORT; + } + (void)threadPool->Execute(task); + return E_OK; +} + +int RuntimeContextImpl::SetTimerByThreadPool(int milliSeconds, const TimerAction &action, + const TimerFinalizer &finalizer, bool allocTimerId, TimerId &timerId) +{ + std::shared_ptr threadPool = GetThreadPool(); + if (threadPool == nullptr) { + return -E_NOT_SUPPORT; + } + int errCode = E_OK; + if (allocTimerId) { + errCode = AllocTimerId(nullptr, timerId); + } else { + std::lock_guard autoLock(mappingTaskIdLock_); + if (taskIds_.find(timerId) == taskIds_.end()) { + LOGD("[RuntimeContext] Timer has been remove"); + return -E_NO_SUCH_ENTRY; + } + } + if (errCode != E_OK) { + return errCode; + } + { + std::lock_guard autoLock(timerFinalizerLock_); + timerFinalizers_[timerId] = finalizer; + } + Duration duration = std::chrono::duration_cast( + std::chrono::milliseconds(milliSeconds)); + TaskId taskId = threadPool->Execute([milliSeconds, action, timerId, this]() { + ThreadPoolTimerAction(milliSeconds, action, timerId); + }, duration); + std::lock_guard autoLock(mappingTaskIdLock_); + taskIds_[timerId] = taskId; + return E_OK; +} + +int RuntimeContextImpl::ModifyTimerByThreadPool(TimerId timerId, int milliSeconds) +{ + std::shared_ptr threadPool = GetThreadPool(); + if (threadPool == nullptr) { + return -E_NOT_SUPPORT; + } + TaskId taskId; + { + std::lock_guard autoLock(mappingTaskIdLock_); + if (taskIds_.find(timerId) == taskIds_.end()) { + return -E_NO_SUCH_ENTRY; + } + taskId = taskIds_[timerId]; + } + Duration duration = std::chrono::duration_cast( + std::chrono::milliseconds(milliSeconds)); + TaskId ret = threadPool->Reset(taskId, duration); + if (ret != taskId) { + return -E_NO_SUCH_ENTRY; + } + return E_OK; +} + +void RuntimeContextImpl::RemoveTimerByThreadPool(TimerId timerId, bool wait) +{ + std::shared_ptr threadPool = GetThreadPool(); + if (threadPool == nullptr) { + return; + } + TaskId taskId; + { + std::lock_guard autoLock(mappingTaskIdLock_); + if (taskIds_.find(timerId) == taskIds_.end()) { + return; + } + taskId = taskIds_[timerId]; + taskIds_.erase(timerId); + } + bool removeBeforeExecute = threadPool->Remove(taskId, wait); + TimerFinalizer timerFinalizer = nullptr; + if (removeBeforeExecute) { + std::lock_guard autoLock(timerFinalizerLock_); + timerFinalizer = timerFinalizers_[timerId]; + timerFinalizers_.erase(timerId); + } + if (timerFinalizer) { + timerFinalizer(); + } +} + +void RuntimeContextImpl::ThreadPoolTimerAction(int milliSeconds, const TimerAction &action, TimerId timerId) +{ + TimerFinalizer timerFinalizer = nullptr; + { + std::lock_guard autoLock(timerFinalizerLock_); + if (timerFinalizers_.find(timerId) == timerFinalizers_.end()) { + LOGD("[RuntimeContext] Timer has been finalize"); + return; + } + timerFinalizer = timerFinalizers_[timerId]; + timerFinalizers_.erase(timerId); + } + if (action(timerId) == E_OK) { + // schedule task again + int errCode = SetTimerByThreadPool(milliSeconds, action, timerFinalizer, false, timerId); + if (errCode == E_OK) { + return; + } + LOGW("[RuntimeContext] create timer failed %d", errCode); + } + if (timerFinalizer) { + timerFinalizer(); + } + { + std::lock_guard autoLock(mappingTaskIdLock_); + taskIds_.erase(timerId); + } + std::lock_guard autoLock(timersLock_); + timers_.erase(timerId); +} + +void RuntimeContextImpl::SetCloudTranslate(const std::shared_ptr &dataTranslate) +{ + std::unique_lock autoLock(dataTranslateLock_); + dataTranslate_ = dataTranslate; +} + +int RuntimeContextImpl::AssetToBlob(const Asset &asset, std::vector &blob) +{ + std::shared_lock autoLock(dataTranslateLock_); + if (dataTranslate_ == nullptr) { + return -E_NOT_INIT; + } + blob = dataTranslate_->AssetToBlob(asset); + return E_OK; +} + +int RuntimeContextImpl::AssetsToBlob(const Assets &assets, std::vector &blob) +{ + std::shared_lock autoLock(dataTranslateLock_); + if (dataTranslate_ == nullptr) { + return -E_NOT_INIT; + } + blob = dataTranslate_->AssetsToBlob(assets); + return E_OK; +} + +int RuntimeContextImpl::BlobToAsset(const std::vector &blob, Asset &asset) +{ + std::shared_lock autoLock(dataTranslateLock_); + if (dataTranslate_ == nullptr) { + return -E_NOT_INIT; + } + asset = dataTranslate_->BlobToAsset(blob); + return E_OK; +} + +int RuntimeContextImpl::BlobToAssets(std::vector &blob, Assets &assets) +{ + std::shared_lock autoLock(dataTranslateLock_); + if (dataTranslate_ == nullptr) { + return -E_NOT_INIT; + } + assets = dataTranslate_->BlobToAssets(blob); + return E_OK; +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/common/src/runtime_context_impl.h b/frameworks/libs/distributeddb/common/src/runtime_context_impl.h index 62b9ce623c790f949af7c6b026006c2e9b50c8c1..c702cbce9808513ccab2ced6d800f864134dc5b3 100644 --- a/frameworks/libs/distributeddb/common/src/runtime_context_impl.h +++ b/frameworks/libs/distributeddb/common/src/runtime_context_impl.h @@ -60,7 +60,8 @@ public: void ShrinkMemory(const std::string &description) override; // Register a time changed lister, it will be callback when local time changed. - NotificationChain::Listener *RegisterTimeChangedLister(const TimeChangedAction &action, int &errCode) override; + NotificationChain::Listener *RegisterTimeChangedLister(const TimeChangedAction &action, + const TimeFinalizeAction &finalize, int &errCode) override; int SetPermissionCheckCallback(const PermissionCheckCallback &callback) override; @@ -78,7 +79,7 @@ public: void GetAutoLaunchSyncDevices(const std::string &identifier, std::vector &devices) const override; - void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBType type) override; + void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBTypeInner type) override; NotificationChain::Listener *RegisterLockStatusLister(const LockStatusNotifier &action, int &errCode) override; @@ -120,7 +121,7 @@ public: void DumpCommonInfo(int fd) override; - void CloseAutoLaunchConnection(DBType type, const DBProperties &properties) override; + void CloseAutoLaunchConnection(DBTypeInner type, const DBProperties &properties) override; int SetPermissionConditionCallback(const PermissionConditionCallback &callback) override; @@ -130,6 +131,22 @@ public: void StopTimeTickMonitorIfNeed() override; + void SetTranslateToDeviceIdCallback(const TranslateToDeviceIdCallback &callback) override; + + int TranslateDeviceId(const std::string &deviceId, + const StoreInfo &info, std::string &newDeviceId) override; + + bool ExistTranslateDevIdCallback() const override; + + void SetThreadPool(const std::shared_ptr &threadPool) override; + + std::shared_ptr GetThreadPool() const override; + + void SetCloudTranslate(const std::shared_ptr &dataTranslate) override; + int AssetToBlob(const Asset &asset, std::vector &blob) override; + int AssetsToBlob(const Assets &assets, std::vector &blob) override; + int BlobToAsset(const std::vector &blob, Asset &asset) override; + int BlobToAssets(std::vector &blob, Assets &assets) override; private: static constexpr int MAX_TP_THREADS = 10; // max threads of the task pool. static constexpr int MIN_TP_THREADS = 1; // min threads of the task pool. @@ -139,6 +156,17 @@ private: int PrepareTaskPool(); int AllocTimerId(IEvent *evTimer, TimerId &timerId); + int ScheduleTaskByThreadPool(const TaskAction &task) const; + + int SetTimerByThreadPool(int milliSeconds, const TimerAction &action, + const TimerFinalizer &finalizer, bool allocTimerId, TimerId &timerId); + + int ModifyTimerByThreadPool(TimerId timerId, int milliSeconds); + + void RemoveTimerByThreadPool(TimerId timerId, bool wait); + + void ThreadPoolTimerAction(int milliSeconds, const TimerAction &action, TimerId timerId); + // Context fields mutable std::mutex labelMutex_; std::string processLabel_; @@ -192,6 +220,21 @@ private: // Get map from this callback, use for run permission check in remote device mutable std::shared_mutex permissionConditionLock_; PermissionConditionCallback permissionConditionCallback_; + + mutable std::mutex translateToDeviceIdLock_; + TranslateToDeviceIdCallback translateToDeviceIdCallback_; + std::map> deviceIdCache_; // cache > + + mutable std::shared_mutex threadPoolLock_; + std::shared_ptr threadPool_; + + mutable std::mutex mappingTaskIdLock_; + std::map taskIds_; + mutable std::mutex timerFinalizerLock_; + std::map timerFinalizers_; + + mutable std::shared_mutex dataTranslateLock_; + std::shared_ptr dataTranslate_; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp b/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp index bf96ac03486a617896da09e1eceffd1c47a9833c..1c8756f43e1557f1049377283ef39c66350545e5 100644 --- a/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp +++ b/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp @@ -80,7 +80,8 @@ void TimeTickMonitor::StopTimeTickMonitor() isStarted_ = false; } -NotificationChain::Listener *TimeTickMonitor::RegisterTimeChangedLister(const TimeChangedAction &action, int &errCode) +NotificationChain::Listener *TimeTickMonitor::RegisterTimeChangedLister(const TimeChangedAction &action, + const TimeFinalizeAction &finalize, int &errCode) { if (timeChangedNotifier_ == nullptr) { errCode = -E_NOT_INIT; @@ -92,7 +93,7 @@ NotificationChain::Listener *TimeTickMonitor::RegisterTimeChangedLister(const Ti return nullptr; } - return timeChangedNotifier_->RegisterListener(TIME_CHANGE_EVENT, action, nullptr, errCode); + return timeChangedNotifier_->RegisterListener(TIME_CHANGE_EVENT, action, finalize, errCode); } int TimeTickMonitor::PrepareNotifierChain() diff --git a/frameworks/libs/distributeddb/common/src/time_tick_monitor.h b/frameworks/libs/distributeddb/common/src/time_tick_monitor.h index eac4d23f731925b31915fe978bb726408c021275..0294ad5aaf9db0b8712b030b705f96ec20b8ac39 100644 --- a/frameworks/libs/distributeddb/common/src/time_tick_monitor.h +++ b/frameworks/libs/distributeddb/common/src/time_tick_monitor.h @@ -36,7 +36,8 @@ public: void StopTimeTickMonitor(); // Register a time changed lister, it will be callback when local time changed. - NotificationChain::Listener *RegisterTimeChangedLister(const TimeChangedAction &action, int &errCode); + NotificationChain::Listener *RegisterTimeChangedLister(const TimeChangedAction &action, + const TimeFinalizeAction &finalize, int &errCode); // Notify TIME_CHANGE_EVENT. void NotifyTimeChange(TimeOffset offset) const; diff --git a/frameworks/libs/distributeddb/communicator/include/communicator_aggregator.h b/frameworks/libs/distributeddb/communicator/include/communicator_aggregator.h index d85e6340f5e0167ecd70453813bc3ab3974ad102..417a8f02e8ee04ad359ec26036854c35fcf77913 100644 --- a/frameworks/libs/distributeddb/communicator/include/communicator_aggregator.h +++ b/frameworks/libs/distributeddb/communicator/include/communicator_aggregator.h @@ -135,6 +135,12 @@ private: // Record the protocol version of remote target. void SetRemoteCommunicatorVersion(const std::string &target, uint16_t version); + void InitSendThread(); + + void SendOnceData(); + + void TriggerSendData(); + DECLARE_OBJECT_TAG(CommunicatorAggregator); static std::atomic isCommunicatorNotFoundFeedbackEnable_; @@ -175,6 +181,11 @@ private: OnConnectCallback onConnectHandle_; Finalizer onConnectFinalizer_; mutable std::mutex onConnectMutex_; + + std::atomic useExclusiveThread_ = false; + bool sendTaskStart_ = false; + mutable std::mutex scheduleSendTaskMutex_; + std::condition_variable finalizeCv_; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp b/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp index 4f8427e1aecfd8f3558c77c43ebec03c2fa12261..f62df2921ab664d06dea2bce98a8e22582c8d006 100644 --- a/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp +++ b/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp @@ -82,7 +82,7 @@ int CommunicatorAggregator::Initialize(IAdapter *inAdapter) GenerateLocalSourceId(); shutdown_ = false; - exclusiveThread_ = std::thread(&CommunicatorAggregator::SendDataRoutine, this); + InitSendThread(); return E_OK; ROLL_BACK: UnRegCallbackFromAdapter(); @@ -105,8 +105,17 @@ void CommunicatorAggregator::Finalize() wakingSignal_ = true; wakingCv_.notify_one(); } - exclusiveThread_.join(); // Waiting thread to thoroughly quit - LOGI("[CommAggr][Final] Sub Thread Exit."); + if (useExclusiveThread_) { + exclusiveThread_.join(); // Waiting thread to thoroughly quit + LOGI("[CommAggr][Final] Sub Thread Exit."); + } else { + LOGI("[CommAggr][Final] Begin wait send task exit."); + std::unique_lock scheduleSendTaskLock(scheduleSendTaskMutex_); + finalizeCv_.wait(scheduleSendTaskLock, [this]() { + return !sendTaskStart_; + }); + LOGI("[CommAggr][Final] End wait send task exit."); + } scheduler_.Finalize(); // scheduler_ must finalize here to make space for linker to dump residual frame adapterHandle_->StopAdapter(); @@ -313,10 +322,7 @@ int CommunicatorAggregator::ScheduleSendTask(const std::string &dstTarget, Seria LOGW("[CommAggr][Create] Exit failed, thread=%s, errCode=%d", GetThreadId().c_str(), errCode); return errCode; } - - std::lock_guard wakingLockGuard(wakingMutex_); - wakingSignal_ = true; - wakingCv_.notify_one(); + TriggerSendData(); LOGI("[CommAggr][Create] Exit ok, thread=%s, frameId=%u", GetThreadId().c_str(), info.frameId); return E_OK; } @@ -348,40 +354,7 @@ void CommunicatorAggregator::SendDataRoutine() wakingSignal_ = false; continue; } - - SendTask taskToSend; - int errCode = scheduler_.ScheduleOutSendTask(taskToSend); - if (errCode != E_OK) { - continue; // Not possible to happen - } - // - std::vector, uint32_t>> piecePackets; - errCode = ProtocolProto::SplitFrameIntoPacketsIfNeed(taskToSend.buffer, - adapterHandle_->GetMtuSize(taskToSend.dstTarget), piecePackets); - if (errCode != E_OK) { - LOGE("[CommAggr][Routine] Split frame fail, errCode=%d.", errCode); - TaskFinalizer(taskToSend, errCode); - continue; - } - // > - std::vector>> eachPacket; - if (piecePackets.empty()) { - // Case that no need to split a frame, just use original buffer as a packet - std::pair tmpEntry = taskToSend.buffer->GetReadOnlyBytesForEntireBuffer(); - std::pair> entry; - entry.first = tmpEntry.first - taskToSend.buffer->GetExtendHeadLength(); - entry.second.first = taskToSend.buffer->GetExtendHeadLength(); - entry.second.second = tmpEntry.second + entry.second.first; - eachPacket.push_back(entry); - } else { - for (auto &entry : piecePackets) { - std::pair> tmpEntry = {&(entry.first[0]), - {entry.second, entry.first.size()}}; - eachPacket.push_back(tmpEntry); - } - } - - SendPacketsAndDisposeTask(taskToSend, eachPacket); + SendOnceData(); } } @@ -565,9 +538,7 @@ void CommunicatorAggregator::OnSendable(const std::string &target) LOGE("[CommAggr][Sendable] NoDelay target=%s{private} fail, errCode=%d.", target.c_str(), errCode); return; } - std::lock_guard wakingLockGuard(wakingMutex_); - wakingSignal_ = true; - wakingCv_.notify_one(); + TriggerSendData(); } void CommunicatorAggregator::OnFragmentReceive(const std::string &srcTarget, const uint8_t *bytes, uint32_t length, @@ -890,5 +861,89 @@ std::shared_ptr CommunicatorAggregator::GetExtendHeaderHandl return adapterHandle_->GetExtendHeaderHandle(paramInfo); } +void CommunicatorAggregator::InitSendThread() +{ + if (RuntimeContext::GetInstance()->GetThreadPool() != nullptr) { + return; + } + exclusiveThread_ = std::thread(&CommunicatorAggregator::SendDataRoutine, this); + useExclusiveThread_ = true; +} + +void CommunicatorAggregator::SendOnceData() +{ + SendTask taskToSend; + int errCode = scheduler_.ScheduleOutSendTask(taskToSend); + if (errCode != E_OK) { + return; // Not possible to happen + } + // + std::vector, uint32_t>> piecePackets; + errCode = ProtocolProto::SplitFrameIntoPacketsIfNeed(taskToSend.buffer, + adapterHandle_->GetMtuSize(taskToSend.dstTarget), piecePackets); + if (errCode != E_OK) { + LOGE("[CommAggr] Split frame fail, errCode=%d.", errCode); + TaskFinalizer(taskToSend, errCode); + return; + } + // > + std::vector>> eachPacket; + if (piecePackets.empty()) { + // Case that no need to split a frame, just use original buffer as a packet + std::pair tmpEntry = taskToSend.buffer->GetReadOnlyBytesForEntireBuffer(); + std::pair> entry; + entry.first = tmpEntry.first - taskToSend.buffer->GetExtendHeadLength(); + entry.second.first = taskToSend.buffer->GetExtendHeadLength(); + entry.second.second = tmpEntry.second + entry.second.first; + eachPacket.push_back(entry); + } else { + for (auto &entry : piecePackets) { + std::pair> tmpEntry = {&(entry.first[0]), + {entry.second, entry.first.size()}}; + eachPacket.push_back(tmpEntry); + } + } + + SendPacketsAndDisposeTask(taskToSend, eachPacket); +} + +void CommunicatorAggregator::TriggerSendData() +{ + if (useExclusiveThread_) { + std::lock_guard wakingLockGuard(wakingMutex_); + wakingSignal_ = true; + wakingCv_.notify_one(); + return; + } + { + std::lock_guard autoLock(scheduleSendTaskMutex_); + if (sendTaskStart_) { + return; + } + sendTaskStart_ = true; + } + RefObject::IncObjRef(this); + int errCode = RuntimeContext::GetInstance()->ScheduleTask([this]() { + LOGI("[CommAggr] Send thread start."); + while (!shutdown_ && scheduler_.GetNoDelayTaskCount() != 0) { + SendOnceData(); + } + { + std::lock_guard autoLock(scheduleSendTaskMutex_); + sendTaskStart_ = false; + } + if (!shutdown_ && scheduler_.GetNoDelayTaskCount() != 0) { + TriggerSendData(); // avoid sendTaskStart_ was mark false after trigger thread check it + } + finalizeCv_.notify_one(); + RefObject::DecObjRef(this); + LOGI("[CommAggr] Send thread end."); + }); + if (errCode != E_OK) { + LOGW("[CommAggr] Trigger send data failed %d", errCode); + RefObject::DecObjRef(this); + } +} + DEFINE_OBJECT_TAG_FACILITIES(CommunicatorAggregator) } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp b/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp index 849bae8450ab65b1378b30ed26417c41ecd3c63f..0422edd9a70e26f4299685b5dfd0f4b58755119f 100644 --- a/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp +++ b/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp @@ -264,6 +264,10 @@ void NetworkAdapter::OnDataReceiveHandler(const DeviceInfos &srcDevInfo, const u LOGI("[NAdapt][OnDataRecv] userId dismatched, drop packet"); return; } + if (headLength >= length) { + LOGW("[NAdapt][OnDataRecv] head len is too big, drop packet"); + return; + } { std::lock_guard onReceiveLockGard(onReceiveMutex_); if (!onReceiveHandle_) { diff --git a/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp b/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp index 5268d29109c9b47f1a1e378230089daa48c45c3c..4fce91dbdf500b8d9cedecaffb0949d00fc8e1af 100644 --- a/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp +++ b/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp @@ -15,6 +15,7 @@ #include "protocol_proto.h" #include +#include #include #include "db_common.h" #include "endian_convert.h" @@ -60,6 +61,7 @@ FrameType GetFrameType(uint8_t inPacketType) } std::map ProtocolProto::msgIdMapFunc_; +std::shared_mutex ProtocolProto::msgIdMutex_; uint32_t ProtocolProto::GetAppLayerFrameHeaderLength() { @@ -366,6 +368,7 @@ int ProtocolProto::CombinePacketIntoFrame(SerialBuffer *inFrame, const uint8_t * int ProtocolProto::RegTransformFunction(uint32_t msgId, const TransformFunc &inFunc) { + std::unique_lock autoLock(msgIdMutex_); if (msgIdMapFunc_.count(msgId) != 0) { return -E_ALREADY_REGISTER; } @@ -378,6 +381,7 @@ int ProtocolProto::RegTransformFunction(uint32_t msgId, const TransformFunc &inF void ProtocolProto::UnRegTransformFunction(uint32_t msgId) { + std::unique_lock autoLock(msgIdMutex_); if (msgIdMapFunc_.count(msgId) != 0) { msgIdMapFunc_.erase(msgId); } @@ -582,12 +586,12 @@ int ProtocolProto::CalculateXorSum(const uint8_t *bytes, uint32_t length, uint64 int ProtocolProto::CalculateDataSerializeLength(const Message *inMsg, uint32_t &outLength) { uint32_t messageId = inMsg->GetMessageId(); - if (msgIdMapFunc_.count(messageId) == 0) { + TransformFunc function; + if (GetTransformFunc(messageId, function) != E_OK) { LOGE("[Proto][CalcuDataSerialLen] Not registered for messageId=%" PRIu32 ".", messageId); return -E_NOT_REGISTER; } - TransformFunc function = msgIdMapFunc_[messageId]; uint32_t serializeLen = function.computeFunc(inMsg); uint32_t alignedLen = BYTE_8_ALIGN(serializeLen); // Currently not allowed the upper module to send a message without data. Regard serializeLen zero as abnormal. @@ -625,8 +629,11 @@ int ProtocolProto::SerializeMessage(SerialBuffer *inBuff, const Message *inMsg) return E_OK; } // If dataLen not zero, the TransformFunc of this messageId must exist, the caller's logic guarantee it - uint32_t messageId = inMsg->GetMessageId(); - TransformFunc function = msgIdMapFunc_[messageId]; + TransformFunc function; + if (GetTransformFunc(inMsg->GetMessageId(), function) != E_OK) { + LOGE("[Proto][Serialize] Not register, messageId=%" PRIu32 ".", inMsg->GetMessageId()); + return -E_NOT_REGISTER; + } int result = function.serializeFunc(payloadByteLen.first + sizeof(MessageHeader), dataLen, inMsg); if (result != E_OK) { LOGE("[Proto][Serialize] SerializeFunc Fail, result=%d.", result); @@ -674,12 +681,11 @@ int ProtocolProto::DeSerializeMessage(const SerialBuffer *inBuff, Message *inMsg if (onlyMsgHeader || dataLen == 0) { // Do not need to deserialize data return E_OK; } - uint32_t messageId = inMsg->GetMessageId(); - if (msgIdMapFunc_.count(messageId) == 0) { - LOGE("[Proto][DeSerialize] Not register, messageId=%" PRIu32 ".", messageId); + TransformFunc function; + if (GetTransformFunc(inMsg->GetMessageId(), function) != E_OK) { + LOGE("[Proto][DeSerialize] Not register, messageId=%" PRIu32 ".", inMsg->GetMessageId()); return -E_NOT_REGISTER; } - TransformFunc function = msgIdMapFunc_[messageId]; int result = function.deserializeFunc(payloadByteLen.first + sizeof(MessageHeader), dataLen, inMsg); if (result != E_OK) { LOGE("[Proto][DeSerialize] DeserializeFunc Fail, result=%d.", result); @@ -723,11 +729,6 @@ int ProtocolProto::ParseCommPhyHeaderCheckMagicAndVersion(const uint8_t *bytes, int ProtocolProto::ParseCommPhyHeaderCheckField(const std::string &srcTarget, const CommPhyHeader &phyHeader, const uint8_t *bytes, uint32_t length) { - if (phyHeader.sourceId != Hash::HashFunc(srcTarget)) { - LOGE("[Proto][ParsePhyCheck] SourceId Error: inSourceId=%" PRIu64 ", srcTarget=%s{private}, hashId=%" PRIu64, - ULL(phyHeader.sourceId), srcTarget.c_str(), ULL(Hash::HashFunc(srcTarget))); - return -E_PARSE_FAIL; - } if (phyHeader.packetLen != length) { LOGE("[Proto][ParsePhyCheck] PacketLen=%" PRIu32 " Mismatch length=%" PRIu32 ".", phyHeader.packetLen, length); return -E_PARSE_FAIL; @@ -1092,4 +1093,15 @@ int ProtocolProto::FillExtendHeadDataIfNeed(std::shared_ptr } return E_OK; } + +int ProtocolProto::GetTransformFunc(uint32_t messageId, DistributedDB::TransformFunc &function) +{ + std::shared_lock autoLock(msgIdMutex_); + const auto &entry = msgIdMapFunc_.find(messageId); + if (entry == msgIdMapFunc_.end()) { + return -E_NOT_REGISTER; + } + function = entry->second; + return E_OK; +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/communicator/src/protocol_proto.h b/frameworks/libs/distributeddb/communicator/src/protocol_proto.h index c5f7e0918c1703daf5207438a40dfce3934e231f..f151f0a609d7c265eccc20571dfcad7cc9891bb9 100644 --- a/frameworks/libs/distributeddb/communicator/src/protocol_proto.h +++ b/frameworks/libs/distributeddb/communicator/src/protocol_proto.h @@ -18,6 +18,7 @@ #include #include +#include #include "communicator_type_define.h" #include "frame_header.h" #include "iprocess_communicator.h" @@ -130,6 +131,9 @@ private: static int FillExtendHeadDataIfNeed(std::shared_ptr &extendHandle, SerialBuffer *buffer, uint32_t headSize); + static int GetTransformFunc(uint32_t messageId, TransformFunc &function); + + static std::shared_mutex msgIdMutex_; static std::map msgIdMapFunc_; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/include/query.h b/frameworks/libs/distributeddb/include/query.h index 657e93df3eef3fa1a309822bddcece3649fb9ec0..1a1f1d90069712b001ae49572e157336b9209c95 100644 --- a/frameworks/libs/distributeddb/include/query.h +++ b/frameworks/libs/distributeddb/include/query.h @@ -33,6 +33,8 @@ public: DB_API static Query Select(); DB_API static Query Select(const std::string &tableName); + DB_API Query FromTable(const std::vector &tableNames); + template DB_API Query &EqualTo(const std::string &field, const T &value) { diff --git a/frameworks/libs/distributeddb/include/types_export.h b/frameworks/libs/distributeddb/include/types_export.h index 95adef5e899bf4cd490bb5625d14b6aaee63837d..9772f2a8837ccffeedd1d1f5e13b72641bcf8c3e 100644 --- a/frameworks/libs/distributeddb/include/types_export.h +++ b/frameworks/libs/distributeddb/include/types_export.h @@ -206,5 +206,12 @@ enum class CompressAlgorithm : uint8_t { NONE = 0, ZLIB = 1 }; + +struct StoreInfo { + std::string userId; + std::string appId; + std::string storeId; +}; +using TranslateToDeviceIdCallback = std::function; } // namespace DistributedDB #endif // DISTRIBUTEDDB_TYPES_EXPORT_H diff --git a/frameworks/libs/distributeddb/interfaces/include/cloud/cloud_store_types.h b/frameworks/libs/distributeddb/interfaces/include/cloud/cloud_store_types.h new file mode 100644 index 0000000000000000000000000000000000000000..bcdca889e284b2836d2aba6d487c31a0ddf7dd43 --- /dev/null +++ b/frameworks/libs/distributeddb/interfaces/include/cloud/cloud_store_types.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2023 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 CLOUD_STORE_TYPE_H +#define CLOUD_STORE_TYPE_H + +#include "db_types.h" +#include +#include +#include +#include +#include + +#include "store_types.h" + +namespace DistributedDB { +const uint32_t MAX_UPLOAD_SIZE = 1024 * 1024 * 8; +enum TableSyncType { + DEVICE_COOPERATION = 0, + CLOUD_COOPERATION = 1, +}; + +enum ClearMode { + DATA_INCLUDE = 0, + FLAG_ONLY = 1, +}; + +struct Asset { + uint32_t version = 0; + std::string name; + std::string uri; + std::string modifyTime; + std::string createTime; + std::string size; + std::string hash; +}; +using Nil = std::monostate; +using Assets = std::vector; +using Bytes = std::vector; +using Type = std::variant; +using VBucket = std::map; + +enum ProcessStatus { + PREPARED = 0, + PROCESSING = 1, + FINISHED = 2, +}; + +struct Info { + uint32_t batchIndex = 0; + uint32_t total = 0; + uint32_t successCount = 0; // merge or upload success count + uint32_t failCount = 0; +}; + +struct TableProcessInfo { + ProcessStatus process = PREPARED; + Info downLoadInfo; + Info upLoadInfo; +}; + +struct SyncProcess { + ProcessStatus process = PREPARED; + DBStatus errCode = OK; + std::map tableProcess; +}; + +struct Field { + std::string colName; + int32_t type; // get value from TYPE_INDEX; + bool primary = false; + bool nullable = true; +}; + +struct TableSchema { + std::string name; + std::vector fields; +}; + +struct DataBaseSchema { + std::vector tables; +}; + +} // namespace DistributedDB +#endif // CLOUD_STORE_TYPE_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/interfaces/include/cloud/icloud_data_translate.h b/frameworks/libs/distributeddb/interfaces/include/cloud/icloud_data_translate.h new file mode 100644 index 0000000000000000000000000000000000000000..5604c0e4ef38e3cbf7b7714984ff430ec0c19fad --- /dev/null +++ b/frameworks/libs/distributeddb/interfaces/include/cloud/icloud_data_translate.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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 ICLOUD_DATA_TRANSLATE_H +#define ICLOUD_DATA_TRANSLATE_H + +#include +#include +#include +#include +#include +#include "cloud_store_types.h" + +namespace DistributedDB { +class ICloudDataTranslate { +public: + virtual std::vector AssetToBlob(const Asset &asset) = 0; + virtual std::vector AssetsToBlob(const Assets &assets) = 0; + virtual Asset BlobToAsset(const std::vector &blob) = 0; + virtual Assets BlobToAssets(std::vector &blob) = 0; +}; +} // namespace DistributedDB + +#endif // ICLOUD_DATA_TRANSLATE_H diff --git a/frameworks/libs/distributeddb/interfaces/include/cloud/icloud_db.h b/frameworks/libs/distributeddb/interfaces/include/cloud/icloud_db.h new file mode 100644 index 0000000000000000000000000000000000000000..d9ca944511702535e721c0e1faee79a3c065d786 --- /dev/null +++ b/frameworks/libs/distributeddb/interfaces/include/cloud/icloud_db.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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 ICLOUD_DB_H +#define ICLOUD_DB_H + +#include +#include +#include +#include +#include +#include "cloud_store_types.h" + +namespace DistributedDB { +class ICloudDb { +public: + /** + ** param[in & out] extend: will fill gid after insert ok + **/ + virtual DBStatus BatchInsert(const std::string &tableName, std::vector &&record, + std::vector &extend) = 0; + virtual DBStatus BatchUpdate(const std::string &tableName, std::vector &&record, + std::vector &extend) = 0; + virtual DBStatus BatchDelete(const std::string &tableName, std::vector &&record, + std::vector &extend) = 0; + /** + ** param[out] data: query data + **/ + virtual DBStatus Query(const std::string &tableName, VBucket &extend, std::vector &data) = 0; + virtual std::pair Lock() = 0; + virtual DBStatus UnLock() = 0; + virtual DBStatus HeartBeat() = 0; + virtual DBStatus Close() = 0; +}; +} // namespace DistributedDB + +#endif // ICLOUD_DB_H diff --git a/frameworks/libs/distributeddb/interfaces/include/ithread_pool.h b/frameworks/libs/distributeddb/interfaces/include/ithread_pool.h new file mode 100644 index 0000000000000000000000000000000000000000..f574e8c9ff3a39156d426439bfd1ec9f214adec1 --- /dev/null +++ b/frameworks/libs/distributeddb/interfaces/include/ithread_pool.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 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 ITHREAD_POOL_H +#define ITHREAD_POOL_H + +#include +#include "store_types.h" + +namespace DistributedDB { +using Task = std::function; +using TaskId = uint64_t; +using Duration = std::chrono::steady_clock::duration; +class IThreadPool { +public: + IThreadPool() = default; + virtual ~IThreadPool() = default; + + virtual TaskId Execute(const Task &task) = 0; + + virtual TaskId Execute(const Task &task, Duration delay) = 0; + + virtual TaskId Schedule(const Task &task, Duration interval) = 0; + + virtual TaskId Schedule(const Task &task, Duration delay, Duration interval) = 0; + + virtual TaskId Schedule(const Task &task, Duration delay, Duration interval, uint64_t times) = 0; + + virtual bool Remove(const TaskId &taskId, bool wait) = 0; + + virtual TaskId Reset(const TaskId &taskId, Duration interval) = 0; +}; +} +#endif // ITHREAD_POOL_H diff --git a/frameworks/libs/distributeddb/interfaces/include/kv_store_delegate_manager.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_delegate_manager.h index 78bc31ff2129949baca67374aab95ad47d93de6e..9f8792b39deaccb9e0b53e2e46d089d2cd939717 100644 --- a/frameworks/libs/distributeddb/interfaces/include/kv_store_delegate_manager.h +++ b/frameworks/libs/distributeddb/interfaces/include/kv_store_delegate_manager.h @@ -91,8 +91,10 @@ public: DB_API static DBStatus DisableKvStoreAutoLaunch(const std::string &userId, const std::string &appId, const std::string &storeId); + // deprecated DB_API static void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback); + // deprecated DB_API static std::string GetKvStoreIdentifier(const std::string &userId, const std::string &appId, const std::string &storeId, bool syncDualTupleMode = false); diff --git a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h index 21a112187afa4849d6db44b17519a3964384cdab..453aea705e8d1ad7343b1e2f7091a03e2f1af7ba 100644 --- a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h +++ b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h @@ -227,6 +227,9 @@ public: // calculate full sync sync data size after Serialize; // return 1M while sync data size is larger than 1M, otherwise return actualy size DB_API virtual size_t GetSyncDataSize(const std::string &device) const = 0; + + // update all key in sync_data which is not deleted data + DB_API virtual DBStatus UpdateKey(const UpdateKeyCallback &callback) = 0; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h index 9bb6f38e5adc133f04e81e764f1dc2ea91911226..3e1714887e1d8b9a95318fb0bdcd40516b66f1cf 100644 --- a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h +++ b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h @@ -19,6 +19,9 @@ #include #include #include "distributeddb/result_set.h" +#include "cloud/cloud_store_types.h" +#include "cloud/icloud_db.h" +#include "cloud/icloud_data_translate.h" #include "query.h" #include "store_types.h" #include "store_observer.h" @@ -38,18 +41,30 @@ public: uint32_t iterateTimes = 0; }; - DB_API virtual DBStatus CreateDistributedTable(const std::string &tableName) = 0; + DB_API virtual DBStatus CreateDistributedTable(const std::string &tableName, + TableSyncType = DEVICE_COOPERATION) = 0; DB_API virtual DBStatus Sync(const std::vector &devices, SyncMode mode, const Query &query, const SyncStatusCallback &onComplete, bool wait) = 0; - DB_API virtual DBStatus RemoveDeviceData(const std::string &device) = 0; + DB_API virtual DBStatus RemoveDeviceData(const std::string &device, ClearMode = DATA_INCLUDE) = 0; DB_API virtual DBStatus RemoveDeviceData(const std::string &device, const std::string &tableName) = 0; // timeout is in ms. DB_API virtual DBStatus RemoteQuery(const std::string &device, const RemoteCondition &condition, uint64_t timeout, std::shared_ptr &result) = 0; + + // remove all device data + DB_API virtual DBStatus RemoveDeviceData() = 0; + + DB_API virtual DBStatus Sync(const std::vector &devices, SyncMode mode, + const Query &query, const std::function &onProcess, + int64_t waitTime) = 0; + + DB_API virtual DBStatus SetCloudDB(const std::shared_ptr &cloudDb) = 0; + + DB_API virtual DBStatus SetCloudDbSchema(const DataBaseSchema &schema) = 0; }; } // namespace DistributedDB #endif // RELATIONAL_STORE_DELEGATE_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_manager.h b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_manager.h index 66276e8d2c710acf2bd89f1bb15d61dd1df9d02c..f22b9e715bb523bd4731367a8bba24109839d92c 100644 --- a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_manager.h +++ b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_manager.h @@ -42,11 +42,12 @@ public: DB_API DBStatus CloseStore(RelationalStoreDelegate *store); + // deprecated DB_API static void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback); + // deprecated DB_API static std::string GetRelationalStoreIdentifier(const std::string &userId, const std::string &appId, const std::string &storeId, bool syncDualTupleMode = false); - private: std::string appId_; std::string userId_; diff --git a/frameworks/libs/distributeddb/interfaces/include/runtime_config.h b/frameworks/libs/distributeddb/interfaces/include/runtime_config.h index 1386e47410a2c220dd423ac0530e390acbc01b23..77c078997f19ae83eec7b438d6c0858cc24e4041 100644 --- a/frameworks/libs/distributeddb/interfaces/include/runtime_config.h +++ b/frameworks/libs/distributeddb/interfaces/include/runtime_config.h @@ -19,10 +19,18 @@ #include #include +#include "auto_launch_export.h" +#include "cloud/icloud_data_translate.h" #include "iprocess_communicator.h" #include "iprocess_system_api_adapter.h" +#include "ithread_pool.h" #include "store_types.h" namespace DistributedDB { +enum class DBType { + DB_KV, + DB_RELATION, +}; + class RuntimeConfig final { public: DB_API RuntimeConfig() = default; @@ -50,6 +58,19 @@ public: DB_API static bool IsProcessSystemApiAdapterValid(); + DB_API static void SetTranslateToDeviceIdCallback(const TranslateToDeviceIdCallback &callback); + + DB_API static void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBType type); + + DB_API static std::string GetStoreIdentifier(const std::string &userId, const std::string &appId, + const std::string &storeId, bool syncDualTupleMode = false); + + DB_API static void ReleaseAutoLaunch(const std::string &userId, const std::string &appId, + const std::string &storeId, DBType type); + + DB_API static void SetThreadPool(const std::shared_ptr &threadPool); + + DB_API static void SetCloudTranslate(const std::shared_ptr &dataTranslate); private: static std::mutex communicatorMutex_; static std::mutex multiUserMutex_; diff --git a/frameworks/libs/distributeddb/interfaces/include/store_changed_data.h b/frameworks/libs/distributeddb/interfaces/include/store_changed_data.h index 3077d8d931f81dc723d5a2776e85cb3b75af845e..beef67c189a3ee8d4c9d0413415e42039776cf8a 100644 --- a/frameworks/libs/distributeddb/interfaces/include/store_changed_data.h +++ b/frameworks/libs/distributeddb/interfaces/include/store_changed_data.h @@ -17,7 +17,9 @@ #define STORE_CHANGED_DATA_H #include +#include #include "store_types.h" +#include "cloud/cloud_store_types.h" namespace DistributedDB { struct StoreProperty { @@ -25,6 +27,7 @@ struct StoreProperty { std::string appId; std::string storeId; }; + class StoreChangedData { public: StoreChangedData() {} diff --git a/frameworks/libs/distributeddb/interfaces/include/store_observer.h b/frameworks/libs/distributeddb/interfaces/include/store_observer.h index ea753a3ed89041ea0f3fb66859b0ecdea4a485e5..dc9674d01306c59408adb6bce986132520ad2d0b 100644 --- a/frameworks/libs/distributeddb/interfaces/include/store_observer.h +++ b/frameworks/libs/distributeddb/interfaces/include/store_observer.h @@ -19,12 +19,36 @@ #include "store_changed_data.h" namespace DistributedDB { + +enum ChangeType : uint32_t { + OP_INSERT = 0, + OP_UPDATE, + OP_DELETE, + OP_BUTT, +}; +struct ChangedData { + std::string tableName; + // CLOUD_COOPERATION mode, primaryData store primary keys + // primayData store row id if have no data + std::vector> primaryData[OP_BUTT]; + std::vector field; +}; + +enum Origin : int32_t { + ORIGIN_CLOUD, + ORIGIN_LOCAL, + ORIGIN_REMOTE, + ORIGIN_ALL, + ORIGIN_BUTT +}; class StoreObserver { public: virtual ~StoreObserver() {} // Data change callback - virtual void OnChange(const StoreChangedData &data) = 0; + virtual void OnChange(const StoreChangedData &data) {}; + + virtual void OnChange(Origin origin, const std::string &originalId, ChangedData &&data) {}; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/interfaces/include/store_types.h b/frameworks/libs/distributeddb/interfaces/include/store_types.h index 6a73e36c06a5d2e45c741dabe3810c7b21810792..cf46db42deb4200b4f458fdeb11750ba29c9e67d 100644 --- a/frameworks/libs/distributeddb/interfaces/include/store_types.h +++ b/frameworks/libs/distributeddb/interfaces/include/store_types.h @@ -66,6 +66,10 @@ enum DBStatus { TYPE_MISMATCH, // for row record, get value with mismatch func. REMOTE_OVER_SIZE, // for remote query, the data is too many, only get part or data. RATE_LIMIT, + DATA_HANDLE_ERROR, // remote handle data failed + CONSTRAINT, // constraint check failed in sqlite + CLOUD_ERROR, // cloud error + REACH_END, // Indicates that query function has queried last data from cloud }; struct KvStoreConfig { @@ -108,6 +112,9 @@ enum SyncMode { SYNC_MODE_PUSH_ONLY, SYNC_MODE_PULL_ONLY, SYNC_MODE_PUSH_PULL, + SYNC_MODE_CLOUD_MERGE, + SYNC_MODE_CLOUD_FORCE_PUSH, + SYNC_MODE_CLOUD_FORCE_PULL, }; enum ConflictResolvePolicy { @@ -129,5 +136,7 @@ struct RemoteCondition { std::string sql; // The sql statement; std::vector bindArgs; // The bind args. }; +; +using UpdateKeyCallback = std::function; } // namespace DistributedDB #endif // KV_STORE_TYPE_H diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp index 84da4cadd834e79046834837e1f3c236c48e89d9..9854e2bf2e355c042788b162949794ce4addb713 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp @@ -32,6 +32,7 @@ #include "kvdb_manager.h" #include "kv_store_nb_delegate_impl.h" #include "network_adapter.h" +#include "runtime_config.h" #include "runtime_context.h" #include "param_check_utils.h" #include "auto_launch.h" @@ -541,7 +542,7 @@ DBStatus KvStoreDelegateManager::EnableKvStoreAutoLaunch(const std::string &user } AutoLaunchParam param{ userId, appId, storeId, option, notifier, {}}; std::shared_ptr ptr; - int errCode = AutoLaunch::GetAutoLaunchProperties(param, DBType::DB_KV, true, ptr); + int errCode = AutoLaunch::GetAutoLaunchProperties(param, DBTypeInner::DB_KV, true, ptr); if (errCode != E_OK) { LOGE("[KvStoreManager] Enable auto launch failed:%d", errCode); return TransferDBErrno(errCode); @@ -578,19 +579,13 @@ DBStatus KvStoreDelegateManager::DisableKvStoreAutoLaunch(const std::string &use void KvStoreDelegateManager::SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback) { - RuntimeContext::GetInstance()->SetAutoLaunchRequestCallback(callback, DBType::DB_KV); + RuntimeContext::GetInstance()->SetAutoLaunchRequestCallback(callback, DBTypeInner::DB_KV); } std::string KvStoreDelegateManager::GetKvStoreIdentifier(const std::string &userId, const std::string &appId, const std::string &storeId, bool syncDualTupleMode) { - if (!ParamCheckUtils::CheckStoreParameter(storeId, appId, userId, syncDualTupleMode)) { - return ""; - } - if (syncDualTupleMode) { - return DBCommon::TransferHashString(appId + "-" + storeId); - } - return DBCommon::TransferHashString(userId + "-" + appId + "-" + storeId); + return RuntimeConfig::GetStoreIdentifier(userId, appId, storeId, syncDualTupleMode); } DBStatus KvStoreDelegateManager::SetProcessSystemAPIAdapter(const std::shared_ptr &adapter) diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp index 3128f46fc2a5b942accc6bf8bf3fd1fff39df2ff..986a4d04aa8c60f23a82425dd7a03a454d225967 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp @@ -66,6 +66,8 @@ namespace { { -E_FEEDBACK_UNKNOWN_MESSAGE, NOT_SUPPORT }, { -E_NOT_PERMIT, PERMISSION_CHECK_FORBID_SYNC }, { -E_REMOTE_OVER_SIZE, OVER_MAX_LIMITS }, + { -E_CONSTRAINT, CONSTRAINT }, + { -E_CLOUD_ERROR, CLOUD_ERROR }, }; } diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp index 4f45317896c7ecaebd90eb8436f11ea3c94c3c02..9a8f477202621ece9458b724f2c7f5cf759acb72 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp @@ -974,4 +974,22 @@ size_t KvStoreNbDelegateImpl::GetSyncDataSize(const std::string &device) const } return size; } + +DBStatus KvStoreNbDelegateImpl::UpdateKey(const UpdateKeyCallback &callback) +{ + if (conn_ == nullptr) { + LOGE("%s", INVALID_CONNECTION); + return DB_ERROR; + } + if (callback == nullptr) { + return INVALID_ARGS; + } + int errCode = conn_->UpdateKey(callback); + if (errCode == E_OK) { + LOGI("[KvStoreNbDelegate] update keys success"); + return OK; + } + LOGW("[KvStoreNbDelegate] update keys failed:%d", errCode); + return TransferDBErrno(errCode); +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h index 7ca51a31e59980327498285ae4c00f0306cb3011..24d7c5d8923dc4cd1e30a20ed3203e0986f1e812 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h @@ -156,6 +156,8 @@ public: size_t GetSyncDataSize(const std::string &device) const override; + // update all key in sync_data which is not deleted data + DBStatus UpdateKey(const UpdateKeyCallback &callback) override; private: DBStatus GetInner(const IOption &option, const Key &key, Value &value) const; DBStatus PutInner(const IOption &option, const Key &key, const Value &value); diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.h b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.h index 9544b202ab3dafeebe9abebbc781b4357f82c743..f2035ecbcc32eff57075900a044d9b7b7107142a 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.h +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.h @@ -33,6 +33,7 @@ public: void GetStoreProperty(StoreProperty &storeProperty) const override; void SetStoreProperty(const StoreProperty &storeProperty); + private: mutable std::mutex mutex_; mutable std::string changedDevice_; diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp index 714364dac3e3f551f568e7307647659cf5fd27fa..f46f769d90423f1ca21d8ff38681dcfe5a522765 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp @@ -38,24 +38,29 @@ RelationalStoreDelegateImpl::~RelationalStoreDelegateImpl() conn_ = nullptr; }; -DBStatus RelationalStoreDelegateImpl::RemoveDeviceData(const std::string &device) +DBStatus RelationalStoreDelegateImpl::RemoveDeviceData(const std::string &device, ClearMode mode) { - return RemoveDeviceData(device, {}); + return RemoveDeviceData(device, ""); } -DBStatus RelationalStoreDelegateImpl::CreateDistributedTable(const std::string &tableName) +DBStatus RelationalStoreDelegateImpl::CreateDistributedTable(const std::string &tableName, TableSyncType type) { if (!ParamCheckUtils::CheckRelationalTableName(tableName)) { LOGE("invalid table name."); return INVALID_ARGS; } + if (!(type == DEVICE_COOPERATION || type == CLOUD_COOPERATION)) { + LOGE("invalid table sync type."); + return INVALID_ARGS; + } + if (conn_ == nullptr) { LOGE("[RelationalStore Delegate] Invalid connection for operation!"); return DB_ERROR; } - int errCode = conn_->CreateDistributedTable(tableName); + int errCode = conn_->CreateDistributedTable(tableName, type); if (errCode != E_OK) { LOGE("[RelationalStore Delegate] Create Distributed table failed:%d", errCode); return TransferDBErrno(errCode); @@ -160,5 +165,56 @@ DBStatus RelationalStoreDelegateImpl::RemoteQuery(const std::string &device, con } return OK; } + +DBStatus RelationalStoreDelegateImpl::RemoveDeviceData() +{ + if (conn_ == nullptr) { + LOGE("Invalid connection for operation!"); + return DB_ERROR; + } + + int errCode = conn_->RemoveDeviceData(); + if (errCode != E_OK) { + LOGW("[RelationalStore Delegate] remove device data failed:%d", errCode); + return TransferDBErrno(errCode); + } + return OK; +} + +DBStatus RelationalStoreDelegateImpl::Sync(const std::vector &devices, SyncMode mode, const Query &query, + const std::function &onProcess, int64_t waitTime) +{ + if (conn_ == nullptr) { + return DB_ERROR; + } + int errCode = conn_->Sync(devices, mode, query, onProcess, waitTime); + if (errCode != E_OK) { + LOGW("[RelationalStore Delegate] cloud sync failed:%d", errCode); + return TransferDBErrno(errCode); + } + return OK; +} + +DBStatus RelationalStoreDelegateImpl::SetCloudDB(const std::shared_ptr &cloudDb) +{ + if (conn_ == nullptr) { + return DB_ERROR; + } + if (conn_->SetCloudDB(cloudDb) != E_OK) { + return DB_ERROR; + } + return OK; +} + +DBStatus RelationalStoreDelegateImpl::SetCloudDbSchema(const DataBaseSchema &schema) +{ + if (conn_ == nullptr) { + return DB_ERROR; + } + if (conn_->SetCloudDbSchema(schema) != E_OK) { + return DB_ERROR; + } + return OK; +} } // namespace DistributedDB #endif \ No newline at end of file diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.h b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.h index 508bd94540bd3cc612a51d610f389da3e6d83e60..b3d0b1ee1b40860cb08353fc1042a138e31d890b 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.h +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.h @@ -32,9 +32,9 @@ public: DBStatus Sync(const std::vector &devices, SyncMode mode, const Query &query, const SyncStatusCallback &onComplete, bool wait) override; - DBStatus RemoveDeviceData(const std::string &device) override; + DBStatus RemoveDeviceData(const std::string &device, ClearMode = DATA_INCLUDE) override; - DBStatus CreateDistributedTable(const std::string &tableName) override; + DBStatus CreateDistributedTable(const std::string &tableName, TableSyncType = DEVICE_COOPERATION) override; DBStatus RemoveDeviceData(const std::string &device, const std::string &tableName) override; @@ -46,6 +46,15 @@ public: DBStatus RemoteQuery(const std::string &device, const RemoteCondition &condition, uint64_t timeout, std::shared_ptr &result) override; + DBStatus RemoveDeviceData() override; + + DBStatus Sync(const std::vector &devices, SyncMode mode, const Query &query, + const std::function &onProcess, int64_t waitTime) override; + + DBStatus SetCloudDB(const std::shared_ptr &cloudDb) override; + + DBStatus SetCloudDbSchema(const DataBaseSchema &schema) override; + private: static void OnSyncComplete(const std::map> &devicesStatus, const SyncStatusCallback &onComplete); diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp index 84ca3ba52802bd3c2105709ddab5e5f3296c397d..630ec307fb9d07ed8b53c379b0c667751e9faf76 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp @@ -27,6 +27,7 @@ #include "kv_store_errno.h" #include "relational_store_changed_data_impl.h" #include "relational_store_delegate_impl.h" +#include "runtime_config.h" #include "runtime_context.h" #include "platform_specific.h" @@ -133,7 +134,7 @@ DBStatus RelationalStoreManager::CloseStore(RelationalStoreDelegate *store) std::string RelationalStoreManager::GetDistributedTableName(const std::string &device, const std::string &tableName) { - if (device.empty() || tableName.empty()) { + if ((!RuntimeContext::GetInstance()->ExistTranslateDevIdCallback() && device.empty()) || tableName.empty()) { return {}; } return DBCommon::GetDistributedTableName(device, tableName); @@ -141,19 +142,13 @@ std::string RelationalStoreManager::GetDistributedTableName(const std::string &d void RelationalStoreManager::SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback) { - RuntimeContext::GetInstance()->SetAutoLaunchRequestCallback(callback, DBType::DB_RELATION); + RuntimeContext::GetInstance()->SetAutoLaunchRequestCallback(callback, DBTypeInner::DB_RELATION); } std::string RelationalStoreManager::GetRelationalStoreIdentifier(const std::string &userId, const std::string &appId, const std::string &storeId, bool syncDualTupleMode) { - if (!ParamCheckUtils::CheckStoreParameter(storeId, appId, userId, syncDualTupleMode)) { - return ""; - } - if (syncDualTupleMode) { - return DBCommon::TransferHashString(appId + "-" + storeId); - } - return DBCommon::TransferHashString(DBCommon::GenerateIdentifierId(storeId, appId, userId)); + return RuntimeConfig::GetStoreIdentifier(userId, appId, storeId, syncDualTupleMode); } } // namespace DistributedDB #endif \ No newline at end of file diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp index 65ab912fcc504ccc205d7b7bd263d4fee6662e89..f59f7c355d4736e0c70ac37c91df61db08ff8474 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp @@ -122,6 +122,15 @@ public: return (curTime * TO_100_NS) + currentIncCount_; // Currently Timestamp is uint64_t } + static int GetSysCurrentRawTime(uint64_t &curTime) { + int errCode = GetCurrentSysTimeInMicrosecond(curTime); + if (errCode != E_OK) { + return errCode; + } + curTime *= TO_100_NS; + return E_OK; + } + // Init the TimeHelper static void Initialize(Timestamp maxTimestamp) { @@ -249,9 +258,24 @@ void GetSysTime(sqlite3_context *ctx, int argc, sqlite3_value **argv) sqlite3_result_int64(ctx, (sqlite3_int64)TimeHelper::GetTime(timeOffset)); } +void GetRawSysTime(sqlite3_context *ctx, int argc, sqlite3_value **argv) +{ + if (ctx == nullptr || argc != 0 || argv == nullptr) { // 0: function need zero parameter + return; + } + + uint64_t curTime = 0; + int errCode = TimeHelper::GetSysCurrentRawTime(curTime); + if (errCode != E_OK) { + sqlite3_result_error(ctx, "get raw sys time failed.", errCode); + return; + } + sqlite3_result_int64(ctx, (sqlite3_int64)(curTime)); +} + void GetLastTime(sqlite3_context *ctx, int argc, sqlite3_value **argv) { - if (ctx == nullptr || argc != 0 || argv == nullptr) { // 0: function need one parameter + if (ctx == nullptr || argc != 0 || argv == nullptr) { // 0: function need zero parameter return; } @@ -265,6 +289,13 @@ int RegisterGetSysTime(sqlite3 *db) return RegisterFunction(db, "get_sys_time", 1, nullptr, func); } +int RegisterGetRawSysTime(sqlite3 *db) +{ + TransactFunc func; + func.xFunc = &GetRawSysTime; + return RegisterFunction(db, "get_raw_sys_time", 0, nullptr, func); +} + int RegisterGetLastTime(sqlite3 *db) { TransactFunc func; @@ -413,6 +444,7 @@ void PostHandle(sqlite3 *db) RegisterCalcHash(db); RegisterGetSysTime(db); RegisterGetLastTime(db); + RegisterGetRawSysTime(db); (void)sqlite3_set_droptable_handle(db, &ClearTheLogAfterDropTable); (void)sqlite3_busy_timeout(db, BUSY_TIMEOUT); std::string recursiveTrigger = "PRAGMA recursive_triggers = ON;"; diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h b/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h index 94dfb5e77739623d6009d07c2c73fdafc222c096..6f18812789cf67b39b6626d1d18f2ce20708bde6 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h @@ -17,14 +17,17 @@ #ifdef RELATIONAL_STORE #include "lru_map.h" +#include "icloud_sync_storage_interface.h" #include "relational_db_sync_interface.h" #include "relationaldb_properties.h" +#include "cloud/schema_mgr.h" #include "sqlite_single_relational_storage_engine.h" #include "sqlite_single_ver_relational_continue_token.h" namespace DistributedDB { using RelationalObserverAction = std::function; -class RelationalSyncAbleStorage : public RelationalDBSyncInterface, public virtual RefObject { +class RelationalSyncAbleStorage : public RelationalDBSyncInterface, public ICloudSyncStorageInterface, + public virtual RefObject { public: explicit RelationalSyncAbleStorage(std::shared_ptr engine); ~RelationalSyncAbleStorage() override; @@ -120,9 +123,43 @@ public: int GetRemoteDeviceSchema(const std::string &deviceId, RelationalSchemaObject &schemaObj) override; void ReleaseRemoteQueryContinueToken(ContinueToken &token) const override; + + int StartTransaction(TransactType type) override; + + int Commit() override; + + int Rollback() override; + + int GetUploadCount(const std::string &tableName, const Timestamp ×tamp, int64_t &count) override; + + int FillCloudGid(const CloudSyncData &data) override; + + int GetCloudData(const TableSchema &tableSchema, const Timestamp &beginTime, + ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) override; + + int GetCloudDataNext(ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) override; + + int ReleaseCloudDataToken(ContinueToken &continueStmtToken) override; + + void InitSchemaMgr(ICloudSyncStorageInterface *store); + + int ChkSchema(const TableName &tableName) override; + + int SetCloudDbSchema(const DataBaseSchema &schema) override; + + int GetCloudDbSchema(DataBaseSchema &cloudSchema) override; + + int GetCloudTableSchema(const TableName &tableName, TableSchema &tableSchema) override; + + int GetLogInfoByPrimaryKeyOrGid(const std::string &tableName, const VBucket &vBucket, LogInfo &logInfo) override; + + int PutCloudSyncData(const std::string &tableName, const DownloadData &downloadData) override; + private: SQLiteSingleVerRelationalStorageExecutor *GetHandle(bool isWrite, int &errCode, OperatePerm perm = OperatePerm::NORMAL_PERM) const; + SQLiteSingleVerRelationalStorageExecutor *GetHandleExpectTransaction(bool isWrite, int &errCode, + OperatePerm perm = OperatePerm::NORMAL_PERM) const; void ReleaseHandle(SQLiteSingleVerRelationalStorageExecutor *&handle) const; // get @@ -150,6 +187,12 @@ private: mutable std::mutex securityOptionMutex_; mutable SecurityOption securityOption_; mutable bool isCachedOption_; + + SQLiteSingleVerRelationalStorageExecutor *transactionHandle_ = nullptr; + mutable std::shared_mutex transactionMutex_; // used for transaction + + std::shared_ptr schemaMgr_; + mutable std::shared_mutex schemaMgrMutex_; }; } // namespace DistributedDB #endif diff --git a/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp b/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp index 1dbabc517ce0724c432cb55d1798f5bf1ef2a2bd..88fae3bd2c80885f8f99c9cbbf924b76629ff452 100644 --- a/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp @@ -15,12 +15,15 @@ #ifdef RELATIONAL_STORE #include "runtime_config.h" +#include "db_common.h" #include "db_constant.h" #include "db_dfx_adapter.h" +#include "db_properties.h" #include "kvdb_manager.h" #include "kv_store_errno.h" #include "log_print.h" #include "network_adapter.h" +#include "param_check_utils.h" #include "runtime_context.h" namespace DistributedDB { @@ -128,5 +131,48 @@ DBStatus RuntimeConfig::SetPermissionConditionCallback(const PermissionCondition int errCode = RuntimeContext::GetInstance()->SetPermissionConditionCallback(callback); return TransferDBErrno(errCode); } + +void RuntimeConfig::SetTranslateToDeviceIdCallback(const DistributedDB::TranslateToDeviceIdCallback &callback) +{ + RuntimeContext::GetInstance()->SetTranslateToDeviceIdCallback(callback); +} + +void RuntimeConfig::SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBType type) +{ + DBTypeInner innerType = (type == DBType::DB_KV ? DBTypeInner::DB_KV : DBTypeInner::DB_RELATION); + RuntimeContext::GetInstance()->SetAutoLaunchRequestCallback(callback, innerType); +} + +std::string RuntimeConfig::GetStoreIdentifier(const std::string &userId, const std::string &appId, + const std::string &storeId, bool syncDualTupleMode) +{ + if (!ParamCheckUtils::CheckStoreParameter(storeId, appId, userId, syncDualTupleMode)) { + return ""; + } + if (syncDualTupleMode) { + return DBCommon::TransferHashString(appId + "-" + storeId); + } + return DBCommon::TransferHashString(userId + "-" + appId + "-" + storeId); +} + +void RuntimeConfig::ReleaseAutoLaunch(const std::string &userId, const std::string &appId, const std::string &storeId, + DBType type) +{ + DBProperties properties; + properties.SetIdentifier(userId, appId, storeId); + + DBTypeInner innerType = (type == DBType::DB_KV ? DBTypeInner::DB_KV : DBTypeInner::DB_RELATION); + RuntimeContext::GetInstance()->CloseAutoLaunchConnection(innerType, properties); +} + +void RuntimeConfig::SetThreadPool(const std::shared_ptr &threadPool) +{ + RuntimeContext::GetInstance()->SetThreadPool(threadPool); +} + +void RuntimeConfig::SetCloudTranslate(const std::shared_ptr &dataTranslate) +{ + RuntimeContext::GetInstance()->SetCloudTranslate(dataTranslate); +} } // namespace DistributedDB #endif \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/include/cloud/cloud_meta_data.h b/frameworks/libs/distributeddb/storage/include/cloud/cloud_meta_data.h new file mode 100644 index 0000000000000000000000000000000000000000..bd0030a267ae69f307c72a4887f7ed899b152967 --- /dev/null +++ b/frameworks/libs/distributeddb/storage/include/cloud/cloud_meta_data.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 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 CLOUD_META_DATA_H +#define CLOUD_META_DATA_H + +#include +#include +#include + +#include "cloud_store_types.h" +#include "db_types.h" +#include "icloud_sync_storage_interface.h" +#include "types_export.h" + +namespace DistributedDB { + +class CloudMetaData { +public: + explicit CloudMetaData(ICloudSyncStorageInterface *store); + ~CloudMetaData() = default; + + int GetLocalWaterMark(TableName tableName, LocalWaterMark &localMark); + int GetCloudWaterMark(TableName tableName, CloudWaterMark &cloudMark); + + int SetLocalWaterMark(TableName tableName, LocalWaterMark localMark); + int SetCloudWaterMark(TableName tableName, CloudWaterMark &cloudMark); + +private: + typedef struct CloudMetaValue { + LocalWaterMark localMark; + CloudWaterMark cloudMark; + } CloudMetaValue; + + int ReadMarkFromMeta(const TableName &tableName); + int WriteMarkToMeta(TableName &tableName, LocalWaterMark localmark, CloudWaterMark &cloudMark); + int SerializeMark(TableName tableName, LocalWaterMark localMark, CloudWaterMark &cloudMark, Value &blobMeta); + int DeserializeMark(Value &blobMark, CloudMetaValue &cloudMetaValue); + Key PrefixTableName(const TableName &tableName); + + mutable std::mutex cloudMetaMutex_; + std::unordered_map cloudMetaVals_; + ICloudSyncStorageInterface *store_ = nullptr; +}; + +} // namespace DistributedDB +#endif // DISTRIBUTEDDB_TYPES_EXPORT_H diff --git a/frameworks/libs/distributeddb/storage/include/cloud/schema_mgr.h b/frameworks/libs/distributeddb/storage/include/cloud/schema_mgr.h new file mode 100644 index 0000000000000000000000000000000000000000..9c55164ba04bab6781c6a7ecacd63f33dc5bad2a --- /dev/null +++ b/frameworks/libs/distributeddb/storage/include/cloud/schema_mgr.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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 SCHEMA_MGR_H +#define SCHEMA_MGR_H + +#include +#include +#include + +#include "cloud_store_types.h" +#include "icloud_sync_storage_interface.h" +#include "relational_schema_object.h" + +namespace DistributedDB { +class SchemaMgr { +public: + explicit SchemaMgr(ICloudSyncStorageInterface *store); + ~SchemaMgr() =default; + void SetCloudDbSchema(const DataBaseSchema &schema); + std::shared_ptr GetCloudDbSchema(); + int GetTableSchema(const TableName &tableName, TableSchema &retSchema); + int ChkSchema(const TableName &tableName); + +private: + bool CompareType(const FieldInfo &localField, const Field &cloudField); + bool CompareNullable(const FieldInfo &localField, const Field &cloudField); + bool CompareIsPrimary(std::map &localPrimaryKeys, const Field &cloudField); + int CompareFieldSchema(std::map &primaryKeys, FieldInfoMap &localFields, + std::vector &cloudFields); + int GetLocalSchemaFromMeta(RelationalSchemaObject &schema); + std::shared_ptr cloudSchema_ = nullptr; + ICloudSyncStorageInterface *store_ = nullptr; +}; +} // namespace DistributedDB + +#endif // SCHEMA_MGR_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/include/db_properties.h b/frameworks/libs/distributeddb/storage/include/db_properties.h index de5e00dfe67d6ce19ec4153452dd99bbade2c149..aa944c69e1e43e1fe02ff6bc569f2a329c93437e 100644 --- a/frameworks/libs/distributeddb/storage/include/db_properties.h +++ b/frameworks/libs/distributeddb/storage/include/db_properties.h @@ -21,6 +21,9 @@ namespace DistributedDB { class DBProperties { public: + DBProperties() = default; + virtual ~DBProperties() = default; + // Get the string property according the name std::string GetStringProp(const std::string &name, const std::string &defaultValue) const; @@ -54,10 +57,9 @@ public: static const std::string IDENTIFIER_DIR; static const std::string DUAL_TUPLE_IDENTIFIER_DATA; static const std::string SYNC_DUAL_TUPLE_MODE; + static const std::string AUTO_LAUNCH_ID; protected: - DBProperties() = default; - virtual ~DBProperties() = default; std::map stringProperties_; std::map boolProperties_; diff --git a/frameworks/libs/distributeddb/storage/include/icloud_sync_storage_interface.h b/frameworks/libs/distributeddb/storage/include/icloud_sync_storage_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..ebdaf8fefe262e8bef5d531e66880ab9ada2c8ce --- /dev/null +++ b/frameworks/libs/distributeddb/storage/include/icloud_sync_storage_interface.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023 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 RELATIONAL_DB_CLOUD_INTERFACE_H +#define RELATIONAL_DB_CLOUD_INTERFACE_H + +#include "cloud/cloud_db_types.h" +#include "data_transformer.h" +#include "sqlite_utils.h" + +namespace DistributedDB { +struct TableSchema; + +enum class OpType : uint8_t { + INSERT = 1, + UPDATE, // update data, gid and timestamp at same time + DELETE, + ONLY_UPDATE_GID, + NOT_HANDLE +}; + +typedef struct DownloadData { + std::vector data; + std::vector opType; +} DownloadData; + +class ICloudSyncStorageInterface { +public: + ICloudSyncStorageInterface() = default; + virtual ~ICloudSyncStorageInterface() = default; + + virtual int GetMetaData(const Key &key, Value &value) const = 0; + + virtual int PutMetaData(const Key &key, const Value &value) = 0; + + virtual int ChkSchema(const TableName &tableName) = 0; + + virtual int SetCloudDbSchema(const DataBaseSchema &schema) = 0; + + virtual int GetCloudDbSchema(DataBaseSchema &cloudSchema) = 0; + + virtual int GetCloudTableSchema(const TableName &tableName, TableSchema &tableSchema) = 0; + + virtual int StartTransaction(TransactType type) = 0; + + virtual int Commit() = 0; + + virtual int Rollback() = 0; + + virtual int GetUploadCount(const std::string &tableName, const Timestamp ×tamp, int64_t &count) = 0; + + virtual int FillCloudGid(const CloudSyncData &data) = 0; + + virtual int GetCloudData(const TableSchema &tableSchema, const Timestamp &beginTime, + ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) = 0; + + virtual int GetCloudDataNext(ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) = 0; + + virtual int ReleaseCloudDataToken(ContinueToken &continueStmtToken) = 0; + + virtual int GetLogInfoByPrimaryKeyOrGid(const std::string &tableName, const VBucket &vBucket, LogInfo &logInfo) = 0; + + virtual int PutCloudSyncData(const std::string &tableName, const DownloadData &downloadData) = 0; +}; +} + +#endif //RELATIONAL_DB_CLOUD_INTERFACE_H diff --git a/frameworks/libs/distributeddb/storage/include/ikvdb_connection.h b/frameworks/libs/distributeddb/storage/include/ikvdb_connection.h index 8cfebe8f0402977c7f02edb0a5536968de4350d0..eec37ba70d14b129cb7644af9931d64db2f23eaf 100644 --- a/frameworks/libs/distributeddb/storage/include/ikvdb_connection.h +++ b/frameworks/libs/distributeddb/storage/include/ikvdb_connection.h @@ -131,6 +131,8 @@ public: virtual int GetKeys(const IOption &option, const Key &keyPrefix, std::vector &keys) const = 0; virtual int GetSyncDataSize(const std::string &device, size_t &size) const = 0; + + virtual int UpdateKey(const UpdateKeyCallback &callback) = 0; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/storage/include/isync_interface.h b/frameworks/libs/distributeddb/storage/include/isync_interface.h index d64b3bbaff6f7f0ae708ff90a24957784910f7df..893305b188d1331d9c7836318cb8df76e55031a8 100644 --- a/frameworks/libs/distributeddb/storage/include/isync_interface.h +++ b/frameworks/libs/distributeddb/storage/include/isync_interface.h @@ -67,6 +67,8 @@ public: virtual int GetAllMetaKeys(std::vector &keys) const = 0; virtual const DBProperties &GetDbProperties() const = 0; + + virtual int GetSecurityOption(SecurityOption &option) const = 0; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/storage/include/kvdb_manager.h b/frameworks/libs/distributeddb/storage/include/kvdb_manager.h index 1cb680d80fa6c39812ae3cc1eece00fd07e349c3..88f028cda8699b0fc63edc3be2fcc73d3741ed0c 100644 --- a/frameworks/libs/distributeddb/storage/include/kvdb_manager.h +++ b/frameworks/libs/distributeddb/storage/include/kvdb_manager.h @@ -133,6 +133,8 @@ private: static std::atomic instance_; static std::mutex kvDBLock_; static std::mutex instanceLock_; + + static std::mutex fileHandleMutex_; static std::map locks_; std::map localKvDBs_; diff --git a/frameworks/libs/distributeddb/storage/include/relational_store_connection.h b/frameworks/libs/distributeddb/storage/include/relational_store_connection.h index 202b5f52debdf637f1a2be9b1207bff4cdf7f913..11eb3513028c6413a7af7838cfb4470c42f15fe0 100644 --- a/frameworks/libs/distributeddb/storage/include/relational_store_connection.h +++ b/frameworks/libs/distributeddb/storage/include/relational_store_connection.h @@ -50,14 +50,20 @@ public: virtual int Close() = 0; virtual int SyncToDevice(SyncInfo &info) = 0; virtual std::string GetIdentifier() = 0; - virtual int CreateDistributedTable(const std::string &tableName) = 0; + virtual int CreateDistributedTable(const std::string &tableName, TableSyncType syncType) = 0; virtual int RegisterLifeCycleCallback(const DatabaseLifeCycleNotifier ¬ifier) = 0; + virtual int RemoveDeviceData() = 0; virtual int RemoveDeviceData(const std::string &device) = 0; virtual int RemoveDeviceData(const std::string &device, const std::string &tableName) = 0; virtual void RegisterObserverAction(const RelationalObserverAction &action) = 0; virtual int RemoteQuery(const std::string &device, const RemoteCondition &condition, uint64_t timeout, std::shared_ptr &result) = 0; + virtual int SetCloudDB(const std::shared_ptr &cloudDb) = 0; + virtual int SetCloudDbSchema(const DataBaseSchema &schema) = 0; + + virtual int Sync(const std::vector &devices, SyncMode mode, const Query &query, + const std::function &onProcess, int64_t waitTime) = 0; protected: // Get the stashed 'RelationalDB_ pointer' without ref. diff --git a/frameworks/libs/distributeddb/storage/include/storage_proxy.h b/frameworks/libs/distributeddb/storage/include/storage_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..b4a90f23d873a42a84ce510cc9ad35fa71346ea0 --- /dev/null +++ b/frameworks/libs/distributeddb/storage/include/storage_proxy.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023 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 STORAGE_PROXY_H +#define STORAGE_PROXY_H + +#include +#include + +#include "cloud_store_types.h" +#include "cloud/cloud_meta_data.h" +#include "cloud/cloud_db_constant.h" +#include "cloud/schema_mgr.h" +#include "data_transformer.h" +#include "icloud_sync_storage_interface.h" + + +namespace DistributedDB { +class StorageProxy { +public: + ~StorageProxy() = default; + + static std::shared_ptr GetCloudDb(ICloudSyncStorageInterface *iCloud); + + int Close(); + + int GetLocalWaterMark(const std::string &tableName, LocalWaterMark &localMark); + + int PutLocalWaterMark(const std::string &tableName, LocalWaterMark &localMark); + + int GetCloudWaterMark(const std::string &tableName, CloudWaterMark &cloudMark); + + int PutCloudWaterMark(const std::string &tableName, CloudWaterMark &cloudMark); + + int StartTransaction(TransactType type = TransactType::DEFERRED); + + int Commit(); + + int Rollback(); + + int GetUploadCount(const std::string &tableName, const LocalWaterMark ×tamp, int64_t &count); + + int FillCloudGid(const CloudSyncData &data); + + int GetCloudData(const std::string &tableName, const Timestamp &timeRange, + ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult); + + int GetCloudDataNext(ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) const; + + int GetLogInfoByPrimaryKeyOrGid(const std::string &tableName, const VBucket &vBucket, LogInfo &logInfo); + + int PutCloudSyncData(const std::string &tableName, const DownloadData &downloadData); + + int CheckSchema(const TableName &tableName) const; + + int CheckSchema(std::vector &tables); + + int ReleaseContinueToken(ContinueToken &continueStmtToken); + +private: + StorageProxy(ICloudSyncStorageInterface *iCloud); + void Init(); + + ICloudSyncStorageInterface *store_; + mutable std::shared_mutex storeMutex_; + mutable std::shared_mutex cloudDbMutex_; + std::atomic transactionExeFlag_; + std::shared_ptr cloudMetaData_; + std::atomic isWrite_; +}; +} + +#endif //STORAGE_PROXY_H diff --git a/frameworks/libs/distributeddb/storage/include/sync_generic_interface.h b/frameworks/libs/distributeddb/storage/include/sync_generic_interface.h index 3954a4d0d21f6a67ad29d36619e8db3d9ecc6f44..1e3e2d52291782b37e11697307631d01795bacc8 100644 --- a/frameworks/libs/distributeddb/storage/include/sync_generic_interface.h +++ b/frameworks/libs/distributeddb/storage/include/sync_generic_interface.h @@ -83,7 +83,7 @@ public: return true; } - virtual int GetSecurityOption(SecurityOption &option) const + int GetSecurityOption(SecurityOption &option) const override { return -E_NOT_SUPPORT; } diff --git a/frameworks/libs/distributeddb/storage/src/cloud/cloud_meta_data.cpp b/frameworks/libs/distributeddb/storage/src/cloud/cloud_meta_data.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d5a5b949e49732620a4cce87e6cc23a0d643f782 --- /dev/null +++ b/frameworks/libs/distributeddb/storage/src/cloud/cloud_meta_data.cpp @@ -0,0 +1,153 @@ +#include "cloud/cloud_meta_data.h" + +#include + +#include "cloud/cloud_db_constant.h" +#include "db_errno.h" +#include "parcel.h" + +namespace DistributedDB { + +CloudMetaData::CloudMetaData(ICloudSyncStorageInterface *store) + : store_(store) +{ +} + +Key CloudMetaData::PrefixTableName(const TableName &tableName) +{ + TableName newName = CloudDbConstant::CLOUD_META_TABLE_PREFIX + tableName; + Key prefixedTableName(newName.begin(), newName.end()); + return prefixedTableName; +} + +int CloudMetaData::GetLocalWaterMark(TableName tableName, LocalWaterMark &localMark) +{ + std::lock_guard lock(cloudMetaMutex_); + if (cloudMetaVals_.count(tableName) == 0) { + int ret = ReadMarkFromMeta(tableName); + if (ret != E_OK) { + return ret; + } + } + localMark = cloudMetaVals_[tableName].localMark; + return E_OK; +} + +int CloudMetaData::GetCloudWaterMark(TableName tableName, CloudWaterMark &cloudMark) +{ + std::lock_guard lock(cloudMetaMutex_); + if (cloudMetaVals_.count(tableName) == 0) { + int ret = ReadMarkFromMeta(tableName); + if (ret != E_OK) { + return ret; + } + } + cloudMark = cloudMetaVals_[tableName].cloudMark; + return E_OK; +} + +int CloudMetaData::SetLocalWaterMark(TableName tableName, LocalWaterMark localMark) +{ + std::lock_guard lock(cloudMetaMutex_); + CloudWaterMark cloudMark = ""; + auto iter = cloudMetaVals_.find(tableName); + if (iter != cloudMetaVals_.end()) { + cloudMark = iter->second.cloudMark; + } + int ret = WriteMarkToMeta(tableName, localMark, cloudMark); + if (ret != E_OK) { + return ret; + } + if (iter == cloudMetaVals_.end()) { + CloudMetaValue cloudMetaVal = { .localMark = localMark, .cloudMark = cloudMark }; + cloudMetaVals_[tableName] = cloudMetaVal; + } else { + iter->second.localMark = localMark; + } + return ret; +} + +int CloudMetaData::SetCloudWaterMark(TableName tableName, CloudWaterMark &cloudMark) +{ + std::lock_guard lock(cloudMetaMutex_); + LocalWaterMark localMark = 0; + auto iter = cloudMetaVals_.find(tableName); + if (iter != cloudMetaVals_.end()) { + localMark = iter->second.localMark; + } + int ret = WriteMarkToMeta(tableName, localMark, cloudMark); + if (ret != E_OK) { + return ret; + } + if (iter == cloudMetaVals_.end()) { + CloudMetaValue cloudMetaVal = { .localMark = localMark, .cloudMark = cloudMark }; + cloudMetaVals_[tableName] = cloudMetaVal; + } else { + iter->second.cloudMark = cloudMark; + } + return ret; +} + +int CloudMetaData::ReadMarkFromMeta(const TableName &tableName) +{ + if (store_ == nullptr) { + return -E_INVALID_DB; + } + Value blobMetaVal; + CloudMetaValue cloudMetaValue; + int ret = store_->GetMetaData(PrefixTableName(tableName), blobMetaVal); + if (ret != -E_NOT_FOUND && ret != E_OK) { + return ret; + } + ret = DeserializeMark(blobMetaVal, cloudMetaValue); + if (ret != E_OK) { + return ret; + } + cloudMetaVals_[tableName] = cloudMetaValue; + return E_OK; +} + +int CloudMetaData::WriteMarkToMeta(TableName &tableName, LocalWaterMark localmark, CloudWaterMark &cloudMark) +{ + Value blobMetaVal; + int ret = SerializeMark(tableName, localmark, cloudMark, blobMetaVal); + if (ret != E_OK) { + return ret; + } + if (store_ == nullptr) { + return -E_INVALID_DB; + } + return store_->PutMetaData(PrefixTableName(tableName), blobMetaVal); +} + +int CloudMetaData::SerializeMark(TableName tableName, LocalWaterMark localMark, CloudWaterMark &cloudMark, Value &blobMeta) +{ + uint64_t length = Parcel::GetUInt64Len() + Parcel::GetStringLen(cloudMark); + blobMeta.resize(length); + Parcel parcel(blobMeta.data(), blobMeta.size()); + parcel.WriteUInt64(localMark); + parcel.WriteString(cloudMark); + if (parcel.IsError()) { + LOGE("[Meta] Parcel error while serializing cloud meta data."); + return -E_PARSE_FAIL; + } + return E_OK; +} + +int CloudMetaData::DeserializeMark(Value &blobMark, CloudMetaValue &cloudMetaValue) +{ + if (blobMark.empty()) { + cloudMetaValue.localMark = 0; + cloudMetaValue.cloudMark = ""; + return E_OK; + } + Parcel parcel(blobMark.data(), blobMark.size()); + parcel.ReadUInt64(cloudMetaValue.localMark); + parcel.ReadString(cloudMetaValue.cloudMark); + if (parcel.IsError()) { + LOGE("[Meta] Parcel error while deserializing cloud meta data."); + return -E_PARSE_FAIL; + } + return E_OK; +} +} // namespace DistributedDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/cloud/schema_mgr.cpp b/frameworks/libs/distributeddb/storage/src/cloud/schema_mgr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cce5668dc9523f119896d59894cab406293e9aff --- /dev/null +++ b/frameworks/libs/distributeddb/storage/src/cloud/schema_mgr.cpp @@ -0,0 +1,167 @@ +#include "cloud/schema_mgr.h" + +#include + +#include "cloud_store_types.h" +#include "db_common.h" +#include "db_errno.h" +namespace DistributedDB { +SchemaMgr::SchemaMgr(ICloudSyncStorageInterface *store) + :store_(store) +{ +} + +int SchemaMgr::ChkSchema(const TableName &tableName) +{ + if (cloudSchema_ == nullptr) { + LOGE("Cloud schema has not been set:%d", -E_SCHEMA_NOT_SET); + return -E_SCHEMA_NOT_SET; + } + TableSchema cloudTableSchema; + int ret = GetTableSchema(tableName, cloudTableSchema); + if (ret != E_OK) { + LOGE("Cloud schema does not contain certain table:%d", -E_SCHEMA_MISMATCH); + return -E_SCHEMA_MISMATCH; + } + RelationalSchemaObject localSchema; + ret = GetLocalSchemaFromMeta(localSchema); + if (ret != E_OK) { + return ret; + } + TableInfo tableInfo = localSchema.GetTable(tableName); + if (tableInfo.Empty()) { + LOGE("Local schema does not contain certain table:%d", -E_SCHEMA_MISMATCH); + return -E_SCHEMA_MISMATCH; + } + std::map primaryKeys = tableInfo.GetPrimaryKey(); + FieldInfoMap localFields = tableInfo.GetFields(); + return CompareFieldSchema(primaryKeys, localFields, cloudTableSchema.fields); +} + +int SchemaMgr::CompareFieldSchema(std::map &primaryKeys, FieldInfoMap &localFields, + std::vector &cloudFields) +{ + std::unordered_set cloudColNames; + for (Field &cloudField : cloudFields) { + if (localFields.find(cloudField.colName) == localFields.end()) { + LOGE("Column name mismatch between local and cloud schema: %d", -E_SCHEMA_MISMATCH); + return -E_SCHEMA_MISMATCH; + } + FieldInfo &localField = localFields[cloudField.colName]; + if (CompareType(localField, cloudField) == false) { + LOGE("Type mismatch between local and cloud schema : %d", -E_SCHEMA_MISMATCH); + return -E_SCHEMA_MISMATCH; + } + if (CompareNullable(localField, cloudField) == false) { + LOGE("The nullable property is mismatched between local and cloud schema : %d", -E_SCHEMA_MISMATCH); + return -E_SCHEMA_MISMATCH; + } + if (CompareIsPrimary(primaryKeys, cloudField) == false) { + LOGE("The primary key property is mismatched between local and cloud schema : %d", -E_SCHEMA_MISMATCH); + return -E_SCHEMA_MISMATCH; + } + cloudColNames.emplace(cloudField.colName); + } + if (primaryKeys.size() > 0) { + LOGE("Local schema contain extra primary key:%d", -E_SCHEMA_MISMATCH); + return -E_SCHEMA_MISMATCH; + } + for (auto [fieldName, fieldInfo] : localFields) { + if (fieldInfo.HasDefaultValue() == false && cloudColNames.find(fieldName) == cloudColNames.end()) { + LOGE("Column from local schema is not within cloud schema but doesn't have default value : %d", -E_SCHEMA_MISMATCH); + return -E_SCHEMA_MISMATCH; + } + } + return E_OK; +} + +bool SchemaMgr::CompareType(const FieldInfo &localField, const Field &cloudField) +{ + StorageType localType = localField.GetStorageType(); + switch (cloudField.type) + { + case TYPE_INDEX: + return localType == StorageType::STORAGE_TYPE_NULL; + case TYPE_INDEX: + case TYPE_INDEX: + return localType == StorageType::STORAGE_TYPE_INTEGER; + case TYPE_INDEX: + return localType == StorageType::STORAGE_TYPE_REAL; + case TYPE_INDEX: + return localType == StorageType::STORAGE_TYPE_TEXT; + case TYPE_INDEX: + case TYPE_INDEX: + case TYPE_INDEX: + return localType == StorageType::STORAGE_TYPE_BLOB; + default: + return false; + } + return false; +} + +bool SchemaMgr::CompareNullable(const FieldInfo &localField, const Field &cloudField) +{ + return localField.IsNotNull() == !cloudField.nullable; +} + +bool SchemaMgr::CompareIsPrimary(std::map &localPrimaryKeys, const Field &cloudField) +{ + // whether the corresponding field in local schema is primary key + bool isLocalFieldPrimary = false; + for (auto kvPair : localPrimaryKeys) { + if (kvPair.second == cloudField.colName) { + isLocalFieldPrimary = true; + localPrimaryKeys.erase(kvPair.first); + break; + } + } + return isLocalFieldPrimary == cloudField.primary; +} + +void SchemaMgr::SetCloudDbSchema(const DataBaseSchema &schema) +{ + cloudSchema_ = std::make_shared(schema); +} + +std::shared_ptr SchemaMgr::GetCloudDbSchema() +{ + return cloudSchema_; +} + +int SchemaMgr::GetTableSchema(const TableName &tableName, TableSchema &retSchema) +{ + if (cloudSchema_ == nullptr) { + return -E_SCHEMA_NOT_SET; + } + for (const TableSchema &tableSchema : cloudSchema_->tables) { + if (tableSchema.name == tableName) { + retSchema = tableSchema; + return E_OK; + } + } + return -E_NOT_FOUND; +} + +int SchemaMgr::GetLocalSchemaFromMeta(RelationalSchemaObject &schema) +{ + Key schemaKey; + DBCommon::StringToVector(DBConstant::RELATIONAL_SCHEMA_KEY, schemaKey); + Value schemaVal; + int ret = store_->GetMetaData(schemaKey, schemaVal); + if (ret != E_OK && ret != -E_NOT_FOUND) { + LOGE("Get local schema from meta table failed. %d", ret); + return ret; + } else if (ret == -E_NOT_FOUND || schemaVal.empty()) { + LOGW("Local schema info was not found."); + return -E_NOT_FOUND; + } + std::string schemaStr; + DBCommon::VectorToString(schemaVal, schemaStr); + ret = schema.ParseFromSchemaString(schemaStr); + if (ret != E_OK) { + LOGE("Parse schema string from meta table failed."); + return ret; + } + return E_OK; +} +} // namespace DistributedDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/data_transformer.h b/frameworks/libs/distributeddb/storage/src/data_transformer.h index 1dfe6edd41c2f2678f8e1b613065e8431daca22b..58367fd0e4f3b32bed3415db229a878dee27bba2 100644 --- a/frameworks/libs/distributeddb/storage/src/data_transformer.h +++ b/frameworks/libs/distributeddb/storage/src/data_transformer.h @@ -17,6 +17,7 @@ #ifdef RELATIONAL_STORE #include + #include "data_value.h" #include "db_types.h" #include "relational_schema_object.h" @@ -33,6 +34,7 @@ struct LogInfo { Timestamp wTimestamp = 0; uint64_t flag = 0; Key hashKey; // primary key hash value + std::string cloudGid; // use for sync with cloud }; struct RowDataWithLog { diff --git a/frameworks/libs/distributeddb/storage/src/db_properties.cpp b/frameworks/libs/distributeddb/storage/src/db_properties.cpp index fc7d48b4ed4ea3ea994ca3ed06e24b6bb0d62ea3..a1292eac225c5adb38cb78d0aae64fd524797f29 100644 --- a/frameworks/libs/distributeddb/storage/src/db_properties.cpp +++ b/frameworks/libs/distributeddb/storage/src/db_properties.cpp @@ -28,6 +28,7 @@ const std::string DBProperties::IDENTIFIER_DATA = "identifier"; const std::string DBProperties::IDENTIFIER_DIR = "identifierDir"; const std::string DBProperties::DUAL_TUPLE_IDENTIFIER_DATA = "dualTupleIdentifier"; const std::string DBProperties::SYNC_DUAL_TUPLE_MODE = "syncDualTuple"; +const std::string DBProperties::AUTO_LAUNCH_ID = "autoLaunchID"; std::string DBProperties::GetStringProp(const std::string &name, const std::string &defaultValue) const { diff --git a/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp b/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp index 3ff72c7dfed4eaeb8b5cca3e2dd0b42a25f169ad..13544d3e22b19143d12bddb18ac7917c6eb3b9da 100644 --- a/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp +++ b/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp @@ -55,8 +55,12 @@ const KvDBProperties &GenericKvDB::GetMyProperties() const IKvDBConnection *GenericKvDB::GetDBConnection(int &errCode) { std::lock_guard lock(connectMutex_); - if (operatePerm_ != OperatePerm::NORMAL_PERM) { - errCode = (operatePerm_ == OperatePerm::DISABLE_PERM) ? -E_STALE : -E_BUSY; + if (operatePerm_ == OperatePerm::DISABLE_PERM) { + errCode = -E_STALE; + return nullptr; + } else if (operatePerm_ == OperatePerm::REKEY_MONOPOLIZE_PERM || + operatePerm_ == OperatePerm::IMPORT_MONOPOLIZE_PERM) { + errCode = -E_BUSY; return nullptr; } @@ -157,11 +161,11 @@ int GenericKvDB::TryToDisableConnection(OperatePerm perm) if (operatePerm_ != OperatePerm::NORMAL_PERM) { return -E_BUSY; } - // more than one connection, should prevent the rekey operation. - if (connectionCount_ > 1) { + // more than one connection, should prevent the rekey/import operation. + if ((perm == OperatePerm::REKEY_MONOPOLIZE_PERM || perm == OperatePerm::IMPORT_MONOPOLIZE_PERM) && + connectionCount_ > 1) { return -E_BUSY; } - operatePerm_ = perm; return E_OK; } diff --git a/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp b/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp index 7e6047d1a3363da37f5c7ee9eb769cf2c36db1f8..9bd0b60c3c11573350d6cf6baa2f244ace65e02b 100644 --- a/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp +++ b/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp @@ -356,4 +356,9 @@ int GenericKvDBConnection::GetSyncDataSize(const std::string &device, size_t &si { return -E_NOT_SUPPORT; } + +int GenericKvDBConnection::UpdateKey(const UpdateKeyCallback &callback) +{ + return -E_NOT_SUPPORT; +} } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.h b/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.h index d99aa4d6d42bd741dd246bc3a7a639fc90ac38e4..09c1088bf01cc292dbd629c35a767a6017c0713e 100644 --- a/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.h +++ b/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.h @@ -78,6 +78,8 @@ public: int GetKeys(const IOption &option, const Key &keyPrefix, std::vector &keys) const override; int GetSyncDataSize(const std::string &device, size_t &size) const override; + + int UpdateKey(const UpdateKeyCallback &callback) override; protected: // Get the stashed 'KvDB_ pointer' without ref. template diff --git a/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp b/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp index 16ba90fa04a87bf7b95ad70dbb8c9b9b5d97d4f2..40bce7c091f9c7812d1a278bac2ee91ba6e82e0a 100644 --- a/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp +++ b/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp @@ -29,6 +29,7 @@ std::atomic KvDBManager::instance_{nullptr}; std::mutex KvDBManager::kvDBLock_; std::mutex KvDBManager::instanceLock_; std::map KvDBManager::locks_; +std::mutex KvDBManager::fileHandleMutex_; namespace { DefaultFactory g_defaultFactory; @@ -206,9 +207,12 @@ int KvDBManager::TryLockDB(const KvDBProperties &kvDBProp, int retryTimes) return E_OK; } - if (locks_.count(id) != 0) { - LOGI("db has been locked!"); - return E_OK; + { + std::lock_guard autoLock(fileHandleMutex_); + if (locks_.count(id) != 0) { + LOGI("db has been locked!"); + return E_OK; + } } std::string hexHashId = DBCommon::TransferStringToHex((id)); @@ -223,6 +227,7 @@ int KvDBManager::TryLockDB(const KvDBProperties &kvDBProp, int retryTimes) errCode = OS::FileLock(handle, false); // not block process if (errCode == E_OK) { LOGI("[%s]locked!", STR_MASK(DBCommon::TransferStringToHex(KvDBManager::GenerateKvDBIdentifier(kvDBProp)))); + std::lock_guard autoLock(fileHandleMutex_); locks_[id] = handle; return errCode; } else if (errCode == -E_BUSY) { @@ -246,19 +251,25 @@ int KvDBManager::UnlockDB(const KvDBProperties &kvDBProp) return E_OK; } std::string identifierDir = KvDBManager::GenerateKvDBIdentifier(kvDBProp); - if (locks_.count(identifierDir) == 0) { - return E_OK; + OS::FileHandle *handle = nullptr; + { + std::lock_guard autoLock(fileHandleMutex_); + if (locks_.count(identifierDir) == 0) { + return E_OK; + } + handle = locks_[identifierDir]; } - int errCode = OS::FileUnlock(locks_[identifierDir]); + int errCode = OS::FileUnlock(handle); if (errCode != E_OK) { LOGE("DB unlocked! errCode = [%d]", errCode); return errCode; } - errCode = OS::CloseFile(locks_[identifierDir]); + errCode = OS::CloseFile(handle); if (errCode != E_OK) { LOGE("DB closed! errCode = [%d]", errCode); return errCode; } + std::lock_guard autoLock(fileHandleMutex_); locks_.erase(identifierDir); return E_OK; } @@ -330,7 +341,8 @@ IKvDBConnection *KvDBManager::GetDatabaseConnection(const KvDBProperties &proper std::string userId = properties.GetStringProp(KvDBProperties::USER_ID, ""); std::string storeId = properties.GetStringProp(KvDBProperties::STORE_ID, ""); manager->DataBaseCorruptNotify(appId, userId, storeId); - LOGE("Database [%s] is corrupted:%d", STR_MASK(DBCommon::TransferStringToHex(identifier)), errCode); + LOGE("Database [%s] is corrupted or invalid passwd:%d", STR_MASK(DBCommon::TransferStringToHex(identifier)), + errCode); } return connection; @@ -434,7 +446,7 @@ IKvDB *KvDBManager::GetDataBase(const KvDBProperties &property, int &errCode, bo kvDB = CreateDataBase(property, errCode); if (errCode != E_OK) { - LOGE("Create data base failed, errCode = [%d]", errCode); + LOGE("Create database failed, errCode = [%d]", errCode); } return kvDB; } diff --git a/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp b/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp index aa8a05cd6cac9ce6ec57644b3fdd698cf0b33c31..f118dcc1c670ba3c62197ceb2cfc7be7f25e3483 100644 --- a/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp @@ -144,7 +144,7 @@ IRelationalStore *RelationalStoreInstance::GetDataBase(const RelationalDBPropert db = manager->OpenDatabase(properties, errCode); if (errCode != E_OK) { - LOGE("Create data base failed, errCode = [%d]", errCode); + LOGE("Create database failed, errCode = [%d]", errCode); } return db; } diff --git a/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp b/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp index 7b6be36816a16d80695449dce5b9e72571abe361..818eac318fabc27cbec61a14494b1f1ce0e7a506 100644 --- a/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp @@ -34,7 +34,7 @@ void TriggerCloseAutoLaunchConn(const RelationalDBProperties &properties) static constexpr const char *CLOSE_CONN_TASK = "auto launch close relational connection"; (void)RuntimeContext::GetInstance()->ScheduleQueuedTask( std::string(CLOSE_CONN_TASK), - [properties] { RuntimeContext::GetInstance()->CloseAutoLaunchConnection(DBType::DB_RELATION, properties); } + [properties] { RuntimeContext::GetInstance()->CloseAutoLaunchConnection(DBTypeInner::DB_RELATION, properties); } ); } } @@ -138,6 +138,25 @@ SQLiteSingleVerRelationalStorageExecutor *RelationalSyncAbleStorage::GetHandle(b return handle; } +SQLiteSingleVerRelationalStorageExecutor *RelationalSyncAbleStorage::GetHandleExpectTransaction(bool isWrite, + int &errCode, OperatePerm perm) const +{ + if (storageEngine_ == nullptr) { + errCode = -E_INVALID_DB; + return nullptr; + } + if (transactionHandle_ != nullptr) { + return transactionHandle_; + } + auto handle = static_cast( + storageEngine_->FindExecutor(isWrite, perm, errCode)); + if (errCode != E_OK) { + ReleaseHandle(handle); + handle = nullptr; + } + return handle; +} + void RelationalSyncAbleStorage::ReleaseHandle(SQLiteSingleVerRelationalStorageExecutor *&handle) const { if (storageEngine_ == nullptr) { @@ -162,9 +181,8 @@ int RelationalSyncAbleStorage::GetMetaData(const Key &key, Value &value) const if (key.size() > DBConstant::MAX_KEY_SIZE) { return -E_INVALID_ARGS; } - int errCode = E_OK; - auto handle = GetHandle(true, errCode, OperatePerm::NORMAL_PERM); + auto *handle = GetHandle(true, errCode, OperatePerm::NORMAL_PERM); if (handle == nullptr) { return errCode; } @@ -478,8 +496,14 @@ int RelationalSyncAbleStorage::SaveSyncDataItems(const QueryObject &object, std: return errCode; } + StoreInfo info = { + storageEngine_->GetProperties().GetStringProp(DBProperties::USER_ID, ""), + storageEngine_->GetProperties().GetStringProp(DBProperties::APP_ID, ""), + storageEngine_->GetProperties().GetStringProp(DBProperties::STORE_ID, "") + }; auto inserter = RelationalSyncDataInserter::CreateInserter(deviceName, query, storageEngine_->GetSchema(), - remoteSchema.GetTable(query.GetTableName()).GetFieldInfos(), dataItems); + remoteSchema.GetTable(query.GetTableName()).GetFieldInfos(), info); + inserter.SetEntries(dataItems); auto *handle = GetHandle(true, errCode, OperatePerm::NORMAL_PERM); if (handle == nullptr) { @@ -604,12 +628,17 @@ int RelationalSyncAbleStorage::CreateDistributedDeviceTable(const std::string &d return errCode; } + StoreInfo info = { + storageEngine_->GetProperties().GetStringProp(DBProperties::USER_ID, ""), + storageEngine_->GetProperties().GetStringProp(DBProperties::APP_ID, ""), + storageEngine_->GetProperties().GetStringProp(DBProperties::STORE_ID, "") + }; for (const auto &[table, strategy] : syncStrategy) { if (!strategy.permitSync) { continue; } - errCode = handle->CreateDistributedDeviceTable(device, storageEngine_->GetSchema().GetTable(table)); + errCode = handle->CreateDistributedDeviceTable(device, storageEngine_->GetSchema().GetTable(table), info); if (errCode != E_OK) { LOGE("Create distributed device table failed. %d", errCode); break; @@ -850,5 +879,234 @@ void RelationalSyncAbleStorage::ReleaseRemoteQueryContinueToken(ContinueToken &t remoteToken = nullptr; token = nullptr; } + +int RelationalSyncAbleStorage::StartTransaction(TransactType type) +{ + std::unique_lock lock(transactionMutex_); + if (transactionHandle_ != nullptr) { + LOGD("Transaction started already."); + return -E_TRANSACT_STATE; + } + int errCode; + auto *handle = static_cast( + storageEngine_->FindExecutor(type == TransactType::IMMEDIATE ? true : false, + OperatePerm::NORMAL_PERM, errCode)); + if (handle == nullptr) { + ReleaseHandle(handle); + return errCode; + } + errCode = handle->StartTransaction(type); + if (errCode != E_OK) { + ReleaseHandle(handle); + return errCode; + } + transactionHandle_ = handle; + return errCode; +} + +int RelationalSyncAbleStorage::Commit() +{ + std::unique_lock lock(transactionMutex_); + if (transactionHandle_ == nullptr) { + LOGE("relation database is null or the transaction has not been started"); + return -E_INVALID_DB; + } + int errCode = transactionHandle_->Commit(); + ReleaseHandle(transactionHandle_); + transactionHandle_ = nullptr; + LOGD("connection commit transaction!"); + return errCode; +} + +int RelationalSyncAbleStorage::Rollback() +{ + std::unique_lock lock(transactionMutex_); + if (transactionHandle_ == nullptr) { + LOGE("Invalid handle for rollback or the transaction has not been started."); + return -E_INVALID_DB; + } + + int errCode = transactionHandle_->Rollback(); + ReleaseHandle(transactionHandle_); + transactionHandle_ = nullptr; + LOGI("connection rollback transaction!"); + return errCode; +} + +int RelationalSyncAbleStorage::GetUploadCount(const std::string &tableName, const Timestamp ×tamp, + int64_t &count) +{ + int errCode; + auto *handle = GetHandleExpectTransaction(false, errCode); + if (handle == nullptr) { + return errCode; + } + errCode = handle->GetUploadCount(tableName, timestamp, count); + if (transactionHandle_ == nullptr) { + ReleaseHandle(handle); + } + return errCode; +} + +int RelationalSyncAbleStorage::FillCloudGid(const CloudSyncData &data) +{ + if (storageEngine_ == nullptr) { + return -E_INVALID_DB; + } + int errCode = E_OK; + auto writeHandle = static_cast( + storageEngine_->FindExecutor(true, OperatePerm::NORMAL_PERM, errCode, 0)); + if (writeHandle == nullptr) { + return errCode; + } + errCode = writeHandle->StartTransaction(TransactType::IMMEDIATE); + if (errCode != E_OK) { + ReleaseHandle(writeHandle); + return errCode; + } + errCode = writeHandle->UpdateCloudLogGid(data); + if (errCode != E_OK) { + writeHandle->Rollback(); + ReleaseHandle(writeHandle); + return errCode; + } + errCode = writeHandle->Commit(); + ReleaseHandle(writeHandle); + return errCode; +} + +int RelationalSyncAbleStorage::GetCloudData(const TableSchema &tableSchema, const Timestamp &beginTime, + ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) +{ + if (transactionHandle_ == nullptr) { + LOGE(" the transaction has not been started"); + return -E_INVALID_DB; + } + SyncTimeRange syncTimeRange = { .beginTime = beginTime }; + QueryObject queryObject; + queryObject.SetTableName(tableSchema.name); + auto token = new (std::nothrow) SQLiteSingleVerRelationalContinueToken(syncTimeRange, queryObject); + if (token == nullptr) { + LOGE("[SingleVerNStore] Allocate continue token failed."); + return -E_OUT_OF_MEMORY; + } + token->SetCloudTableSchema(tableSchema); + continueStmtToken = static_cast(token); + return GetCloudDataNext(continueStmtToken, cloudDataResult); +} + +int RelationalSyncAbleStorage::GetCloudDataNext(ContinueToken &continueStmtToken, + CloudSyncData &cloudDataResult) +{ + if (transactionHandle_ == nullptr) { + LOGE(" the transaction has not been started"); + return -E_INVALID_DB; + } + if (continueStmtToken == nullptr) { + return -E_INVALID_ARGS; + } + auto token = static_cast(continueStmtToken); + if (!token->CheckValid()) { + return -E_INVALID_ARGS; + } + int errCode = transactionHandle_->GetSyncCloudData(cloudDataResult, MAX_UPLOAD_SIZE, *token); + if (errCode != -E_UNFINISHED) { + delete token; + token = nullptr; + } + continueStmtToken = static_cast(token); + return errCode; +} + +int RelationalSyncAbleStorage::ReleaseCloudDataToken(ContinueToken &continueStmtToken) +{ + if (continueStmtToken == nullptr) { + return E_OK; + } + auto token = static_cast(continueStmtToken); + if (!token->CheckValid()) { + return E_OK; + } + int errCode = token->ReleaseCloudStatement(); + delete token; + token = nullptr; + return errCode; +} + +void RelationalSyncAbleStorage::InitSchemaMgr(ICloudSyncStorageInterface *store) +{ + schemaMgr_ = std::make_shared(store); +} + +int RelationalSyncAbleStorage::ChkSchema(const TableName &tableName) +{ + if (schemaMgr_ == nullptr) { + return -E_INVALID_DB; + } + std::unique_lock readLock(schemaMgrMutex_); + return schemaMgr_->ChkSchema(tableName);; +} + +int RelationalSyncAbleStorage::SetCloudDbSchema(const DataBaseSchema &schema) +{ + if (schemaMgr_ == nullptr) { + return -E_INVALID_DB; + } + std::unique_lock writeLock(schemaMgrMutex_); + schemaMgr_->SetCloudDbSchema(schema); + return E_OK; +} + +int RelationalSyncAbleStorage::GetCloudDbSchema(DataBaseSchema &cloudSchema) +{ + if (schemaMgr_ == nullptr) { + return -E_INVALID_DB; + } + std::unique_lock readLock(schemaMgrMutex_); + cloudSchema = *schemaMgr_->GetCloudDbSchema(); + return E_OK; +} + +int RelationalSyncAbleStorage::GetLogInfoByPrimaryKeyOrGid(const std::string &tableName, const VBucket &vBucket, + LogInfo &logInfo) +{ + if (transactionHandle_ == nullptr) { + LOGE(" the transaction has not been started"); + return -E_INVALID_DB; + } + + TableSchema tableSchema; + int errCode = GetCloudTableSchema(tableName, tableSchema); + if (errCode != E_OK) { + LOGE("Get cloud schema failed when query log for cloud sync, %d", errCode); + return errCode; + } + return transactionHandle_->GetLogInfoByPrimaryKeyOrGid(tableSchema, vBucket, logInfo); +} + +int RelationalSyncAbleStorage::PutCloudSyncData(const std::string &tableName, const DownloadData &downloadData) +{ + if (transactionHandle_ == nullptr) { + LOGE(" the transaction has not been started"); + return -E_INVALID_DB; + } + + TableSchema tableSchema; + int errCode = GetCloudTableSchema(tableName, tableSchema); + if (errCode != E_OK) { + LOGE("Get cloud schema failed when save cloud data, %d", errCode); + return errCode; + } + return transactionHandle_->PutCloudSyncData(tableName, downloadData, tableSchema); +} + +int RelationalSyncAbleStorage::GetCloudTableSchema(const TableName &tableName, TableSchema &tableSchema) +{ + if (schemaMgr_ == nullptr) { + return -E_INVALID_DB; + } + std::unique_lock readLock(schemaMgrMutex_); + return schemaMgr_->GetTableSchema(tableName, tableSchema); +} } #endif \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/relational_sync_data_inserter.cpp b/frameworks/libs/distributeddb/storage/src/relational_sync_data_inserter.cpp index aeebb9fe3a3bd65e3fa4438d19adeff4e8f03db2..ef32f7e052bd52af166f246d1a8221af74963970 100644 --- a/frameworks/libs/distributeddb/storage/src/relational_sync_data_inserter.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational_sync_data_inserter.cpp @@ -50,11 +50,10 @@ RelationalSyncDataInserter::~RelationalSyncDataInserter() RelationalSyncDataInserter RelationalSyncDataInserter::CreateInserter(const std::string &deviceName, const QueryObject &query, const RelationalSchemaObject &localSchema, const std::vector &remoteFields, - const std::vector &entries) + const StoreInfo &info) { RelationalSyncDataInserter inserter; - inserter.SetDeviceId(deviceName); - inserter.SetEntries(entries); + inserter.SetHashDevId(DBCommon::TransferStringToHex(DBCommon::TransferHashString(deviceName))); inserter.SetRemoteFields(remoteFields); inserter.SetQuery(query); TableInfo localTable = localSchema.GetTable(query.GetTableName()); @@ -63,14 +62,14 @@ RelationalSyncDataInserter RelationalSyncDataInserter::CreateInserter(const std: if (localSchema.GetTableMode() == DistributedTableMode::COLLABORATION) { inserter.SetInsertTableName(localTable.GetTableName()); } else { - inserter.SetInsertTableName(DBCommon::GetDistributedTableName(deviceName, localTable.GetTableName())); + inserter.SetInsertTableName(DBCommon::GetDistributedTableName(deviceName, localTable.GetTableName(), info)); } return inserter; } -void RelationalSyncDataInserter::SetDeviceId(std::string deviceId) +void RelationalSyncDataInserter::SetHashDevId(const std::string &hashDevId) { - deviceId_ = std::move(deviceId); + hashDevId_ = hashDevId; } void RelationalSyncDataInserter::SetRemoteFields(std::vector remoteFields) @@ -208,9 +207,8 @@ int RelationalSyncDataInserter::GetDeleteSyncDataStmt(sqlite3 *db, sqlite3_stmt int RelationalSyncDataInserter::GetSaveLogStatement(sqlite3 *db, sqlite3_stmt *&logStmt, sqlite3_stmt *&queryStmt) { - std::string devName = DBCommon::TransferHashString(deviceId_); const std::string tableName = DBConstant::RELATIONAL_PREFIX + query_.GetTableName() + "_log"; - std::string dataFormat = "?, '" + deviceId_ + "', ?, ?, ?, ?, ?"; + std::string dataFormat = "?, '" + hashDevId_ + "', ?, ?, ?, ?, ?"; std::string columnList = "data_key, device, ori_device, timestamp, wtimestamp, flag, hash_key"; std::string sql = "INSERT OR REPLACE INTO " + tableName + " (" + columnList + ") VALUES (" + dataFormat + ");"; @@ -251,7 +249,7 @@ int RelationalSyncDataInserter::Iterate(const std::function &s { int errCode = E_OK; for (auto &it : entries_) { - it.dev = deviceId_; + it.dev = hashDevId_; errCode = saveSyncDataItem(it); if (errCode != E_OK) { LOGE("Save sync data item failed. err=%d", errCode); diff --git a/frameworks/libs/distributeddb/storage/src/relational_sync_data_inserter.h b/frameworks/libs/distributeddb/storage/src/relational_sync_data_inserter.h index 0a9bb827492c030c7bcf694c91574e7222575600..e24ba3945d2e7e59e542d38fd28597a56a492f2c 100644 --- a/frameworks/libs/distributeddb/storage/src/relational_sync_data_inserter.h +++ b/frameworks/libs/distributeddb/storage/src/relational_sync_data_inserter.h @@ -45,9 +45,9 @@ public: static RelationalSyncDataInserter CreateInserter(const std::string &deviceName, const QueryObject &query, const RelationalSchemaObject &localSchema, const std::vector &remoteFields, - const std::vector &entries); + const StoreInfo &info); - void SetDeviceId(std::string deviceId); + void SetHashDevId(const std::string &hashDevId); // Set remote fields in cid order void SetRemoteFields(std::vector fields); void SetEntries(std::vector entries); @@ -73,7 +73,7 @@ private: int GetSaveLogStatement(sqlite3 *db, sqlite3_stmt *&logStmt, sqlite3_stmt *&queryStmt); - std::string deviceId_; + std::string hashDevId_; std::vector remoteFields_; std::vector entries_; TableInfo localTable_; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/cloud_sync_log_table_manager.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/cloud_sync_log_table_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f54c6ca805c3906a720ddd74e3a3bca607f33a2d --- /dev/null +++ b/frameworks/libs/distributeddb/storage/src/sqlite/cloud_sync_log_table_manager.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2023 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 "cloud_sync_log_table_manager.h" + +namespace DistributedDB { +std::string CloudSyncLogTableManager::CalcPrimaryKeyHash(const std::string &references, const TableInfo &table, + const std::string &identity) +{ + (void)identity; + std::string sql; + if (table.GetPrimaryKey().size() == 1) { + sql = "calc_hash(" + references + "'" + table.GetPrimaryKey().at(0) + "')"; + } else { + std::set primaryKeySet; // we need sort primary key by name + for (const auto &it : table.GetPrimaryKey()) { + primaryKeySet.emplace(it.second); + } + sql = "calc_hash("; + for (const auto &it : primaryKeySet) { + sql += "calc_hash(" + references + "'" + it + "')||"; + } + sql.pop_back(); + sql.pop_back(); + sql += ")"; + } + return sql; +} + +void CloudSyncLogTableManager::GetIndexSql(const TableInfo &table, std::vector &schema) +{ + const std::string tableName = GetLogTableName(table); + + std::string indexTimestampFlagGid = "CREATE INDEX IF NOT EXISTS " + tableName + + "_cloud_time_flag_gid_index ON " + tableName + "(timestamp, flag, cloud_gid);"; + schema.emplace_back(indexTimestampFlagGid); + + std::string indexHashkey = "CREATE INDEX IF NOT EXISTS " + tableName + + "_cloud_hashkey_index ON " + tableName + "(hash_key);"; + schema.emplace_back(indexHashkey); +} + +std::string CloudSyncLogTableManager::GetPrimaryKeySql(const TableInfo &table) +{ + return "PRIMARY KEY(hash_key)"; +} + +// The parameter "identity" is a hash string that identifies a device. The same for the next two functions. +std::string CloudSyncLogTableManager::GetInsertTrigger(const TableInfo &table, const std::string &identity) +{ + std::string logTblName = DBConstant::RELATIONAL_PREFIX + table.GetTableName() + "_log"; + std::string insertTrigger = "CREATE TRIGGER IF NOT EXISTS "; + insertTrigger += "naturalbase_rdb_" + table.GetTableName() + "_ON_INSERT AFTER INSERT \n"; + insertTrigger += "ON '" + table.GetTableName() + "'\n"; + insertTrigger += "WHEN (SELECT count(*) from " + DBConstant::RELATIONAL_PREFIX + "metadata "; + insertTrigger += "WHERE key = 'log_trigger_switch' AND value = 'true')\n"; + insertTrigger += "BEGIN\n"; + insertTrigger += "\t INSERT OR REPLACE INTO " + logTblName; + insertTrigger += " (data_key, device, ori_device, timestamp, wtimestamp, flag, hash_key, cloud_gid)"; + insertTrigger += " VALUES (new.rowid, '', '',"; + insertTrigger += " get_raw_sys_time(), get_raw_sys_time(), 0x02, "; + insertTrigger += CalcPrimaryKeyHash("NEW.", table, identity) + ", '');\n"; + insertTrigger += "END;"; + return insertTrigger; +} + +std::string CloudSyncLogTableManager::GetUpdateTrigger(const TableInfo &table, const std::string &identity) +{ + std::string logTblName = DBConstant::RELATIONAL_PREFIX + table.GetTableName() + "_log"; + std::string updateTrigger = "CREATE TRIGGER IF NOT EXISTS "; + updateTrigger += "naturalbase_rdb_" + table.GetTableName() + "_ON_UPDATE AFTER UPDATE \n"; + updateTrigger += "ON '" + table.GetTableName() + "'\n"; + updateTrigger += "WHEN (SELECT count(*) from " + DBConstant::RELATIONAL_PREFIX + "metadata "; + updateTrigger += "WHERE key = 'log_trigger_switch' AND value = 'true')\n"; + updateTrigger += "BEGIN\n"; + if (table.GetPrimaryKey().size() == 1 && table.GetPrimaryKey().at(0) == "rowid") { + updateTrigger += "\t UPDATE " + DBConstant::RELATIONAL_PREFIX + table.GetTableName() + "_log"; + updateTrigger += " SET timestamp=get_raw_sys_time(), device='', flag=0x02"; + updateTrigger += " WHERE data_key = OLD.rowid;\n"; + } else { // the row id may be modified + updateTrigger += "\t UPDATE " + logTblName; + updateTrigger += " SET data_key=-1,timestamp=get_raw_sys_time(), device='', flag=0x03"; + updateTrigger += " WHERE hash_key=" + CalcPrimaryKeyHash("OLD.", table, identity) + ";\n"; + updateTrigger += "\t INSERT OR REPLACE INTO " + logTblName + " VALUES (NEW.rowid, '', '', "; + updateTrigger += "get_raw_sys_time(), (select wtimestamp from " + logTblName + " where hash_key = "; + updateTrigger += CalcPrimaryKeyHash("OLD.", table, identity) + "), 0x02, "; + updateTrigger += CalcPrimaryKeyHash("NEW.", table, identity) + ", '');\n"; + } + updateTrigger += "END;"; + return updateTrigger; +} + +std::string CloudSyncLogTableManager::GetDeleteTrigger(const TableInfo &table, const std::string &identity) +{ + (void)identity; + std::string deleteTrigger = "CREATE TRIGGER IF NOT EXISTS "; + deleteTrigger += "naturalbase_rdb_" + table.GetTableName() + "_ON_DELETE BEFORE DELETE \n"; + deleteTrigger += "ON '" + table.GetTableName() + "'\n"; + deleteTrigger += "WHEN (SELECT count(*) from " + DBConstant::RELATIONAL_PREFIX + "metadata "; + deleteTrigger += "WHERE key = 'log_trigger_switch' AND VALUE = 'true')\n"; + deleteTrigger += "BEGIN\n"; + deleteTrigger += "\t UPDATE " + DBConstant::RELATIONAL_PREFIX + table.GetTableName() + "_log"; + deleteTrigger += " SET data_key=-1,flag=0x03,timestamp=get_sys_time(0)"; + deleteTrigger += " WHERE data_key = OLD.rowid;"; + deleteTrigger += "END;"; + return deleteTrigger; +} +} // DistributedDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/cloud_sync_log_table_manager.h b/frameworks/libs/distributeddb/storage/src/sqlite/cloud_sync_log_table_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..13179f4a48484a695387a591a7353c70a0908f1a --- /dev/null +++ b/frameworks/libs/distributeddb/storage/src/sqlite/cloud_sync_log_table_manager.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 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 CLOUD_SYNC_LOG_TABLE_MANAGER_H +#define CLOUD_SYNC_LOG_TABLE_MANAGER_H + +#include "sqlite_log_table_manager.h" + +namespace DistributedDB { +class CloudSyncLogTableManager : public SqliteLogTableManager{ +public: + CloudSyncLogTableManager() = default; + ~CloudSyncLogTableManager() override = default; + + // The parameter "references" is "", "NEW." or "OLD.". "identity" is a hash string that identifies a device. + std::string CalcPrimaryKeyHash(const std::string &references, const TableInfo &table, + const std::string &identity) override; + +private: + void GetIndexSql(const TableInfo &table, std::vector &schema) override; + std::string GetPrimaryKeySql(const TableInfo &table) override; + + // The parameter "identity" is a hash string that identifies a device. The same for the next two functions. + std::string GetInsertTrigger(const TableInfo &table, const std::string &identity) override; + std::string GetUpdateTrigger(const TableInfo &table, const std::string &identity) override; + std::string GetDeleteTrigger(const TableInfo &table, const std::string &identity) override; +}; + +} // DistributedDB + +#endif //DISTRIBUTED_UT_CLOUD_SYNC_LOG_TABLE_MANAGER_H diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp index 2132dde07df1e6ab77dbc4a0f4e9604fc05d36c5..5110060cb27add2c91c0a9ba58a6cd9c871e1c06 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp @@ -84,7 +84,7 @@ std::string CollaborationLogTableManager::GetUpdateTrigger(const TableInfo &tabl updateTrigger += "\t INSERT OR REPLACE INTO " + logTblName + " VALUES (NEW.rowid, '', '', get_sys_time(0), " "get_last_time(), CASE WHEN (" + CalcPrimaryKeyHash("NEW.", table, identity) + " != " + CalcPrimaryKeyHash("NEW.", table, identity) + ") THEN 0x02 ELSE 0x22 END, " + - CalcPrimaryKeyHash("NEW.", table, identity) + ");\n"; + CalcPrimaryKeyHash("NEW.", table, identity) + ", '');\n"; } updateTrigger += "END;"; return updateTrigger; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp index 841fa48cb8859702a9730ac408f6016e9e0f9c4b..a6f613f1b955fca36855b3cbe2f9ed7533807b2b 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp @@ -14,16 +14,21 @@ */ #include "log_table_manager_factory.h" - +#include "cloud_sync_log_table_manager.h" #include "collaboration_log_table_manager.h" #include "split_device_log_table_manager.h" namespace DistributedDB { -std::unique_ptr LogTableManagerFactory::GetTableManager(DistributedTableMode mode) +std::unique_ptr LogTableManagerFactory::GetTableManager(DistributedTableMode mode, + TableSyncType syncType) { - if (mode == DistributedTableMode::COLLABORATION) { - return std::make_unique(); + if (syncType == CLOUD_COOPERATION) { + return std::make_unique(); + } else { + if (mode == DistributedTableMode::COLLABORATION) { + return std::make_unique(); + } + return std::make_unique(); } - return std::make_unique(); } } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.h b/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.h index e534ea325f6e647a9629885a23a1b0de2ad2a872..34347471dd2a56303bb25bfe8596be3c7b3b6c44 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.h @@ -16,13 +16,15 @@ #ifndef LOG_TABLE_MANAGER_FACTORY_H #define LOG_TABLE_MANAGER_FACTORY_H #include + +#include "cloud_store_types.h" #include "sqlite_log_table_manager.h" #include "types_export.h" namespace DistributedDB { class LogTableManagerFactory final { public: - static std::unique_ptr GetTableManager(DistributedTableMode mode); + static std::unique_ptr GetTableManager(DistributedTableMode mode, TableSyncType syncType); private: LogTableManagerFactory() {} diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp index f84466c944eeec3594ae38cd6391764c85049ae9..a47bcc65ba7193f6a30a88ab329be0afd3ab0708 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp @@ -361,4 +361,13 @@ std::string QuerySyncObject::GetRelationTableName() const } return tableName_; } + +std::vector QuerySyncObject::GetRelationTableNames() const +{ + + if (!isTableNameSpecified_) { + return {}; + } + return { tableName_ }; +} } // namespace DistributedDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h index 129ae547436b2711e813da4a977d2021c5fc878e..547c87de12660e3249f6f6824db6e17d73555ddd 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h @@ -51,6 +51,8 @@ public: std::string GetRelationTableName() const; + std::vector GetRelationTableNames() const; + private: uint32_t CalculateLen() const; uint32_t CalculateIdentifyLen() const; 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 a99792abd9993228d3e8e02a6e312e345739bca7..2e5c994804087fb87bedb59f3ef0b599235d05d3 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 @@ -63,6 +63,12 @@ int SqliteRelationalDatabaseUpgrader::ExecuteUpgrade() return (errCode == -E_NOT_FOUND) ? E_OK : errCode; } + errCode = UpgradeLogTable(logTableVersion); + if (errCode != E_OK) { + LOGE("[Relational][Upgrade] Upgrade log table failed, err = %d.", errCode); + return errCode; + } + return UpgradeTrigger(logTableVersion); } @@ -75,9 +81,14 @@ int SqliteRelationalDatabaseUpgrader::EndUpgrade(bool isSuccess) return SQLiteUtils::RollbackTransaction(db_); } +bool SqliteRelationalDatabaseUpgrader::IsNewestVersion(const std::string &logTableVersion) +{ + return logTableVersion == DBConstant::LOG_TABLE_VERSION_CURRENT; +} + int SqliteRelationalDatabaseUpgrader::UpgradeTrigger(const std::string &logTableVersion) { - if (logTableVersion != DBConstant::LOG_TABLE_VERSION_1) { + if (IsNewestVersion(logTableVersion)) { LOGD("[Relational][Upgrade] No need upgrade trigger."); return E_OK; } @@ -98,10 +109,6 @@ int SqliteRelationalDatabaseUpgrader::UpgradeTrigger(const std::string &logTable } DistributedTableMode mode = schemaObject.GetTableMode(); - if (mode != DistributedTableMode::SPLIT_BY_DEVICE) { - return E_OK; - } - for (const auto &[tableName, tableInfo] : schemaObject.GetTables()) { std::string dropTriggerSql = "DROP TRIGGER IF EXISTS " + DBConstant::SYSTEM_TABLE_PREFIX + tableName + "_ON_UPDATE"; @@ -110,7 +117,7 @@ int SqliteRelationalDatabaseUpgrader::UpgradeTrigger(const std::string &logTable LOGE("[Relational][Upgrade] drop trigger failed.", errCode); return errCode; } - auto manager = LogTableManagerFactory::GetTableManager(mode); + auto manager = LogTableManagerFactory::GetTableManager(mode, tableInfo.GetTableSyncType()); errCode = manager->AddRelationalLogTableTrigger(db_, tableInfo, ""); if (errCode != E_OK) { LOGE("[Relational][Upgrade] recreate trigger failed.", errCode); @@ -119,4 +126,38 @@ int SqliteRelationalDatabaseUpgrader::UpgradeTrigger(const std::string &logTable } return E_OK; } + +int SqliteRelationalDatabaseUpgrader::UpgradeLogTable(const std::string &logTableVersion) +{ + if (IsNewestVersion(logTableVersion)) { + LOGD("[Relational][Upgrade] No need upgrade log table."); + return E_OK; + } + + // get schema from meta + std::string schemaDefine; + int errCode = SQLiteUtils::GetRelationalSchema(db_, schemaDefine); + if (errCode != E_OK) { + LOGW("[Relational][UpgradeLogTable] Get relational schema from meta return %d.", errCode); + return (errCode == -E_NOT_FOUND) ? E_OK : errCode; + } + + RelationalSchemaObject schemaObject; + errCode = schemaObject.ParseFromSchemaString(schemaDefine); + if (errCode != E_OK) { + LOGE("[Relational][UpgradeLogTable] Parse to relational schema failed.", errCode); + return errCode; + } + + for (const auto &[tableName, tableInfo] : schemaObject.GetTables()) { + std::string addColumnSql = "alter table " + DBConstant::RELATIONAL_PREFIX + tableName + + "_log add cloud_gid text after hash_key;"; + errCode = SQLiteUtils::ExecuteRawSQL(db_, addColumnSql); + if (errCode != E_OK) { + LOGE("[Relational][UpgradeLogTable] add column failed.", errCode); + return errCode; + } + } + return E_OK; +} } // namespace DistributedDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.h index 5eeff9df5c218a4558b4dd1e1c62445b7599340f..4debfc1e2e4871bac3bd97a5d6f80d65dd273896 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.h @@ -32,7 +32,9 @@ private: int ExecuteUpgrade(); int EndUpgrade(bool isSuccess); + bool IsNewestVersion(const std::string &logTableVersion); int UpgradeTrigger(const std::string &logTableVersion); + int UpgradeLogTable(const std::string &logTableVersion); sqlite3 *db_; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp index 288d5443677c366de9a702d17f1e4315be0b6e00..233402a91739a7f70f71285469da112876e1d792 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp @@ -94,7 +94,7 @@ void SQLiteRelationalStore::ReleaseResources() int SQLiteRelationalStore::CheckDBMode() { int errCode = E_OK; - auto *handle = GetHandle(false, errCode); + auto *handle = GetHandle(true, errCode); if (handle == nullptr) { return errCode; } @@ -273,8 +273,10 @@ int SQLiteRelationalStore::Open(const RelationalDBProperties &properties) errCode = -E_OUT_OF_MEMORY; break; } + storageEngine_->InitSchemaMgr(storageEngine_); syncAbleEngine_ = std::make_unique(storageEngine_); + cloudSyncer_ = std::make_unique(StorageProxy::GetCloudDb(storageEngine_)); errCode = CheckDBMode(); if (errCode != E_OK) { @@ -404,7 +406,7 @@ void SQLiteRelationalStore::WakeUpSyncer() syncAbleEngine_->WakeUpSyncer(); } -int SQLiteRelationalStore::CreateDistributedTable(const std::string &tableName) +int SQLiteRelationalStore::CreateDistributedTable(const std::string &tableName, TableSyncType syncType) { auto mode = static_cast(sqliteStorageEngine_->GetProperties().GetIntProp( RelationalDBProperties::DISTRIBUTED_TABLE_MODE, DistributedTableMode::SPLIT_BY_DEVICE)); @@ -420,7 +422,7 @@ int SQLiteRelationalStore::CreateDistributedTable(const std::string &tableName) bool schemaChanged = false; int errCode = sqliteStorageEngine_->CreateDistributedTable(tableName, DBCommon::TransferStringToHex(localIdentity), - schemaChanged); + schemaChanged, syncType); if (errCode != E_OK) { LOGE("Create distributed table failed. %d", errCode); } @@ -431,7 +433,7 @@ int SQLiteRelationalStore::CreateDistributedTable(const std::string &tableName) return errCode; } -int SQLiteRelationalStore::RemoveDeviceData(const std::string &device, const std::string &tableName) +int SQLiteRelationalStore::RemoveDeviceData() { auto mode = static_cast(sqliteStorageEngine_->GetProperties().GetIntProp( RelationalDBProperties::DISTRIBUTED_TABLE_MODE, DistributedTableMode::SPLIT_BY_DEVICE)); @@ -440,50 +442,85 @@ int SQLiteRelationalStore::RemoveDeviceData(const std::string &device, const std return -E_NOT_SUPPORT; } - TableInfoMap tables = sqliteStorageEngine_->GetSchema().GetTables(); // TableInfoMap - if (tables.empty() || (!tableName.empty() && tables.find(tableName) == tables.end())) { - LOGE("Remove device data with table name which is not a distributed table or no distributed table found."); - return -E_DISTRIBUTED_SCHEMA_NOT_FOUND; + std::vector tableNameList = GetAllDistributedTableName(); + if (tableNameList.empty()) { + return E_OK; } - - int errCode = E_OK; - auto *handle = GetHandle(true, errCode); - if (handle == nullptr) { + // erase watermark first + int errCode = EraseAllDeviceWatermark(tableNameList); + if (errCode != E_OK) { return errCode; } - - errCode = handle->StartTransaction(TransactType::IMMEDIATE); - if (errCode != E_OK) { - ReleaseHandle(handle); + auto *handle = GetHandleAndStartTransaction(errCode); + if (handle == nullptr) { return errCode; } - errCode = handle->DeleteDistributedDeviceTable(device, tableName); - if (errCode != E_OK) { - LOGE("delete device data failed. %d", errCode); - goto END; - } + for (const auto &table: tableNameList) { + errCode = handle->DeleteDistributedDeviceTable("", table); + if (errCode != E_OK) { + LOGE("delete device data failed. %d", errCode); + break; + } - for (const auto &it : tables) { - if (tableName.empty() || it.second.GetTableName() == tableName) { - errCode = handle->DeleteDistributedDeviceTableLog(device, it.second.GetTableName()); - if (errCode != E_OK) { - LOGE("delete device data failed. %d", errCode); - break; - } + errCode = handle->DeleteDistributedAllDeviceTableLog(table); + if (errCode != E_OK) { + LOGE("delete device data failed. %d", errCode); + break; } } -END: if (errCode != E_OK) { (void)handle->Rollback(); ReleaseHandle(handle); return errCode; } + errCode = handle->Commit(); ReleaseHandle(handle); storageEngine_->NotifySchemaChanged(); - return (errCode != E_OK) ? errCode : syncAbleEngine_->EraseDeviceWaterMark(device, true, tableName); + return errCode; +} + +int SQLiteRelationalStore::RemoveDeviceData(const std::string &device, const std::string &tableName) +{ + auto mode = static_cast(sqliteStorageEngine_->GetProperties().GetIntProp( + RelationalDBProperties::DISTRIBUTED_TABLE_MODE, DistributedTableMode::SPLIT_BY_DEVICE)); + if (mode == DistributedTableMode::COLLABORATION) { + LOGE("Not support remove device data in collaboration mode."); + return -E_NOT_SUPPORT; + } + + TableInfoMap tables = sqliteStorageEngine_->GetSchema().GetTables(); // TableInfoMap + if (tables.empty() || (!tableName.empty() && tables.find(tableName) == tables.end())) { + LOGE("Remove device data with table name which is not a distributed table or no distributed table found."); + return -E_DISTRIBUTED_SCHEMA_NOT_FOUND; + } + + bool isNeedHash = false; + std::string hashDeviceId; + int errCode = syncAbleEngine_->GetHashDeviceId(device, hashDeviceId); + if (errCode == -E_NOT_SUPPORT) { + isNeedHash = true; + hashDeviceId = device; + errCode = E_OK; + } + if (errCode != E_OK) { + return errCode; + } + if (isNeedHash) { + // check device is uuid in meta + std::set hashDevices; + errCode = GetExistDevices(hashDevices); + if (errCode != E_OK) { + return errCode; + } + if (hashDevices.find(DBCommon::TransferHashString(device)) == hashDevices.end()) { + LOGD("[SQLiteRelationalStore] not match device, just return"); + return E_OK; + } + } + return RemoveDeviceDataInner(hashDeviceId, device, tableName, isNeedHash); } void SQLiteRelationalStore::RegisterObserverAction(const RelationalObserverAction &action) @@ -673,5 +710,180 @@ int SQLiteRelationalStore::RemoteQuery(const std::string &device, const RemoteCo return syncAbleEngine_->RemoteQuery(device, condition, timeout, connectionId, result); } + +int SQLiteRelationalStore::EraseAllDeviceWatermark(const std::vector &tableNameList) +{ + std::set devices; + int errCode = GetExistDevices(devices); + if (errCode != E_OK) { + return errCode; + } + for (const auto &tableName: tableNameList) { + for (const auto &device: devices) { + errCode = syncAbleEngine_->EraseDeviceWaterMark(device, false, tableName); + if (errCode != E_OK) { + return errCode; + } + } + } + return errCode; +} + +std::string SQLiteRelationalStore::GetDevTableName(const std::string &device, const std::string &hashDev) const +{ + std::string devTableName; + StoreInfo info = { + sqliteStorageEngine_->GetProperties().GetStringProp(DBProperties::USER_ID, ""), + sqliteStorageEngine_->GetProperties().GetStringProp(DBProperties::APP_ID, ""), + sqliteStorageEngine_->GetProperties().GetStringProp(DBProperties::STORE_ID, "") + }; + if (RuntimeContext::GetInstance()->TranslateDeviceId(device, info, devTableName) != E_OK) { + devTableName = hashDev; + } + return devTableName; +} + +SQLiteSingleVerRelationalStorageExecutor *SQLiteRelationalStore::GetHandleAndStartTransaction(int &errCode) const +{ + auto *handle = GetHandle(true, errCode); + if (handle == nullptr) { + return nullptr; + } + + errCode = handle->StartTransaction(TransactType::IMMEDIATE); + if (errCode != E_OK) { + ReleaseHandle(handle); + return nullptr; + } + return handle; +} + +int SQLiteRelationalStore::RemoveDeviceDataInner(const std::string &mappingDev, const std::string &device, + const std::string &tableName, bool isNeedHash) +{ + std::string hashHexDev; + std::string hashDev; + std::string devTableName; + if (!isNeedHash) { + // if is not need hash mappingDev mean hash(uuid) device is param device + hashHexDev = DBCommon::TransferStringToHex(mappingDev); + hashDev = mappingDev; + devTableName = device; + } else { + // if is need hash mappingDev mean uuid + hashDev = DBCommon::TransferHashString(mappingDev); + hashHexDev = DBCommon::TransferStringToHex(hashDev); + devTableName = GetDevTableName(mappingDev, hashHexDev); + } + // erase watermark first + int errCode = syncAbleEngine_->EraseDeviceWaterMark(hashDev, false, tableName); + if (errCode != E_OK) { + return errCode; + } + auto *handle = GetHandleAndStartTransaction(errCode); + if (handle == nullptr) { + return errCode; + } + + errCode = handle->DeleteDistributedDeviceTable(devTableName, tableName); + TableInfoMap tables = sqliteStorageEngine_->GetSchema().GetTables(); // TableInfoMap + if (errCode != E_OK) { + LOGE("delete device data failed. %d", errCode); + goto END; + } + + for (const auto &it : tables) { + if (tableName.empty() || it.second.GetTableName() == tableName) { + errCode = handle->DeleteDistributedDeviceTableLog(hashHexDev, it.second.GetTableName()); + if (errCode != E_OK) { + LOGE("delete device data failed. %d", errCode); + break; + } + } + } + +END: + if (errCode != E_OK) { + (void)handle->Rollback(); + ReleaseHandle(handle); + return errCode; + } + errCode = handle->Commit(); + ReleaseHandle(handle); + storageEngine_->NotifySchemaChanged(); + return errCode; +} + +int SQLiteRelationalStore::GetExistDevices(std::set &hashDevices) const +{ + int errCode = E_OK; + auto *handle = GetHandle(true, errCode); + if (handle == nullptr) { + LOGE("[SingleVerRDBStore] GetExistsDeviceList get handle failed:%d", errCode); + return errCode; + } + errCode = handle->GetExistsDeviceList(hashDevices); + if (errCode != E_OK) { + LOGE("[SingleVerRDBStore] Get remove device list from meta failed. err=%d", errCode); + } + ReleaseHandle(handle); + return errCode; +} + +std::vector SQLiteRelationalStore::GetAllDistributedTableName() +{ + TableInfoMap tables = sqliteStorageEngine_->GetSchema().GetTables(); // TableInfoMap + std::vector tableNames; + for (const auto &table: tables) { + tableNames.push_back(table.second.GetTableName()); + } + return tableNames; +} + +int SQLiteRelationalStore::SetCloudDB(const std::shared_ptr &cloudDb) +{ + if (cloudSyncer_ == nullptr) { + LOGE("[RelationalStore][SetCloudDB] cloudSyncer was not initialized"); + return -E_INVALID_DB; + } + return cloudSyncer_->SetCloudDB(cloudDb); +} + +int SQLiteRelationalStore::SetCloudDbSchema(const DataBaseSchema &schema) +{ + if (storageEngine_ == nullptr) { + LOGE("[RelationalStore][SetCloudDbSchema] storageEngine was not initialized"); + return -E_INVALID_DB; + } + return storageEngine_->SetCloudDbSchema(schema); +} + +int SQLiteRelationalStore::ChkSchema(const TableName &tableName) +{ + if (storageEngine_ == nullptr) { + LOGE("[RelationalStore][ChkSchema] storageEngine was not initialized"); + return -E_INVALID_DB; + } + return storageEngine_->ChkSchema(tableName); +} + +int SQLiteRelationalStore::Sync(const std::vector &devices, SyncMode mode, + const Query &query, const std::function &onProcess, int64_t waitTime) +{ + if (cloudSyncer_ == nullptr) { + LOGE("[RelationalStore] cloudSyncer was not initialized when sync"); + return -E_INVALID_DB; + } + QuerySyncObject querySyncObject(query); + const auto &tableNames = querySyncObject.GetRelationTableNames(); + for (const auto &table: tableNames) { + int errCode = ChkSchema(table); + if (errCode != E_OK) { + LOGE("[RelationalStore] schema check failed when sync"); + return errCode; + } + } + return cloudSyncer_->Sync(devices, mode, tableNames, onProcess, waitTime); +} } #endif \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.h index 216b0ad26edc82ea08330c3ddd11054c27d078e7..b7593baf30b1ef8f80f1b1dd1c441c23dea55b03 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.h @@ -26,6 +26,7 @@ #include "sync_able_engine.h" #include "relational_sync_able_storage.h" #include "runtime_context.h" +#include "cloud_syncer.h" namespace DistributedDB { using RelationalObserverAction = std::function; @@ -56,8 +57,9 @@ public: return storageEngine_; } - int CreateDistributedTable(const std::string &tableName); + int CreateDistributedTable(const std::string &tableName, TableSyncType syncType); + int RemoveDeviceData(); int RemoveDeviceData(const std::string &device, const std::string &tableName); void RegisterObserverAction(const RelationalObserverAction &action); @@ -74,6 +76,15 @@ public: int RemoteQuery(const std::string &device, const RemoteCondition &condition, uint64_t timeout, uint64_t connectionId, std::shared_ptr &result); + int SetCloudDB(const std::shared_ptr &cloudDb); + + int SetCloudDbSchema(const DataBaseSchema &schema); + + int ChkSchema(const TableName &tableName); + + int Sync(const std::vector &devices, SyncMode mode, const Query &query, + const std::function &onProcess, int64_t waitTime); + private: void ReleaseResources(); @@ -98,11 +109,25 @@ private: void IncreaseConnectionCounter(); int InitStorageEngine(const RelationalDBProperties &kvDBProp); + int EraseAllDeviceWatermark(const std::vector &tableNameList); + + std::string GetDevTableName(const std::string &device, const std::string &hashDev) const; + + SQLiteSingleVerRelationalStorageExecutor *GetHandleAndStartTransaction(int &errCode) const; + + int RemoveDeviceDataInner(const std::string &mappingDev, const std::string &device, + const std::string &tableName, bool isNeedHash); + + int GetExistDevices(std::set &hashDevices) const; + + std::vector GetAllDistributedTableName(); + // use for sync Interactive std::unique_ptr syncAbleEngine_ = nullptr; // For storage operate sync function // use ref obj same as kv RelationalSyncAbleStorage *storageEngine_ = nullptr; // For storage operate data std::shared_ptr sqliteStorageEngine_; + std::unique_ptr cloudSyncer_ = nullptr; std::mutex connectMutex_; std::atomic connectionCount_ = 0; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp index 86e72eed861431787f77a251443ed14c90c9dcbd..86e895911a1e3c6032f40dc79f724436052bf096 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp @@ -141,7 +141,7 @@ int SQLiteRelationalStoreConnection::RollBack() return errCode; } -int SQLiteRelationalStoreConnection::CreateDistributedTable(const std::string &tableName) +int SQLiteRelationalStoreConnection::CreateDistributedTable(const std::string &tableName, TableSyncType syncType) { auto *store = GetDB(); if (store == nullptr) { @@ -149,13 +149,28 @@ int SQLiteRelationalStoreConnection::CreateDistributedTable(const std::string &t return -E_INVALID_CONNECTION; } - int errCode = store->CreateDistributedTable(tableName); + int errCode = store->CreateDistributedTable(tableName, syncType); if (errCode != E_OK) { LOGE("[RelationalConnection] create distributed table failed. %d", errCode); } return errCode; } +int SQLiteRelationalStoreConnection::RemoveDeviceData() +{ + auto *store = GetDB(); + if (store == nullptr) { + LOGE("[RelationalConnection] store is null, get DB failed!"); + return -E_INVALID_CONNECTION; + } + + int errCode = store->RemoveDeviceData(); + if (errCode != E_OK) { + LOGE("[RelationalConnection] remove device data failed. %d", errCode); + } + return errCode; +} + int SQLiteRelationalStoreConnection::RemoveDeviceData(const std::string &device) { return RemoveDeviceData(device, {}); @@ -247,5 +262,58 @@ int SQLiteRelationalStoreConnection::RemoteQuery(const std::string &device, cons } return store->RemoteQuery(device, condition, timeout, GetConnectionId(), result); } + +int SQLiteRelationalStoreConnection::SetCloudDB(const std::shared_ptr &cloudDb) +{ + auto *store = GetDB(); + if (store == nullptr) { + LOGE("[RelationalConnection] store is null, get DB failed!"); + return -E_INVALID_CONNECTION; + } + + int ret = store->SetCloudDB(cloudDb); + if (ret != E_OK) { + LOGE("[RelationalConnection] SetCloudDB failed. %d", ret); + } + return ret; +} + +int SQLiteRelationalStoreConnection::SetCloudDbSchema(const DataBaseSchema &schema) +{ + auto *store = GetDB(); + if (store == nullptr) { + LOGE("[RelationalConnection] store is null, get DB failed!"); + return -E_INVALID_CONNECTION; + } + + int ret = store->SetCloudDbSchema(schema); + if (ret != E_OK) { + LOGE("[RelationalConnection] SetCloudDbSchema failed. %d", ret); + } + return ret; +} + +int SQLiteRelationalStoreConnection::Sync(const std::vector &devices, SyncMode mode, const Query &query, + const std::function &onProcess, int64_t waitTime) +{ + auto *store = GetDB(); + if (store == nullptr) { + LOGE("[RelationalConnection] store is null, get executor failed!"); + return -E_INVALID_CONNECTION; + } + { + AutoLock lockGuard(this); + if (IsKilled()) { + // If this happens, users are using a closed connection. + LOGE("Sync on a closed connection."); + return -E_STALE; + } + IncObjRef(this); + } + int errCode = store->Sync(devices, mode, query, onProcess, waitTime); + DecObjRef(this); + return errCode; +} + } #endif \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.h index 3c51d21de0b4b2eb3edd81cc23922c9514c67181..24fed648d9d693a209870ad89c5ab1ca339014f6 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.h @@ -36,14 +36,20 @@ public: int Close() override; int SyncToDevice(SyncInfo &info) override; std::string GetIdentifier() override; - int CreateDistributedTable(const std::string &tableName) override; + int CreateDistributedTable(const std::string &tableName, TableSyncType syncType) override; int RegisterLifeCycleCallback(const DatabaseLifeCycleNotifier ¬ifier) override; + int RemoveDeviceData() override; int RemoveDeviceData(const std::string &device) override; int RemoveDeviceData(const std::string &device, const std::string &tableName) override; void RegisterObserverAction(const RelationalObserverAction &action) override; int RemoteQuery(const std::string &device, const RemoteCondition &condition, uint64_t timeout, std::shared_ptr &result) override; + int SetCloudDB(const std::shared_ptr &cloudDb) override; + int SetCloudDbSchema(const DataBaseSchema &schema) override; + + int Sync(const std::vector &devices, SyncMode mode, const Query &query, + const std::function &onProcess, int64_t waitTime) override; protected: diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp index 2f12e420682b4c6904d87e7df2d467c65dbade7c..769bf033a33a5d73dc029fa12fbca9e9f813365b 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp @@ -15,6 +15,7 @@ #include "sqlite_relational_utils.h" #include "db_errno.h" +#include "cloud/cloud_db_types.h" #include "sqlite_utils.h" namespace DistributedDB { @@ -78,4 +79,83 @@ std::vector SQLiteRelationalUtils::GetSelectValues(sqlite3_stmt *stmt } return values; } + +int SQLiteRelationalUtils::GetCloudValueByType(sqlite3_stmt *statement, int type, int cid, Type &cloudValue) +{ + if (statement == nullptr || cid < 0 || cid >= sqlite3_column_count(statement)) { + return -E_INVALID_ARGS; + } + int errCode = E_OK; + int storageType = sqlite3_column_type(statement, cid); + switch (storageType) { + case SQLITE_INTEGER: { + if (type == TYPE_INDEX) { + cloudValue = static_cast(sqlite3_column_int(statement, cid)); + } else { + cloudValue = static_cast(sqlite3_column_int64(statement, cid)); + } + break; + } + case SQLITE_FLOAT: { + cloudValue = sqlite3_column_double(statement, cid); + break; + } + case SQLITE_BLOB: { + std::vector blobValue; + errCode = SQLiteUtils::GetColumnBlobValue(statement, cid, blobValue); + if (errCode != E_OK) { + return errCode; + } + cloudValue = blobValue; + break; + } + case SQLITE_NULL: { + break; + } + case SQLITE3_TEXT: { + if (type == TYPE_INDEX || type == TYPE_INDEX || type == TYPE_INDEX) { + std::vector blobValue; + errCode = SQLiteUtils::GetColumnBlobValue(statement, cid, blobValue); + if (errCode != E_OK) { + return errCode; + } + cloudValue = blobValue; + } else { + std::string str; + (void)SQLiteUtils::GetColumnTextValue(statement, cid, str); + cloudValue = str; + } + break; + } + default: + break; + } + return errCode; +} + +void SQLiteRelationalUtils::CalCloudValueLen(Type &cloudValue, uint32_t &totalSize) +{ + switch (cloudValue.index()) { + case TYPE_INDEX: + totalSize += sizeof(int64_t); + break; + case TYPE_INDEX: + totalSize += sizeof(double); + break; + case TYPE_INDEX: + totalSize += std::get(cloudValue).size(); + break; + case TYPE_INDEX: + totalSize += sizeof(int32_t); + break; + case TYPE_INDEX: + case TYPE_INDEX: + case TYPE_INDEX: + totalSize += std::get(cloudValue).size(); + break; + default: { + break; + } + } +} } // namespace DistributedDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.h index a03e14221952960ee250fb3f6dfa93ba4778e255..84e140afb66252475dee1e7cdb757f9d43f64b1d 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.h @@ -19,6 +19,7 @@ #include #include "sqlite_import.h" #include "data_value.h" +#include "cloud_store_types.h" namespace DistributedDB { class SQLiteRelationalUtils { @@ -26,6 +27,10 @@ public: static int GetDataValueByType(sqlite3_stmt *statement, int cid, DataValue &value); static std::vector GetSelectValues(sqlite3_stmt *stmt); + + static int GetCloudValueByType(sqlite3_stmt *statement, int type, int cid, Type &cloudValue); + + static void CalCloudValueLen(Type &cloudValue, uint32_t &totalSize); }; } // namespace DistributedDB #endif // SQLITE_RELATIONAL_UTILS_H 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 6b90670ef79f5bde8e7fd8c54f8e752e82dbbfa8..e9cf8dc80bb2f5647041fa60683daf154cf406fe 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 @@ -141,13 +141,17 @@ int SaveSchemaToMetaTable(SQLiteSingleVerRelationalStorageExecutor *handle, cons } int SQLiteSingleRelationalStorageEngine::CreateDistributedTable(const std::string &tableName, - const std::string &identity, bool &schemaChanged) + const std::string &identity, bool &schemaChanged, TableSyncType syncType) { std::lock_guard lock(schemaMutex_); RelationalSchemaObject schema = schema_; bool isUpgraded = false; if (schema.GetTable(tableName).GetTableName() == tableName) { LOGI("distributed table bas been created."); + if (schema.GetTable(tableName).GetTableSyncType() != syncType) { + LOGE("table sync type mismatch."); + return -E_TYPE_MISMATCH; + } isUpgraded = true; int errCode = UpgradeDistributedTable(tableName, schemaChanged); if (errCode != E_OK) { @@ -162,11 +166,11 @@ int SQLiteSingleRelationalStorageEngine::CreateDistributedTable(const std::strin schemaChanged = true; } - return CreateDistributedTable(tableName, isUpgraded, identity, schema); + return CreateDistributedTable(tableName, isUpgraded, identity, schema, syncType); } int SQLiteSingleRelationalStorageEngine::CreateDistributedTable(const std::string &tableName, bool isUpgraded, - const std::string &identity, RelationalSchemaObject &schema) + const std::string &identity, RelationalSchemaObject &schema, TableSyncType tableSyncType) { LOGD("Create distributed table."); int errCode = E_OK; @@ -185,7 +189,9 @@ int SQLiteSingleRelationalStorageEngine::CreateDistributedTable(const std::strin auto mode = static_cast(properties_.GetIntProp( RelationalDBProperties::DISTRIBUTED_TABLE_MODE, DistributedTableMode::SPLIT_BY_DEVICE)); TableInfo table; - errCode = handle->CreateDistributedTable(tableName, mode, isUpgraded, identity, table); + table.SetTableName(tableName); + table.SetTableSyncType(tableSyncType); + errCode = handle->CreateDistributedTable(mode, isUpgraded, identity, table, tableSyncType); if (errCode != E_OK) { LOGE("create distributed table failed. %d", errCode); (void)handle->Rollback(); 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 540f499c99baf592a2eaf00ceff4f3462c5fd569..ff51bf648dda2d97b82daba9644b3e7dc9d18fe8 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 @@ -34,7 +34,8 @@ public: RelationalSchemaObject GetSchema() const; - int CreateDistributedTable(const std::string &tableName, const std::string &identity, bool &schemaChanged); + int CreateDistributedTable(const std::string &tableName, const std::string &identity, bool &schemaChanged, + TableSyncType syncType); int CleanDistributedDeviceTable(std::vector &missingTables); @@ -55,7 +56,7 @@ private: int UpgradeDistributedTable(const std::string &tableName, bool &schemaChanged); int CreateDistributedTable(const std::string &tableName, bool isUpgraded, const std::string &identity, - RelationalSchemaObject &schema); + RelationalSchemaObject &schema, TableSyncType tableSyncType); int CreateRelationalMetaTable(sqlite3 *db); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp index 6f50bc5baed5a5880c2b57261f306c3213804de8..1f06f5b23015116c4098ecbdde209b053bb2e367 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp @@ -72,7 +72,7 @@ std::string SplitDeviceLogTableManager::GetUpdateTrigger(const TableInfo &table, updateTrigger += "\t INSERT OR REPLACE INTO " + logTblName + " VALUES (NEW.rowid, '', '', get_sys_time(0), " "get_last_time(), CASE WHEN (" + CalcPrimaryKeyHash("NEW.", table, identity) + " != " + CalcPrimaryKeyHash("NEW.", table, identity) + ") THEN 0x02 ELSE 0x22 END, " + - CalcPrimaryKeyHash("NEW.", table, identity) + ");\n"; + CalcPrimaryKeyHash("NEW.", table, identity) + ", '');\n"; } updateTrigger += "END;"; return updateTrigger; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp index f1755b7bda775480f5fac43a1f3cf75b13a037d8..053ed430164e01dcad2d6bd0d29ced8dba41b418 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp @@ -44,7 +44,9 @@ int SqliteLogTableManager::CreateRelationalLogTable(sqlite3 *db, const TableInfo "timestamp INT NOT NULL," \ "wtimestamp INT NOT NULL," \ "flag INT NOT NULL," \ - "hash_key BLOB NOT NULL," + primaryKey + ");"; + "hash_key BLOB NOT NULL," \ + "cloud_gid TEXT," \ + + primaryKey + ");"; std::vector logTableSchema; logTableSchema.emplace_back(createTableSql); GetIndexSql(table, logTableSchema); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_meta_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_meta_executor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fdc929b8a4d62ae1d18359576d3a7882614619ae --- /dev/null +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_meta_executor.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2023 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 "sqlite_meta_executor.h" + +#include "db_common.h" +#include "db_constant.h" +namespace DistributedDB { +int SqliteMetaExecutor::GetMetaKeysByKeyPrefix(const std::string &keyPre, sqlite3 *dbHandle, MetaMode metaMode, + bool isMemDb, std::set &outKeys) +{ + sqlite3_stmt *statement = nullptr; + std::string sqlStr; + switch (metaMode) { + case MetaMode::KV: + sqlStr = SELECT_META_KEYS_BY_PREFIX; + break; + case MetaMode::KV_ATTACH: + sqlStr = SELECT_ATTACH_META_KEYS_BY_PREFIX; + break; + case MetaMode::RDB: + sqlStr = SELECT_RDB_META_KEYS_BY_PREFIX; + break; + default: + return -E_INVALID_ARGS; + } + int errCode = SQLiteUtils::GetStatement(dbHandle, sqlStr, statement); + if (errCode != E_OK) { + LOGE("[SqliteMetaExecutor] Get statement failed:%d", errCode); + return errCode; + } + + Key keyPrefix; + DBCommon::StringToVector(keyPre + '%', keyPrefix); + errCode = SQLiteUtils::BindBlobToStatement(statement, 1, keyPrefix); // 1: bind index for prefix key + if (errCode != E_OK) { + LOGE("[SqliteMetaExecutor] Bind statement failed:%d", errCode); + SQLiteUtils::ResetStatement(statement, true, errCode); + return errCode; + } + + std::vector keys; + errCode = GetAllKeys(statement, isMemDb, keys); + SQLiteUtils::ResetStatement(statement, true, errCode); + for (const auto &it : keys) { + if (it.size() >= keyPre.size() + DBConstant::HASH_KEY_SIZE) { + outKeys.insert({it.begin() + keyPre.size(), it.begin() + keyPre.size() + DBConstant::HASH_KEY_SIZE}); + } else { + LOGW("[SqliteMetaExecutor] Get invalid key, size=%zu", it.size()); + } + } + return errCode; +} + +int SqliteMetaExecutor::GetAllKeys(sqlite3_stmt *statement, bool isMemDb, std::vector &keys) +{ + if (statement == nullptr) { + return -E_INVALID_DB; + } + int errCode; + do { + errCode = SQLiteUtils::StepWithRetry(statement, isMemDb); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { + Key key; + errCode = SQLiteUtils::GetColumnBlobValue(statement, 0, key); + if (errCode != E_OK) { + break; + } + + keys.push_back(std::move(key)); + } else if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { + errCode = E_OK; + break; + } else { + LOGE("SQLite step for getting all keys failed:%d", errCode); + break; + } + } while (true); + return errCode; +} + +int SqliteMetaExecutor::GetExistsDevicesFromMeta(sqlite3 *dbHandle, MetaMode metaMode, + bool isMemDb, std::set &devices) +{ + int errCode = GetMetaKeysByKeyPrefix(DBConstant::DEVICEID_PREFIX_KEY, dbHandle, metaMode, isMemDb, devices); + if (errCode != E_OK) { + LOGE("Get meta data key failed. err=%d", errCode); + return errCode; + } + errCode = GetMetaKeysByKeyPrefix(DBConstant::QUERY_SYNC_PREFIX_KEY, dbHandle, metaMode, isMemDb, devices); + if (errCode != E_OK) { + LOGE("Get meta data key failed. err=%d", errCode); + return errCode; + } + errCode = GetMetaKeysByKeyPrefix(DBConstant::DELETE_SYNC_PREFIX_KEY, dbHandle, metaMode, isMemDb, devices); + if (errCode != E_OK) { + LOGE("Get meta data key failed. err=%d", errCode); + } + return errCode; +} +} \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_meta_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_meta_executor.h new file mode 100644 index 0000000000000000000000000000000000000000..f2890e7b473817abacfe96ed71f5bbd9d1c3cf94 --- /dev/null +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_meta_executor.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 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 SQLITE_META_EXECUTOR_H +#define SQLITE_META_EXECUTOR_H + +#include "sqlite_utils.h" + +namespace DistributedDB { +class SqliteMetaExecutor { +public: + enum class MetaMode { + KV = 0, + KV_ATTACH = 1, + RDB = 2 + }; + static int GetMetaKeysByKeyPrefix(const std::string &keyPre, sqlite3 *dbHandle, MetaMode metaMode, bool isMemDb, + std::set &outKeys); + + static int GetAllKeys(sqlite3_stmt *statement, bool isMemDb, std::vector &keys); + + static int GetExistsDevicesFromMeta(sqlite3 *dbHandle, MetaMode metaMode, + bool isMemDb, std::set &devices); +private: + static constexpr const char *SELECT_ATTACH_META_KEYS_BY_PREFIX = + "SELECT key FROM meta.meta_data where key like ?;"; + + static constexpr const char *SELECT_META_KEYS_BY_PREFIX = + "SELECT key FROM meta_data where key like ?;"; + + static constexpr const char *SELECT_RDB_META_KEYS_BY_PREFIX = + "SELECT key FROM naturalbase_rdb_aux_metadata where key like ?;"; +}; +} // DistributedDB +#endif // SQLITE_META_EXECUTOR_H diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp index 9ad4757add427bb603e8cbe80212a6657a51be57..ac23ed014341afaa5856ce96dbd2daa483ea085c 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp @@ -995,6 +995,27 @@ std::string GetRelationalSyncDataQueryHeader(const std::vector &fie } return sql; } + +std::string GetRelationalCloudSyncDataQueryHeader(const std::vector &fields) +{ + std::string sql = "SELECT b.data_key," + "b.device," + "b.ori_device," + "b.timestamp as " + DBConstant::TIMESTAMP_ALIAS + "," + "b.wtimestamp," + "b.flag," + "b.hash_key," + "b.cloud_gid,"; + if (fields.empty()) { // For query check. If column count changed, can be discovered. + sql += "a.*"; + } else { + for (const auto &field : fields) { // For query data. + sql += "a." + field.colName + ","; + } + sql.pop_back(); + } + return sql; +} } int SqliteQueryHelper::GetRelationalSyncDataQuerySqlWithLimit(const std::vector &fieldNames, @@ -1115,4 +1136,34 @@ int SqliteQueryHelper::BindKeysToStmt(const std::set &keys, sqlite3_stmt *& } return E_OK; } + +int SqliteQueryHelper::GetRelationalCloudQueryStatement(sqlite3 *dbHandle, uint64_t beginTime, + const std::vector &fields, sqlite3_stmt *&statement) +{ + std::string sql = GetRelationalCloudSyncDataQueryHeader(fields); + sql += " FROM '" + tableName_ + "' AS a INNER JOIN "; + sql += DBConstant::RELATIONAL_PREFIX + tableName_ + "_log"; + sql += " AS b ON (a.rowid = b.data_key)"; + sql += " WHERE b.timestamp > ? AND (b.flag & 0x02 = 0x02)"; + sql += " AND (b.cloud_gid != '' or"; // actually, b.cloud_gid will not be null. + sql += " (b.cloud_gid == '' and (b.flag & 0x01 = 0))) "; + + querySql_.clear(); // clear local query sql format + int errCode = ToQuerySyncSql(false, true); + if (errCode != E_OK) { + LOGE("To query sql fail! errCode[%d]", errCode); + return errCode; + } + sql += querySql_; + errCode = SQLiteUtils::GetStatement(dbHandle, sql, statement); + if (errCode != E_OK) { + LOGE("[Query] Get statement fail!"); + return -E_INVALID_QUERY_FORMAT; + } + errCode = SQLiteUtils::BindInt64ToStatement(statement, 1, beginTime); + if (errCode != E_OK) { + SQLiteUtils::ResetStatement(statement, true, errCode); + } + return errCode; +} } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.h index ece7e1d5c5f9329a0db6b893d935f35ee73a9036..00071c9f4d7cad74c5d10427d20cda6a8826ca9b 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.h @@ -23,6 +23,7 @@ #include "query_expression.h" #include "schema_utils.h" #include "sqlite_import.h" +#include "cloud_store_types.h" namespace DistributedDB { namespace TriggerMode { @@ -100,6 +101,8 @@ public: int GetRelationalSyncDataQuerySqlWithLimit(const std::vector &fieldNames, std::string &sql); int GetRelationalQueryStatement(sqlite3 *dbHandle, uint64_t beginTime, uint64_t endTime, const std::vector &fieldNames, sqlite3_stmt *&statement); + int GetRelationalCloudQueryStatement(sqlite3 *dbHandle, uint64_t beginTime, + const std::vector &fields, sqlite3_stmt *&statement); private: int ToQuerySql(); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp index 62b1a51861769e73386d828bf0cd54874d25a101..bf820309d5d45b8e6fc63f6365a2d92b13c3648a 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp @@ -413,13 +413,13 @@ int SQLiteSingleVerNaturalStore::GetAndInitStorageEngine(const KvDBProperties &k } if (storageEngine_->IsEngineCorrupted()) { - LOGE("[SqlSinStore][GetAndInitStorageEngine] database engine is corrupted, not need continue to open!"); + LOGE("[SqlSinStore][GetAndInitStorageEngine] database engine is corrupted or invalid passwd, stop open!"); return -E_INVALID_PASSWD_OR_CORRUPTED_DB; } errCode = InitDatabaseContext(kvDBProp); if (errCode != E_OK) { - LOGE("[SqlSinStore][Open] Init database context fail! errCode = [%d]", errCode); + LOGE("[SqlSinStore][GetAndInitStorageEngine] Init database context fail! errCode = [%d]", errCode); } return errCode; } @@ -974,55 +974,28 @@ int SQLiteSingleVerNaturalStore::RemoveDeviceData(const std::string &deviceName, if (!isInSync && !CheckWritePermission()) { return -E_NOT_PERMIT; } - int errCode = E_OK; - SQLiteSingleVerStorageExecutor *handle = GetHandle(true, errCode); - if (handle == nullptr) { - LOGE("[SingleVerNStore] RemoveDeviceData get handle failed:%d", errCode); - return errCode; - } - uint64_t logFileSize = handle->GetLogFileSize(); - ReleaseHandle(handle); - if (logFileSize > GetMaxLogSize()) { - LOGW("[SingleVerNStore] RmDevData log size[%" PRIu64 "] over the limit", logFileSize); - return -E_LOG_OVER_LIMITS; - } - - bool isNeedHash = true; - std::set removeDevices; - if (deviceName.empty()) { - errCode = GetExistsDeviceList(removeDevices); - if (errCode != E_OK) { - LOGE("[SingleVerNStore] get remove device list failed:%d", errCode); - return errCode; - } - isNeedHash = false; - } else { - removeDevices.insert(deviceName); - } - - LOGD("[SingleVerNStore] remove device data, size=%zu", removeDevices.size()); - for (const auto &iterDevice : removeDevices) { - // Call the syncer module to erase the water mark. - errCode = EraseDeviceWaterMark(iterDevice, isNeedHash); - if (errCode != E_OK) { - LOGE("[SingleVerNStore] erase water mark failed:%d", errCode); - return errCode; + std::string hashDeviceId; + bool hash = false; + do { + if (!deviceName.empty() && !isInSync) { + int errCode = GetHashDeviceId(deviceName, hashDeviceId); + if (errCode == -E_NOT_SUPPORT) { + break; + } + if (errCode != E_OK) { + return errCode; + } + hash = true; } + } while (false); + if (!hash) { + hashDeviceId = DBCommon::TransferHashString(deviceName); } - if (IsExtendedCacheDBMode()) { - errCode = RemoveDeviceDataInCacheMode(deviceName, isNeedNotify); - } else { - errCode = RemoveDeviceDataNormally(deviceName, isNeedNotify); - } - if (errCode != E_OK) { - LOGE("[SingleVerNStore] RemoveDeviceData failed:%d", errCode); - } - - return errCode; + return RemoveDeviceDataInner(hashDeviceId, isNeedNotify); } -int SQLiteSingleVerNaturalStore::RemoveDeviceDataInCacheMode(const std::string &deviceName, bool isNeedNotify) +int SQLiteSingleVerNaturalStore::RemoveDeviceDataInCacheMode(const std::string &hashDev, bool isNeedNotify) const { int errCode = E_OK; SQLiteSingleVerStorageExecutor *handle = GetHandle(true, errCode); @@ -1032,7 +1005,7 @@ int SQLiteSingleVerNaturalStore::RemoveDeviceDataInCacheMode(const std::string & } uint64_t recordVersion = GetAndIncreaseCacheRecordVersion(); LOGI("Remove device data in cache mode isNeedNotify:%d, recordVersion:%" PRIu64, isNeedNotify, recordVersion); - errCode = handle->RemoveDeviceDataInCacheMode(deviceName, isNeedNotify, recordVersion); + errCode = handle->RemoveDeviceDataInCacheMode(hashDev, isNeedNotify, recordVersion); if (errCode != E_OK) { LOGE("[SingleVerNStore] RemoveDeviceDataInCacheMode failed:%d", errCode); } @@ -1040,7 +1013,7 @@ int SQLiteSingleVerNaturalStore::RemoveDeviceDataInCacheMode(const std::string & return errCode; } -int SQLiteSingleVerNaturalStore::RemoveDeviceDataNormally(const std::string &deviceName, bool isNeedNotify) +int SQLiteSingleVerNaturalStore::RemoveDeviceDataNormally(const std::string &hashDev, bool isNeedNotify) { int errCode = E_OK; SQLiteSingleVerStorageExecutor *handle = GetHandle(true, errCode); @@ -1051,11 +1024,11 @@ int SQLiteSingleVerNaturalStore::RemoveDeviceDataNormally(const std::string &dev std::vector entries; if (isNeedNotify) { - handle->GetAllSyncedEntries(deviceName, entries); + handle->GetAllSyncedEntries(hashDev, entries); } LOGI("Remove device data:%d", isNeedNotify); - errCode = handle->RemoveDeviceData(deviceName); + errCode = handle->RemoveDeviceData(hashDev); ReleaseHandle(handle); if (errCode == E_OK && isNeedNotify) { NotifyRemovedData(entries); @@ -1120,7 +1093,7 @@ SQLiteSingleVerStorageExecutor *SQLiteSingleVerNaturalStore::GetHandle(bool isWr CorruptNotify(); errCode = -E_INVALID_PASSWD_OR_CORRUPTED_DB; engineMutex_.unlock_shared(); // unlock when get handle failed. - LOGI("Handle is corrupted can not to get! errCode = [%d]", errCode); + LOGI("Handle is corrupted or invalid passwd, can not to get! errCode = [%d]", errCode); return nullptr; } @@ -1484,9 +1457,16 @@ int SQLiteSingleVerNaturalStore::Export(const std::string &filePath, const Ciphe std::unique_ptr operation = std::make_unique(this, storageEngine_); operation->SetLocalDevId(localDev); + errCode = TryToDisableConnection(OperatePerm::NORMAL_WRITE); + if (errCode != E_OK) { + LOGE("disable connection failed! errCode %d", errCode); + ReleaseHandle(handle); + return errCode; + } LOGI("Begin export the kv store"); errCode = operation->Export(filePath, passwd); + ReEnableConnection(OperatePerm::NORMAL_WRITE); ReleaseHandle(handle); return errCode; } @@ -2410,5 +2390,52 @@ void SQLiteSingleVerNaturalStore::Dump(int fd) SyncAbleKvDB::Dump(fd); } +int SQLiteSingleVerNaturalStore::RemoveDeviceDataInner(const std::string &hashDev, bool isNeedNotify) +{ + int errCode = E_OK; + SQLiteSingleVerStorageExecutor *handle = GetHandle(true, errCode); + if (handle == nullptr) { + LOGE("[SingleVerNStore] RemoveDeviceData get handle failed:%d", errCode); + return errCode; + } + uint64_t logFileSize = handle->GetLogFileSize(); + ReleaseHandle(handle); + if (logFileSize > GetMaxLogSize()) { + LOGW("[SingleVerNStore] RmDevData log size[%" PRIu64 "] over the limit", logFileSize); + return -E_LOG_OVER_LIMITS; + } + + std::set removeDevices; + if (hashDev.empty()) { + errCode = GetExistsDeviceList(removeDevices); + if (errCode != E_OK) { + LOGE("[SingleVerNStore] get remove device list failed:%d", errCode); + return errCode; + } + } else { + removeDevices.insert(hashDev); + } + + LOGD("[SingleVerNStore] remove device data, size=%zu", removeDevices.size()); + for (const auto &iterDevice : removeDevices) { + // Call the syncer module to erase the water mark. + errCode = EraseDeviceWaterMark(iterDevice, false); + if (errCode != E_OK) { + LOGE("[SingleVerNStore] erase water mark failed:%d", errCode); + return errCode; + } + } + + if (IsExtendedCacheDBMode()) { + errCode = RemoveDeviceDataInCacheMode(hashDev, isNeedNotify); + } else { + errCode = RemoveDeviceDataNormally(hashDev, isNeedNotify); + } + if (errCode != E_OK) { + LOGE("[SingleVerNStore] RemoveDeviceData failed:%d", errCode); + } + + return errCode; +} DEFINE_OBJECT_TAG_FACILITIES(SQLiteSingleVerNaturalStore) } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h index d9a63145e9429d63a5c63ea516d727ca8d585864..0bb1a832eae8093425e4f63f9bf1609aa44dbe43 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h @@ -244,9 +244,9 @@ private: // Change value that should be amended, and neglect value that is incompatible void CheckAmendValueContentForSyncProcedure(std::vector &dataItems) const; - int RemoveDeviceDataInCacheMode(const std::string &deviceName, bool isNeedNotify); + int RemoveDeviceDataInCacheMode(const std::string &hashDev, bool isNeedNotify) const; - int RemoveDeviceDataNormally(const std::string &deviceName, bool isNeedNotify); + int RemoveDeviceDataNormally(const std::string &hashDev, bool isNeedNotify); int SaveSyncDataToMain(const QueryObject &query, std::vector &dataItems, const DeviceInfo &deviceInfo); @@ -275,6 +275,8 @@ private: int GetExistsDeviceList(std::set &devices) const; + int RemoveDeviceDataInner(const std::string &hashDev, bool isNeedNotify); + DECLARE_OBJECT_TAG(SQLiteSingleVerNaturalStore); Timestamp currentMaxTimestamp_ = 0; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp index ca6de67dfc1ccf5f3dc4ce52b71e9c8cbf0dd059..7a06386a95cfffc88cdd496a48442019322b35cf 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp @@ -1276,6 +1276,14 @@ int SQLiteSingleVerNaturalStoreConnection::StartTransactionNormally(TransactType if (handle == nullptr) { return errCode; } + + errCode = kvDB_->TryToDisableConnection(OperatePerm::NORMAL_WRITE); + if (errCode != E_OK) { + ReleaseExecutor(handle); + LOGE("Start transaction failed, %d", errCode); + return errCode; + } + if (CheckLogOverLimit(handle)) { LOGW("Over the log limit"); ReleaseExecutor(handle); @@ -1399,6 +1407,7 @@ bool SQLiteSingleVerNaturalStoreConnection::IsExtendedCacheDBMode() const void SQLiteSingleVerNaturalStoreConnection::ReleaseExecutor(SQLiteSingleVerStorageExecutor *&executor) const { + kvDB_->ReEnableConnection(OperatePerm::NORMAL_WRITE); SQLiteSingleVerNaturalStore *naturalStore = GetDB(); if (naturalStore != nullptr) { naturalStore->ReleaseHandle(executor); @@ -1833,5 +1842,31 @@ int SQLiteSingleVerNaturalStoreConnection::GetEntriesInner(bool isGetValue, cons return errCode; } +int SQLiteSingleVerNaturalStoreConnection::UpdateKey(const DistributedDB::UpdateKeyCallback &callback) +{ + if (IsExtendedCacheDBMode()) { + LOGE("[Connection] Not support update key in cache mode"); + return -E_NOT_SUPPORT; + } + int errCode = E_OK; + { + std::lock_guard lock(transactionMutex_); + if (writeHandle_ != nullptr) { + LOGD("[Connection] Transaction started already."); + errCode = writeHandle_->UpdateKey(callback); + return errCode; + } + } + + SQLiteSingleVerStorageExecutor *handle = GetExecutor(true, errCode); + if (handle == nullptr) { + LOGE("[Connection]::[UpdateKey] Get executor failed, errCode = [%d]", errCode); + return errCode; + } + + errCode = handle->UpdateKey(callback); + ReleaseExecutor(handle); + return errCode; +} DEFINE_OBJECT_TAG_FACILITIES(SQLiteSingleVerNaturalStoreConnection) } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.h index 84381bfcb90f8669fc9e4a1314c445b8d20fb85f..330876c6a9d706a6e678a516b0858c31da9a7a85 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.h @@ -107,6 +107,7 @@ public: int GetKeys(const IOption &option, const Key &keyPrefix, std::vector &keys) const override; + int UpdateKey(const UpdateKeyCallback &callback) override; private: int CheckMonoStatus(OperatePerm perm); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp index 3c3fbbac545d7447ba3e9fde2d610fb753e529a7..b7435d94f9272979a53ae5ec81b813dfbe8b123c 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp @@ -167,5 +167,46 @@ void SQLiteSingleVerRelationalContinueToken::UpdateNextSyncOffset(int addOffset) } queryObj_.SetLimit(limit - addOffset, offset + addOffset); } + +void SQLiteSingleVerRelationalContinueToken::SetCloudTableSchema(const TableSchema &schema) +{ + tableSchema_ = schema; +} + +int SQLiteSingleVerRelationalContinueToken::GetCloudStatement(sqlite3 *db, sqlite3_stmt *&queryStmt, bool &isFirstTime) +{ + if (queryStmt_ != nullptr) { + queryStmt = queryStmt_; + isFirstTime = false; + return E_OK; + } + int errCode; + SqliteQueryHelper helper = queryObj_.GetQueryHelper(errCode); + if (errCode != E_OK) { + return errCode; + } + errCode = helper.GetRelationalCloudQueryStatement(db, timeRange_.beginTime, tableSchema_.fields, queryStmt_); + if (errCode == E_OK) { + queryStmt = queryStmt_; + } + isFirstTime = true; + return errCode; +} + +void SQLiteSingleVerRelationalContinueToken::GetCloudTableSchema(TableSchema &tableSchema) +{ + tableSchema = tableSchema_; +} + +int SQLiteSingleVerRelationalContinueToken::ReleaseCloudStatement() +{ + if (queryStmt_ == nullptr) { + return E_OK; + } + int errCode = E_OK; + SQLiteUtils::ResetStatement(queryStmt_, true, errCode); + queryStmt_ = nullptr; + return errCode; +} } // namespace DistributedDB #endif \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.h index 69906191541f5edc8bcaf0d00fbb00b0a37ed2d5..518075047b540d9dcd8ae32dd20ede83c9d61248 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.h @@ -20,6 +20,7 @@ #include "db_types.h" #include "query_object.h" +#include "cloud_store_types.h" namespace DistributedDB { class SQLiteSingleVerRelationalContinueToken { @@ -37,6 +38,10 @@ public: const QueryObject &GetQuery() const; void SetFieldNames(const std::vector &fieldNames); void UpdateNextSyncOffset(int addOffset); + void SetCloudTableSchema(const TableSchema &tableSchema); + int GetCloudStatement(sqlite3 *db, sqlite3_stmt *&queryStmt, bool &isFirstTime); + void GetCloudTableSchema(TableSchema &tableSchema); + int ReleaseCloudStatement(); private: std::string GetDeletedDataSQL() const; int GetQuerySyncStatement(sqlite3 *db, sqlite3_stmt *&stmt); @@ -52,6 +57,8 @@ private: SyncTimeRange timeRange_; std::vector fieldNames_; unsigned int magicEnd_ = MAGIC_END; + TableSchema tableSchema_; + sqlite3_stmt *queryStmt_ = nullptr; }; } // namespace DistributedDB #endif // RELATIONAL_STORE diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp index 02c5c7a6f1892811624dbaf4a9ce7825b8b62bd2..25c2e1c2d3c3b714c9ac774cc6c1f16c46e1231c 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp @@ -18,15 +18,22 @@ #include #include +#include "cloud/cloud_db_constant.h" #include "data_transformer.h" #include "db_common.h" #include "log_table_manager_factory.h" #include "relational_row_data_impl.h" #include "res_finalizer.h" +#include "sqlite_meta_executor.h" #include "sqlite_relational_utils.h" +#include "value_hash_calc.h" namespace DistributedDB { namespace { +static constexpr const char* CLOUD_FLAG[] = { "ROWID", "FLAG" }; +static constexpr uint64_t DELETE_FLAG = 0x01; +static constexpr uint64_t LOCAL_FLAG = 0x02; + int PermitSelect(void *a, int b, const char *c, const char *d, const char *e, const char *f) { if (b != SQLITE_SELECT && b != SQLITE_READ && b != SQLITE_FUNCTION) { @@ -107,17 +114,18 @@ int SQLiteSingleVerRelationalStorageExecutor::GeneLogInfoForExistedData(sqlite3 std::string logTable = DBConstant::RELATIONAL_PREFIX + tableName + "_log"; std::string sql = "INSERT INTO " + logTable + " SELECT rowid, '', '', " + timeOffsetStr + " + rowid, " + timeOffsetStr + " + rowid, 0x2, " + - calPrimaryKeyHash + " FROM '" + tableName + "' AS a WHERE 1=1;"; + calPrimaryKeyHash + ", ''" + " FROM '" + tableName + "' AS a WHERE 1=1;"; return SQLiteUtils::ExecuteRawSQL(db, sql); } -int SQLiteSingleVerRelationalStorageExecutor::CreateDistributedTable(const std::string &tableName, - DistributedTableMode mode, bool isUpgraded, const std::string &identity, TableInfo &table) +int SQLiteSingleVerRelationalStorageExecutor::CreateDistributedTable(DistributedTableMode mode, bool isUpgraded, + const std::string &identity, TableInfo &table, TableSyncType syncType) { if (dbHandle_ == nullptr) { return -E_INVALID_DB; } + const std::string tableName = table.GetTableName(); int errCode = SQLiteUtils::AnalysisSchema(dbHandle_, tableName, table); if (errCode != E_OK) { LOGE("[CreateDistributedTable] analysis table schema failed. %d", errCode); @@ -133,14 +141,16 @@ int SQLiteSingleVerRelationalStorageExecutor::CreateDistributedTable(const std:: } } - errCode = CheckTableConstraint(table, mode); - if (errCode != E_OK) { - LOGE("[CreateDistributedTable] check table constraint failed."); - return errCode; + if (syncType != CLOUD_COOPERATION) { + errCode = CheckTableConstraint(table, mode); + if (errCode != E_OK) { + LOGE("[CreateDistributedTable] check table constraint failed."); + return errCode; + } } // create log table - auto tableManager = LogTableManagerFactory::GetTableManager(mode); + auto tableManager = LogTableManagerFactory::GetTableManager(mode, syncType); errCode = tableManager->CreateRelationalLogTable(dbHandle_, table); if (errCode != E_OK) { LOGE("[CreateDistributedTable] create log table failed"); @@ -210,8 +220,7 @@ int GetDeviceTableName(sqlite3 *handle, const std::string &tableName, const std: if (device.empty() && tableName.empty()) { // device and table name should not both be empty return -E_INVALID_ARGS; } - std::string deviceHash = DBCommon::TransferStringToHex(DBCommon::TransferHashString(device)); - std::string devicePattern = device.empty() ? "%" : deviceHash; + std::string devicePattern = device.empty() ? "%" : device; std::string tablePattern = tableName.empty() ? "%" : tableName; std::string deviceTableName = DBConstant::RELATIONAL_PREFIX + tablePattern + "_" + devicePattern; @@ -461,6 +470,55 @@ static int GetLogData(sqlite3_stmt *logStatement, LogInfo &logInfo) return SQLiteUtils::GetColumnBlobValue(logStatement, 6, logInfo.hashKey); // 6 means hashKey index } +namespace { +inline std::string GetLogTableName(const std::string tableName) +{ + return DBConstant::RELATIONAL_PREFIX + tableName + "_log"; +} + +void GetCloudLog(sqlite3_stmt *logStatement, VBucket &logInfo, uint32_t &totalSize) +{ + logInfo.insert_or_assign(CloudDbConstant::MODIFY_FIELD, + static_cast(sqlite3_column_int64(logStatement, 3))); // 3 means timestamp index + logInfo.insert_or_assign(CloudDbConstant::CREATE_FIELD, + static_cast(sqlite3_column_int64(logStatement, 4))); // 4 means w_timestamp index + totalSize += 2 * sizeof(int64_t); + if (sqlite3_column_text(logStatement, 7) != nullptr) { + std::string cloudGid = reinterpret_cast( + sqlite3_column_text(logStatement, 7)); // 7 means cloudGid index + if (!cloudGid.empty()) { + logInfo.insert_or_assign(CloudDbConstant::GID_FIELD, cloudGid); + totalSize += cloudGid.size(); + } + } +} + +void GetCloudFlag(sqlite3_stmt *logStatement, VBucket &flags) +{ + flags.insert_or_assign(CLOUD_FLAG[0], + static_cast(sqlite3_column_int64(logStatement, 0))); // 0 means hash_key index + flags.insert_or_assign(CLOUD_FLAG[1], + static_cast(sqlite3_column_int64(logStatement, 5))); // 5 means flag index +} + +void IdentifyCloudType(CloudSyncData &cloudSyncData, VBucket &data, VBucket &log, VBucket &flags) +{ + int64_t rowid = std::get(flags[CLOUD_FLAG[0]]); + int64_t flag = std::get(flags[CLOUD_FLAG[1]]); + if (flag & DELETE_FLAG) { + cloudSyncData.delData.record.push_back(data); + cloudSyncData.delData.extend.push_back(log); + } else if (log.find(CloudDbConstant::GID_FIELD) == log.end()) { + cloudSyncData.insData.record.push_back(data); + cloudSyncData.insData.extend.push_back(log); + cloudSyncData.insData.rowid.push_back(rowid); + } else { + cloudSyncData.updData.record.push_back(data); + cloudSyncData.updData.extend.push_back(log); + } +} +} + static size_t GetDataItemSerialSize(DataItem &item, size_t appendLen) { // timestamp and local flag: 3 * uint64_t, version(uint32_t), key, value, origin dev and the padding size. @@ -579,33 +637,6 @@ int SQLiteSingleVerRelationalStorageExecutor::DeleteMetaDataByPrefixKey(const Ke return CheckCorruptedStatus(errCode); } -static int GetAllKeys(sqlite3_stmt *statement, std::vector &keys) -{ - if (statement == nullptr) { - return -E_INVALID_DB; - } - int errCode; - do { - errCode = SQLiteUtils::StepWithRetry(statement, false); - if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { - Key key; - errCode = SQLiteUtils::GetColumnBlobValue(statement, 0, key); - if (errCode != E_OK) { - break; - } - - keys.push_back(std::move(key)); - } else if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { - errCode = E_OK; - break; - } else { - LOGE("SQLite step for getting all keys failed:%d", errCode); - break; - } - } while (true); - return errCode; -} - int SQLiteSingleVerRelationalStorageExecutor::GetAllMetaKeys(std::vector &keys) const { static const std::string SELECT_ALL_META_KEYS = "SELECT key FROM " + DBConstant::RELATIONAL_PREFIX + "metadata;"; @@ -615,7 +646,7 @@ int SQLiteSingleVerRelationalStorageExecutor::GetAllMetaKeys(std::vector &k LOGE("[Relational][GetAllKey] Get statement failed:%d", errCode); return errCode; } - errCode = GetAllKeys(statement, keys); + errCode = SqliteMetaExecutor::GetAllKeys(statement, isMemDb_, keys); SQLiteUtils::ResetStatement(statement, true, errCode); return errCode; } @@ -1091,6 +1122,12 @@ int SQLiteSingleVerRelationalStorageExecutor::DeleteDistributedDeviceTable(const return errCode; } +int SQLiteSingleVerRelationalStorageExecutor::DeleteDistributedAllDeviceTableLog(const std::string &tableName) +{ + std::string deleteLogSql = "DELETE FROM " + DBConstant::RELATIONAL_PREFIX + tableName + "_log WHERE flag&0x02=0"; + return SQLiteUtils::ExecuteRawSQL(dbHandle_, deleteLogSql); +} + int SQLiteSingleVerRelationalStorageExecutor::DeleteDistributedDeviceTableLog(const std::string &device, const std::string &tableName) { @@ -1179,7 +1216,7 @@ int SQLiteSingleVerRelationalStorageExecutor::CheckAndCleanDistributedTable(cons } int SQLiteSingleVerRelationalStorageExecutor::CreateDistributedDeviceTable(const std::string &device, - const TableInfo &baseTbl) + const TableInfo &baseTbl, const StoreInfo &info) { if (dbHandle_ == nullptr) { return -E_INVALID_DB; @@ -1189,7 +1226,7 @@ int SQLiteSingleVerRelationalStorageExecutor::CreateDistributedDeviceTable(const return -E_INVALID_ARGS; } - std::string deviceTableName = DBCommon::GetDistributedTableName(device, baseTbl.GetTableName()); + std::string deviceTableName = DBCommon::GetDistributedTableName(device, baseTbl.GetTableName(), info); int errCode = SQLiteUtils::CreateSameStuTable(dbHandle_, baseTbl, deviceTableName); if (errCode != E_OK) { LOGE("Create device table failed. %d", errCode); @@ -1370,5 +1407,813 @@ int SQLiteSingleVerRelationalStorageExecutor::CheckEncryptedOrCorrupted() const } return errCode; } + +int SQLiteSingleVerRelationalStorageExecutor::GetExistsDeviceList(std::set &devices) const +{ + return SqliteMetaExecutor::GetExistsDevicesFromMeta(dbHandle_, SqliteMetaExecutor::MetaMode::RDB, + isMemDb_, devices); +} + +int SQLiteSingleVerRelationalStorageExecutor::GetUploadCount(const std::string &tableName, + const Timestamp ×tamp, int64_t &count) +{ + std::string sql = "SELECT count(rowid) from " + GetLogTableName(tableName) + + " where timestamp > ? and (flag & 0x02) = 0x02 and (cloud_gid != ''" + " or (cloud_gid == '' and (flag & 0x01) = 0 ));"; + sqlite3_stmt *stmt = nullptr; + int errCode = SQLiteUtils::GetStatement(dbHandle_, sql, stmt); + if (errCode != E_OK) { + return errCode; + } + errCode = SQLiteUtils::BindInt64ToStatement(stmt, 1, timestamp); + if (errCode != E_OK) { + SQLiteUtils::ResetStatement(stmt, true, errCode); + return errCode; + } + errCode = SQLiteUtils::StepWithRetry(stmt, isMemDb_); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { + count = static_cast(sqlite3_column_int64(stmt, 0)); + errCode = E_OK; + } else { + LOGE("Failed to get the count to be uploaded. %d", errCode); + } + SQLiteUtils::ResetStatement(stmt, true, errCode); + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::UpdateCloudLogGid(const CloudSyncData &cloudDataResult) +{ + if (cloudDataResult.insData.extend.empty() || cloudDataResult.insData.rowid.empty() || + cloudDataResult.insData.extend.size() != cloudDataResult.insData.rowid.size()) { + return -E_INVALID_ARGS; + } + std::string sql = "UPDATE " + GetLogTableName(cloudDataResult.tableName) + + " SET cloud_gid = ? where data_key = ? "; + sqlite3_stmt *stmt = nullptr; + int errCode = SQLiteUtils::GetStatement(dbHandle_, sql, stmt); + if (errCode != E_OK) { + return errCode; + } + for (size_t i = 0; i < cloudDataResult.insData.extend.size(); ++i) { + auto gidEntry = cloudDataResult.insData.extend[i].find(CloudDbConstant::GID_FIELD); + int64_t rowid = cloudDataResult.insData.rowid[i]; + if (gidEntry == cloudDataResult.insData.extend[i].end()) { + errCode = -E_INVALID_ARGS; + goto END; + } + if (gidEntry->second.index() != TYPE_INDEX) { + errCode = -E_TYPE_MISMATCH; + goto END; + } + errCode = SQLiteUtils::BindTextToStatement(stmt, 1, std::get(gidEntry->second)); + if (errCode != E_OK) { + goto END; + } + errCode = SQLiteUtils::BindInt64ToStatement(stmt, 2, rowid); + if (errCode != E_OK) { + goto END; + } + errCode = SQLiteUtils::StepWithRetry(stmt, false); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { + errCode = E_OK; + SQLiteUtils::ResetStatement(stmt, false, errCode); + } else { + LOGE("Update cloud log failed:%d", errCode); + break; + } + } + +END: + SQLiteUtils::ResetStatement(stmt, true, errCode); + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::GetSyncCloudData(CloudSyncData &cloudDataResult, + const uint32_t &maxSize, SQLiteSingleVerRelationalContinueToken &token) +{ + token.GetCloudTableSchema(tableSchema_); + baseTblName_ = tableSchema_.name; + sqlite3_stmt *queryStmt = nullptr; + bool isStepNext = false; + int errCode = token.GetCloudStatement(dbHandle_, queryStmt, isStepNext); + if (errCode != E_OK) { + (void)token.ReleaseCloudStatement(); + return errCode; + } + Timestamp queryTime = 0; + uint32_t totalSize = 0; + do { + if (isStepNext) { + errCode = StepNext(isMemDb_, queryStmt, queryTime); + if (errCode != E_OK || queryTime == INT64_MAX) { + break; + } + } + isStepNext = true; + errCode = GetCloudDataForSync(queryStmt, cloudDataResult, totalSize, maxSize); + if (errCode != E_OK) { + break; + } + } while (true); + if (errCode == -E_UNFINISHED) { + return errCode; + } + (void)token.ReleaseCloudStatement(); + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::GetCloudDataForSync(sqlite3_stmt *statement, + CloudSyncData &cloudDataResult, uint32_t &totalSize, const uint32_t &maxSize) +{ + VBucket log; + VBucket flags; + GetCloudLog(statement, log, totalSize); + GetCloudFlag(statement, flags); + + int errCode; + VBucket data; + for (size_t cid = 0; cid < tableSchema_.fields.size(); ++cid) { + Type cloudValue; + errCode = SQLiteRelationalUtils::GetCloudValueByType(statement, + tableSchema_.fields[cid].type, cid + 8, cloudValue); // 8 is the start index of query cloud data + if (errCode != E_OK) { + return errCode; + } + SQLiteRelationalUtils::CalCloudValueLen(cloudValue, totalSize); + GetVBucketByType(data, cid, cloudValue); + } + if (totalSize < maxSize) { + IdentifyCloudType(cloudDataResult, data, log, flags); + } else { + errCode = -E_UNFINISHED; + } + return errCode; +} + +std::vector SQLiteSingleVerRelationalStorageExecutor::AssetToBlob(const Asset &asset) +{ + return {}; +} + +std::vector SQLiteSingleVerRelationalStorageExecutor::AssetsToBlob(const Assets &assets) +{ + return {}; +} + +Asset SQLiteSingleVerRelationalStorageExecutor::BlobToAsset(const std::vector &blob) +{ + return {}; +} + +Assets SQLiteSingleVerRelationalStorageExecutor::BlobToAssets(std::vector &blob) +{ + return {}; +} + +void SQLiteSingleVerRelationalStorageExecutor::GetVBucketByType(VBucket &vBucket, int cid, Type &cloudValue) { + if (tableSchema_.fields[cid].type == TYPE_INDEX) { + Asset asset = BlobToAsset(std::get(cloudValue)); + vBucket.insert_or_assign(tableSchema_.fields[cid].colName, asset); + } else if (tableSchema_.fields[cid].type == TYPE_INDEX) { + Assets assets = BlobToAssets(std::get(cloudValue)); + vBucket.insert_or_assign(tableSchema_.fields[cid].colName, assets); + } else { + vBucket.insert_or_assign(tableSchema_.fields[cid].colName, cloudValue); + } +} + +int SQLiteSingleVerRelationalStorageExecutor::GetLogInfoByPrimaryKeyOrGid(const TableSchema &tableSchema, + const VBucket &vBucket, LogInfo &logInfo) +{ + std::string querySql; + std::set pkSet = GetCloudPrimaryKey(tableSchema); + int errCode = GetQueryLogSql(tableSchema.name, vBucket, pkSet, querySql); + if (errCode != E_OK) { + LOGE("Get query log sql fail, %d", errCode); + return errCode; + } + + sqlite3_stmt *selectStmt = nullptr; + errCode = GetQueryLogStatement(tableSchema, vBucket, querySql, pkSet, selectStmt); + if (errCode != E_OK) { + LOGE("Get query log statement fail, %d", errCode); + return errCode; + } + + bool alreadyFound = false; + do { + errCode = SQLiteUtils::StepWithRetry(selectStmt); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { + if (alreadyFound) { + LOGE("found two records in log table for one primary key."); + errCode = -E_INTERNAL_ERROR; + break; + } + alreadyFound = true; + GetLogInfoByStatement(selectStmt, logInfo); + } else if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { + if (alreadyFound) { + errCode = E_OK; + } else { + errCode = -E_NOT_FOUND; + } + break; + } else { + LOGE("SQLite step failed when query log for cloud sync:%d", errCode); + break; + } + } while (true); + + SQLiteUtils::ResetStatement(selectStmt, true, errCode); + return errCode; +} + +void SQLiteSingleVerRelationalStorageExecutor::GetLogInfoByStatement(sqlite3_stmt *statement, LogInfo &logInfo) +{ + logInfo.dataKey = sqlite3_column_int64(statement, 1); + (void)SQLiteUtils::GetColumnTextValue(statement, 2, logInfo.originDev); + logInfo.timestamp = sqlite3_column_int64(statement, 4); + logInfo.wTimestamp = sqlite3_column_int64(statement, 5); + logInfo.flag = sqlite3_column_int(statement, 6); + (void)SQLiteUtils::GetColumnBlobValue(statement, 7, logInfo.hashKey); + (void)SQLiteUtils::GetColumnTextValue(statement, 8, logInfo.cloudGid); +} + +std::set SQLiteSingleVerRelationalStorageExecutor::GetCloudPrimaryKey(const TableSchema &tableSchema) +{ + std::set pkSet; + for (const auto &field : tableSchema.fields) { + if (field.primary) { + pkSet.insert(field.colName); + } + } + return pkSet; +} + +std::vector SQLiteSingleVerRelationalStorageExecutor::GetCloudPrimaryKeyField(const TableSchema &tableSchema) +{ + std::vector pkVec; + for (const auto &field : tableSchema.fields) { + if (field.primary) { + pkVec.push_back(field); + } + } + return pkVec; +} + +std::map SQLiteSingleVerRelationalStorageExecutor::GetCloudPrimaryKeyFieldMap( + const TableSchema &tableSchema) +{ + std::map pkMap; + for (const auto &field : tableSchema.fields) { + if (field.primary) { + pkMap[field.colName] = field; + } + } + return pkMap; +} + +Field SQLiteSingleVerRelationalStorageExecutor::GetFieldByName(const TableSchema &tableSchema, const std::string &name) +{ + for (const auto &field : tableSchema.fields) { + if (field.colName == name) { + return field; + } + } + return {}; +} + +std::string SQLiteSingleVerRelationalStorageExecutor::GetInsertSqlForCloudSync(const TableSchema &tableSchema) +{ + std::string sql = "insert into " + tableSchema.name + "("; + for (const auto &field : tableSchema.fields) { + sql += field.colName + ","; + } + sql.pop_back(); + sql += ") values("; + for (const auto &field : tableSchema.fields) { + sql += "?,"; + } + sql.pop_back(); + sql += ");"; + return sql; +} + +int SQLiteSingleVerRelationalStorageExecutor::GetPrimaryKeyHashValue(const VBucket &vBucket, + const TableSchema &tableSchema, std::vector &hashValue) +{ + int errCode = E_OK; + std::map pkMap = GetCloudPrimaryKeyFieldMap(tableSchema); + if (pkMap.size() == 1) { + std::vector pkVec = GetCloudPrimaryKeyField(tableSchema); + errCode = CalcHashKeyForOneField(pkVec.at(0), vBucket, hashValue); + } else { + std::vector tempRes; + for (const auto &item: pkMap) { + std::vector temp; + errCode = CalcHashKeyForOneField(item.second, vBucket, temp); + if (errCode != E_OK) { + LOGE("calc hash fail when there is more than one primary key. errCode = %d", errCode); + } + tempRes.insert(tempRes.end(), temp.begin(), temp.end()); + } + errCode = DBCommon::CalcValueHash(tempRes, hashValue); + } + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::GetQueryLogStatement(const TableSchema &tableSchema, + const VBucket &vBucket, const std::string &querySql, std::set &pkSet, sqlite3_stmt *&selectStmt) +{ + int errCode = SQLiteUtils::GetStatement(dbHandle_, querySql, selectStmt); + if (errCode != E_OK) { + LOGE("Get select log statement failed, %d", errCode); + return errCode; + } + + std::vector hashValue; + if (pkSet.size() == 0) { + hashValue.resize(0); + } else { + errCode = GetPrimaryKeyHashValue(vBucket, tableSchema, hashValue); + } + if (errCode != E_OK) { + LOGE("calc hash fail when get query log statement, errCode = %d", errCode); + SQLiteUtils::ResetStatement(selectStmt, true, errCode); + return errCode; + } + + errCode = SQLiteUtils::BindBlobToStatement(selectStmt, 1, hashValue, true); + if (errCode != E_OK) { + LOGE("Bind hash key to query log statement failed. %d", errCode); + SQLiteUtils::ResetStatement(selectStmt, true, errCode); + return errCode; + } + + std::string cloudGid = std::get(vBucket.at(CloudDbConstant::GID_FIELD)); + if(!cloudGid.empty()) { + errCode = SQLiteUtils::BindTextToStatement(selectStmt, 2, cloudGid); + if (errCode != E_OK) { + LOGE("Bind cloud gid to query log statement failed. %d", errCode); + SQLiteUtils::ResetStatement(selectStmt, true, errCode); + return errCode; + } + } + return E_OK; +} + +int SQLiteSingleVerRelationalStorageExecutor::CalcHashKeyForOneField(const Field &field, const VBucket &vBucket, + std::vector &hashValue) +{ + std::vector value; + switch (field.type) { + case TYPE_INDEX: + case TYPE_INDEX: + DBCommon::StringToVector(std::to_string(std::get(vBucket.at(field.colName))), value); + break; + case TYPE_INDEX: + DBCommon::StringToVector(std::to_string(std::get(vBucket.at(field.colName))), value); + break; + case TYPE_INDEX: + DBCommon::StringToVector(std::get(vBucket.at(field.colName)), value); + break; + case TYPE_INDEX: + value = std::get>(vBucket.at(field.colName)); + break; + default: + return -E_INVALID_ARGS; + } + + return DBCommon::CalcValueHash(value, hashValue); +} + +int SQLiteSingleVerRelationalStorageExecutor::GetQueryLogSql(const std::string &tableName, const VBucket &vBucket, + std::set &pkSet, std::string &querySql) +{ + Type cloudValue = vBucket.at(CloudDbConstant::GID_FIELD); + std::string *cloudGid = std::get_if(&cloudValue); + if (cloudGid == nullptr) { + LOGE("Get cloud gid fail when query log table."); + return -E_INVALID_ARGS; + } + + if (pkSet.empty() && (*cloudGid).empty()) { + LOGE("query log table failed because of both primary key and gid are empty."); + return -E_INVALID_ARGS; + } + std::string sql = "select data_key, device, ori_device, timestamp, wtimestamp, flag, hash_key, cloud_gid FROM " + + DBConstant::RELATIONAL_PREFIX + tableName + "_log WHERE hash_key = ?"; + + if (!(*cloudGid).empty()) { + sql += " or cloud_gid = ?"; + } + + querySql = sql; + return E_OK; +} + +int SQLiteSingleVerRelationalStorageExecutor::PutCloudSyncData(const std::string &tableName, + const DownloadData &downloadData, const TableSchema &tableSchema) +{ + if (downloadData.data.size() != downloadData.opType.size()) { + return -E_INVALID_ARGS; + } + + int errCode = SetLogTriggerStatus(false); + if (errCode != E_OK) { + LOGE("Fail to set log trigger off, %d", errCode); + return errCode; + } + + int index = 0; + for (OpType op : downloadData.opType) { + VBucket vBucket = downloadData.data[index]; + switch (op) { + case OpType::INSERT: + errCode = InsertCloudData(tableName, vBucket, tableSchema); + if (errCode != errCode) { + break; + } + case OpType::UPDATE: + errCode = UpdateCloudData(tableName, vBucket, tableSchema); + if (errCode != errCode) { + break; + } + case OpType::DELETE: + errCode = DeleteCloudData(tableName, vBucket, tableSchema); + if (errCode != errCode) { + break; + } + case OpType::ONLY_UPDATE_GID: + errCode = UpdateCloudGid(tableName, vBucket, tableSchema); + if (errCode != errCode) { + break; + } + case OpType::NOT_HANDLE: + default: + break; + } + index++; + } + + int ret = SetLogTriggerStatus(true); + if (ret != E_OK) { + LOGE("Fail to set log trigger on, %d", ret); + } + return errCode == E_OK ? ret : errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::InsertCloudData(const std::string &tableName, const VBucket &vBucket, + const TableSchema &tableSchema) +{ + std::string sql = GetInsertSqlForCloudSync(tableSchema); + sqlite3_stmt *insertStmt = nullptr; + int errCode = SQLiteUtils::GetStatement(dbHandle_, sql, insertStmt); + if (errCode != E_OK) { + LOGE("Get insert statement failed when save cloud data, %d", errCode); + return errCode; + } + + errCode = BindValueToUpsertStatement(vBucket, tableSchema.fields, insertStmt); + if (errCode != E_OK) { + SQLiteUtils::ResetStatement(insertStmt, true, errCode); + return errCode; + } + // insert data + errCode = SQLiteUtils::StepWithRetry(insertStmt, false); + SQLiteUtils::ResetStatement(insertStmt, true, errCode); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { + errCode = E_OK; + } else { + LOGE("insert data failed when save cloud data:%d", errCode); + return errCode; + } + + // insert log + sql = "insert into " + DBConstant::RELATIONAL_PREFIX + tableName + "_log values(?, ?, ?, ?, ?, ?, ?, ?)"; + sqlite3_stmt *insertLogStmt = nullptr; + errCode = SQLiteUtils::GetStatement(dbHandle_, sql, insertLogStmt); + if (errCode != E_OK) { + LOGE("Get insert log statement failed when save cloud data, %d", errCode); + return errCode; + } + + errCode = BindValueToInsertLogStatement(vBucket, tableSchema, insertLogStmt); + if (errCode != E_OK) { + SQLiteUtils::ResetStatement(insertLogStmt, true, errCode); + return errCode; + } + + errCode = SQLiteUtils::StepWithRetry(insertLogStmt, false); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { + errCode = E_OK; + } else { + LOGE("insert log data failed when save cloud data:%d", errCode); + } + SQLiteUtils::ResetStatement(insertLogStmt, true, errCode); + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::BindValueToUpsertStatement(const VBucket &vBucket, + const std::vector &fields, sqlite3_stmt *upsertStmt) +{ + int errCode = E_OK; + int index = 0; + for (const auto &field : fields) { + index++; + if (field.type == TYPE_INDEX) { + int64_t val = 0; + (void)GetValueFronVBucket(field.colName, vBucket, val); + errCode = SQLiteUtils::BindInt64ToStatement(upsertStmt, index, val); + if (errCode != E_OK) { + LOGE("Bind int to insert statement failed, %d", errCode); + return errCode; + } + } else if (field.type == TYPE_INDEX) { + bool val = 0; + (void)GetValueFronVBucket(field.colName, vBucket, val); + errCode = SQLiteUtils::MapSQLiteErrno(sqlite3_bind_int(upsertStmt, index, val)); + if (errCode != E_OK) { + LOGE("Bind bool to insert statement failed, %d", errCode); + return errCode; + } + } else if (field.type == TYPE_INDEX) { + double val = 0; + (void)GetValueFronVBucket(field.colName, vBucket, val); + errCode = SQLiteUtils::MapSQLiteErrno(sqlite3_bind_double(upsertStmt, index, val)); + if (errCode != E_OK) { + LOGE("Bind double to insert statement failed, %d", errCode); + return errCode; + } + } else if (field.type == TYPE_INDEX) { + std::string str; + (void)GetValueFronVBucket(field.colName, vBucket, str); + errCode = SQLiteUtils::BindTextToStatement(upsertStmt, index, str); + if (errCode != E_OK) { + LOGE("Bind double to insert statement failed, %d", errCode); + return errCode; + } + } else if (field.type == TYPE_INDEX) { + Bytes val; + (void)GetValueFronVBucket(field.colName, vBucket, val); + errCode = SQLiteUtils::BindBlobToStatement(upsertStmt, index, val); + if (errCode != E_OK) { + LOGE("Bind blob to insert statement failed, %d", errCode); + return errCode; + } + } else { + LOGE("unknown cloud type."); + return -E_INVALID_ARGS; + } + } + return E_OK; +} + +int SQLiteSingleVerRelationalStorageExecutor::BindValueToInsertLogStatement(const VBucket &vBucket, + const TableSchema &tableSchema, sqlite3_stmt *insertLogStmt) +{ + int64_t rowid = SQLiteUtils::GetLastRowId(dbHandle_); + int errCode = SQLiteUtils::BindInt64ToStatement(insertLogStmt, 1, rowid); + if (errCode != E_OK) { + LOGE("Bind rowid to insert log statement failed, %d", errCode); + return errCode; + } + + errCode = SQLiteUtils::BindTextToStatement(insertLogStmt, 2, "cloud"); // 2 is device + if (errCode != E_OK) { + LOGE("Bind device to insert log statement failed, %d", errCode); + return errCode; + } + + errCode = SQLiteUtils::BindTextToStatement(insertLogStmt, 3, "cloud"); // 2 is ori_device + if (errCode != E_OK) { + LOGE("Bind ori_device to insert log statement failed, %d", errCode); + return errCode; + } + + int64_t val = 0; + (void)GetValueFronVBucket(CloudDbConstant::MODIFY_FIELD, vBucket, val); + errCode = SQLiteUtils::BindInt64ToStatement(insertLogStmt, 4, val); // 4 is timestamp + if (errCode != E_OK) { + LOGE("Bind timestamp to insert log statement failed, %d", errCode); + return errCode; + } + + (void)GetValueFronVBucket(CloudDbConstant::CREATE_FIELD, vBucket, val); + errCode = SQLiteUtils::BindInt64ToStatement(insertLogStmt, 5, val); // 5 is wtimestamp + if (errCode != E_OK) { + LOGE("Bind wtimestamp to insert log statement failed, %d", errCode); + return errCode; + } + + errCode = SQLiteUtils::MapSQLiteErrno(sqlite3_bind_int(insertLogStmt, 6, 0)); // 6 is flag + if (errCode != E_OK) { + LOGE("Bind flag to insert log statement failed, %d", errCode); + return errCode; + } + + std::vector hashKey; + errCode = GetPrimaryKeyHashValue(vBucket, tableSchema, hashKey); + if (errCode != E_OK) { + return errCode; + } + errCode = SQLiteUtils::BindBlobToStatement(insertLogStmt, 7, hashKey); // 7 is hash_key + if (errCode != E_OK) { + LOGE("Bind hash_key to insert log statement failed, %d", errCode); + return errCode; + } + + std::string cloudGid; + (void)GetValueFronVBucket(CloudDbConstant::GID_FIELD, vBucket, cloudGid); + errCode = SQLiteUtils::BindTextToStatement(insertLogStmt, 8, cloudGid); // 8 is cloud_gid + if (errCode != E_OK) { + LOGE("Bind cloud_gid to insert log statement failed, %d", errCode); + } + return errCode; +} + +std::string SQLiteSingleVerRelationalStorageExecutor::GetUpdateSqlForCloudSync(const TableSchema &tableSchema, + const std::set &pkSet) +{ + std::string sql = "update " + tableSchema.name + " set"; + for (const auto &field : tableSchema.fields) { + sql += " " + field.colName + " = ?,"; + } + sql.pop_back(); + sql += " where"; + for (const auto &pk : pkSet) { + sql += (" " + pk + " = ?,"); + } + sql.pop_back(); + return sql; +} + +int SQLiteSingleVerRelationalStorageExecutor::UpdateCloudData(const std::string &tableName, const VBucket &vBucket, + const TableSchema &tableSchema) +{ + std::set pkSet = GetCloudPrimaryKey(tableSchema); + std::string sql = GetUpdateSqlForCloudSync(tableSchema, pkSet); + + sqlite3_stmt *updateStmt = nullptr; + int errCode = SQLiteUtils::GetStatement(dbHandle_, sql, updateStmt); + if (errCode != E_OK) { + LOGE("Get update statement failed when update cloud data, %d", errCode); + return errCode; + } + + errCode = BindValueToUpdateStatement(vBucket, tableSchema, updateStmt); + if (errCode != E_OK) { + SQLiteUtils::ResetStatement(updateStmt, true, errCode); + return errCode; + } + + // update data + errCode = SQLiteUtils::StepWithRetry(updateStmt, false); + SQLiteUtils::ResetStatement(updateStmt, true, errCode); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { + errCode = E_OK; + } else { + LOGE("update data failed when save cloud data:%d", errCode); + return errCode; + } + + // update log + errCode = UpdateLogRecord(vBucket, tableSchema, OpType::UPDATE); + if (errCode != E_OK) { + LOGE("update log record failed when update cloud data, errCode = %d", errCode); + } + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::BindValueToUpdateStatement(const VBucket &vBucket, + const TableSchema &tableSchema, sqlite3_stmt *updateStmt) +{ + std::vector fields = tableSchema.fields; + std::vector pkFields = GetCloudPrimaryKeyField(tableSchema); + fields.insert(fields.end(), pkFields.begin(), pkFields.end()); + int errCode = BindValueToUpsertStatement(vBucket, fields, updateStmt); + if (errCode != E_OK) { + LOGE("bind value to update statement failed when update cloud data, %d", errCode); + } + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::UpdateLogRecord(const VBucket &vBucket, const TableSchema &tableSchema, + OpType opType) +{ + sqlite3_stmt *updateLogStmt = nullptr; + std::string logTable = DBConstant::RELATIONAL_PREFIX + tableSchema.name + "_log"; + std::string updateLogSql = "update " + logTable + " set "; + std::vector fields; + if (opType == OpType::ONLY_UPDATE_GID) { + updateLogSql += "cloud_gid = ?"; + fields.push_back(GetFieldByName(tableSchema, CloudDbConstant::GID_FIELD)); + } else { + if (opType == OpType::DELETE) { + updateLogSql += "data_key = -1, flag = 1"; + } + updateLogSql += ",device = 'cloud', timestamp = ?, cloud_gid = ?"; + fields.push_back(GetFieldByName(tableSchema, CloudDbConstant::MODIFY_FIELD)); + fields.push_back(GetFieldByName(tableSchema, CloudDbConstant::GID_FIELD)); + } + updateLogSql += " where hash_key = ?"; + + int errCode = SQLiteUtils::GetStatement(dbHandle_, updateLogSql, updateLogStmt); + if (errCode != E_OK) { + LOGE("Get update log statement failed when update cloud data, %d", errCode); + return errCode; + } + + std::map pkMap = GetCloudPrimaryKeyFieldMap(tableSchema); + errCode = BindValueToUpdateLogStatement(vBucket, tableSchema, fields, pkMap, updateLogStmt); + if (errCode != E_OK) { + LOGE("bind value to update log statement failed when update cloud data, %d", errCode); + SQLiteUtils::ResetStatement(updateLogStmt, true, errCode); + return errCode; + } + + errCode = SQLiteUtils::StepWithRetry(updateLogStmt, false); + SQLiteUtils::ResetStatement(updateLogStmt, true, errCode); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { + errCode = E_OK; + } else { + LOGE("update log record failed when update cloud data:%d", errCode); + } + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::BindValueToUpdateLogStatement(const VBucket &vBucket, + const TableSchema &tableSchema, const std::vector &fields, std::map &pkMap, + sqlite3_stmt *updateLogStmt) +{ + int errCode = BindValueToUpsertStatement(vBucket, fields, updateLogStmt); + if (errCode != E_OK) { + return errCode; + } + + std::vector hashKey; + errCode = GetPrimaryKeyHashValue(vBucket, tableSchema, hashKey); + if (errCode != E_OK) { + return errCode; + } + return SQLiteUtils::BindBlobToStatement(updateLogStmt, fields.size() + 1, hashKey); +} + +int SQLiteSingleVerRelationalStorageExecutor::GetDeleteStatementForCloudSync(const TableSchema &tableSchema, + const std::set &pkSet, const VBucket &vBucket, sqlite3_stmt *&deleteStmt) +{ + std::string deleteSql = "delete from " + tableSchema.name + " where"; + for (const auto &pk : pkSet) { + deleteSql += (" " + pk + " = ?,"); + } + deleteSql.pop_back(); + + int errCode = SQLiteUtils::GetStatement(dbHandle_, deleteSql, deleteStmt); + if (errCode != E_OK) { + LOGE("Get delete statement failed when delete data, %d", errCode); + return errCode; + } + + std::vector pkFields = GetCloudPrimaryKeyField(tableSchema); + errCode = BindValueToUpsertStatement(vBucket, pkFields, deleteStmt); + if (errCode != E_OK) { + LOGE("bind value to delete statement failed when delete data, %d", errCode); + SQLiteUtils::ResetStatement(deleteStmt, true, errCode); + } + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::DeleteCloudData(const std::string &tableName, const VBucket &vBucket, + const TableSchema &tableSchema) +{ + std::set pkSet = GetCloudPrimaryKey(tableSchema); + sqlite3_stmt *deleteStmt = nullptr; + int errCode = GetDeleteStatementForCloudSync(tableSchema, pkSet, vBucket, deleteStmt); + if (errCode != E_OK) { + return errCode; + } + + errCode = SQLiteUtils::StepWithRetry(deleteStmt, false); + SQLiteUtils::ResetStatement(deleteStmt, true, errCode); + if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { + errCode = E_OK; + } else { + LOGE("delete data failed when sync with cloud:%d", errCode); + return errCode; + } + + // update log + errCode = UpdateLogRecord(vBucket, tableSchema, OpType::DELETE); + if (errCode != E_OK) { + LOGE("update log record failed when delete cloud data, errCode = %d", errCode); + } + return errCode; +} + +int SQLiteSingleVerRelationalStorageExecutor::UpdateCloudGid(const std::string &tableName, const VBucket &vBucket, + const TableSchema &tableSchema) +{ + return UpdateLogRecord(vBucket, tableSchema, OpType::ONLY_UPDATE_GID); +} } // namespace DistributedDB #endif diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h index ecbda6642f94fd71111181e9e566953a3ddf9c42..637004d6c149604574c667270fb0356cd08bf0ea 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h @@ -16,18 +16,22 @@ #define SQLITE_SINGLE_VER_RELATIONAL_STORAGE_EXECUTOR_H #ifdef RELATIONAL_STORE +#include "cloud/cloud_db_constant.h" +#include "cloud_store_types.h" #include "data_transformer.h" #include "db_types.h" +#include "icloud_sync_storage_interface.h" #include "macro_utils.h" #include "query_object.h" #include "relational_row_data.h" #include "relational_store_delegate.h" #include "relational_sync_data_inserter.h" +#include "sqlite_single_ver_relational_continue_token.h" #include "sqlite_storage_executor.h" #include "sqlite_utils.h" namespace DistributedDB { -class SQLiteSingleVerRelationalStorageExecutor : public SQLiteStorageExecutor { +class SQLiteSingleVerRelationalStorageExecutor : public SQLiteStorageExecutor, public ICloudDataTranslate { public: SQLiteSingleVerRelationalStorageExecutor(sqlite3 *dbHandle, bool writable, DistributedTableMode mode); ~SQLiteSingleVerRelationalStorageExecutor() override = default; @@ -36,8 +40,8 @@ public: DISABLE_COPY_ASSIGN_MOVE(SQLiteSingleVerRelationalStorageExecutor); // The parameter "identity" is a hash string that identifies a device - int CreateDistributedTable(const std::string &tableName, DistributedTableMode mode, bool isUpgraded, - const std::string &identity, TableInfo &table); + int CreateDistributedTable(DistributedTableMode mode, bool isUpgraded, const std::string &identity, + TableInfo &table, TableSyncType syncType); int UpgradeDistributedTable(const std::string &tableName, DistributedTableMode mode, bool &schemaChanged, RelationalSchemaObject &schema); @@ -64,6 +68,8 @@ public: int DeleteDistributedDeviceTable(const std::string &device, const std::string &tableName); + int DeleteDistributedAllDeviceTableLog(const std::string &tableName); + int DeleteDistributedDeviceTableLog(const std::string &device, const std::string &tableName); int DeleteDistributedLogTable(const std::string &tableName); @@ -71,7 +77,7 @@ public: int CheckAndCleanDistributedTable(const std::vector &tableNames, std::vector &missingTables); - int CreateDistributedDeviceTable(const std::string &device, const TableInfo &baseTbl); + int CreateDistributedDeviceTable(const std::string &device, const TableInfo &baseTbl, const StoreInfo &info); int CheckQueryObjectLegal(const TableInfo &table, QueryObject &query, const std::string &schemaVersion); @@ -84,6 +90,28 @@ public: int CheckEncryptedOrCorrupted() const; + int GetExistsDeviceList(std::set &devices) const; + + int GetUploadCount(const std::string &tableName, const Timestamp ×tamp, int64_t &count); + + int UpdateCloudLogGid(const CloudSyncData &cloudDataResult); + + int GetSyncCloudData(CloudSyncData &cloudDataResult, const uint32_t &maxSize, + SQLiteSingleVerRelationalContinueToken &token); + + std::vector AssetToBlob(const Asset &asset) override; + + std::vector AssetsToBlob(const Assets &assets) override; + + Asset BlobToAsset(const std::vector &blob) override; + + Assets BlobToAssets(std::vector &blob) override; + + int GetLogInfoByPrimaryKeyOrGid(const TableSchema &tableSchema, const VBucket &vBucket, LogInfo &logInfo); + + int PutCloudSyncData(const std::string &tableName, const DownloadData &downloadData, + const TableSchema &tableSchema); + private: int GetDataItemForSync(sqlite3_stmt *statement, DataItem &dataItem, bool isGettingDeletedData) const; @@ -119,8 +147,72 @@ private: int GeneLogInfoForExistedData(sqlite3 *db, const std::string &tableName, const TableInfo &table, const std::string &calPrimaryKeyHash); + int GetCloudDataForSync(sqlite3_stmt *statement, CloudSyncData &cloudDataResult, uint32_t &totalSize, + const uint32_t &maxSize); + + void GetVBucketByType(VBucket &vBucket, int cid, Type &cloudValue); + + static std::set GetCloudPrimaryKey(const TableSchema &tableSchema); + static std::vector GetCloudPrimaryKeyField(const TableSchema &tableSchema); + static std::map GetCloudPrimaryKeyFieldMap(const TableSchema &tableSchema); + static Field GetFieldByName(const TableSchema &tableSchema, const std::string &name); + + std::string GetInsertSqlForCloudSync(const TableSchema &tableSchema); + + int GetPrimaryKeyHashValue(const VBucket &vBucket, const TableSchema &tableSchema, std::vector &hashValue); + + int GetQueryLogStatement(const TableSchema &tableSchema, const VBucket &vBucket, const std::string &querySql, + std::set &pkSet, sqlite3_stmt *&selectStmt); + + int GetQueryLogSql(const std::string &tableName, const VBucket &vBucket, std::set &pkSet, + std::string &querySql); + + int CalcHashKeyForOneField(const Field &field, const VBucket &vBucket, std::vector &hashValue); + + void GetLogInfoByStatement(sqlite3_stmt *statement, LogInfo &logInfo); + + int InsertCloudData(const std::string &tableName, const VBucket &vBucket, const TableSchema &tableSchema); + + int BindValueToUpsertStatement(const VBucket &vBucket, const std::vector &fields, sqlite3_stmt *upsertStmt); + + int BindValueToInsertLogStatement(const VBucket &vBucket, const TableSchema &tableSchema, + sqlite3_stmt *insertLogStmt); + + std::string GetUpdateSqlForCloudSync(const TableSchema &tableSchema, const std::set &pkSet); + + int UpdateCloudData(const std::string &tableName, const VBucket &vBucket, const TableSchema &tableSchema); + + int BindValueToUpdateStatement(const VBucket &vBucket, const TableSchema &tableSchema, + sqlite3_stmt *updateStmt); + + int UpdateLogRecord(const VBucket &vBucket, const TableSchema &tableSchema, OpType opType); + + int BindValueToUpdateLogStatement(const VBucket &vBucket, const TableSchema &tableSchema, + const std::vector &fields, std::map &pkMap, sqlite3_stmt *updateLogStmt); + + int GetDeleteStatementForCloudSync(const TableSchema &tableSchema, const std::set &pkSet, + const VBucket &vBucket, sqlite3_stmt *&deleteStmt); + + int DeleteCloudData(const std::string &tableName, const VBucket &vBucket, const TableSchema &tableSchema); + + int UpdateCloudGid(const std::string &tableName, const VBucket &vBucket, const TableSchema &tableSchema); + + template + int GetValueFronVBucket(const std::string &fieldName, const VBucket &vBucket, T &outVal) + { + Type cloudValue = vBucket.at(fieldName); + T *value = std::get_if(&cloudValue); + if (value == nullptr) { + LOGE("Get cloud cloud fail."); + return -E_INVALID_ARGS; + } + outVal = *value; + return E_OK; + } + std::string baseTblName_; TableInfo table_; // Always operating table, user table when get, device table when put. + TableSchema tableSchema_; // for cloud table DistributedTableMode mode_; }; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp index eb31592a7a3e9fcff07604347cfe69b570d6b38a..3282948cf7a7a6d0904bd08102b82a6edc423b1d 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp @@ -392,7 +392,7 @@ int SQLiteSingleVerStorageEngine::ReleaseExecutor(SQLiteSingleVerStorageExecutor Recycle(databaseHandle); handle = nullptr; if (isCorrupted_) { - LOGE("Database is corrupted!"); + LOGE("Database is corrupted or invalid passwd!"); return -E_INVALID_PASSWD_OR_CORRUPTED_DB; // Externally imperceptible, used to terminate migration } return E_OK; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp index d7b1304654a3011cba5294b63607bd3fb42e0af7..91a6cc98a33856589bc78a25cec639101a8eb550 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp @@ -24,11 +24,11 @@ #include "parcel.h" #include "platform_specific.h" #include "runtime_context.h" +#include "sqlite_meta_executor.h" #include "sqlite_single_ver_storage_executor_sql.h" namespace DistributedDB { namespace { -const int HASH_KEY_SIZE = 32; // size of SHA256_DIGEST_LENGTH void InitCommitNotifyDataKeyStatus(SingleVerNaturalStoreCommitNotifyData *committedData, const Key &hashKey, const DataOperStatus &dataStatus) @@ -1405,50 +1405,17 @@ int SQLiteSingleVerStorageExecutor::GetAllMetaKeys(std::vector &keys) const return errCode; } - errCode = GetAllKeys(statement, keys); + errCode = SqliteMetaExecutor::GetAllKeys(statement, isMemDb_, keys); SQLiteUtils::ResetStatement(statement, true, errCode); return errCode; } -int SQLiteSingleVerStorageExecutor::GetMetaKeysByKeyPrefix(const std::string &keyPre, - std::set &outKeys) const -{ - sqlite3_stmt *statement = nullptr; - const std::string &sqlStr = (attachMetaMode_ ? SELECT_ATTACH_META_KEYS_BY_PREFIX : SELECT_META_KEYS_BY_PREFIX); - int errCode = SQLiteUtils::GetStatement(dbHandle_, sqlStr, statement); - if (errCode != E_OK) { - LOGE("[SingleVerExe][GetAllKey] Get statement failed:%d", errCode); - return errCode; - } - - Key keyPrefix; - DBCommon::StringToVector(keyPre + '%', keyPrefix); - errCode = SQLiteUtils::BindBlobToStatement(statement, 1, keyPrefix); // 1: bind index for prefix key - if (errCode != E_OK) { - LOGE("[SingleVerExe][GetAllKey] Bind statement failed:%d", errCode); - SQLiteUtils::ResetStatement(statement, true, errCode); - return errCode; - } - - std::vector keys; - errCode = GetAllKeys(statement, keys); - SQLiteUtils::ResetStatement(statement, true, errCode); - for (const auto &it : keys) { - if (it.size() >= keyPre.size() + HASH_KEY_SIZE) { - outKeys.insert({it.begin() + keyPre.size(), it.begin() + keyPre.size() + HASH_KEY_SIZE}); - } else { - LOGW("[SingleVerExe][GetAllKey] Get invalid key, size=%zu", it.size()); - } - } - return errCode; -} - -int SQLiteSingleVerStorageExecutor::GetAllSyncedEntries(const std::string &deviceName, +int SQLiteSingleVerStorageExecutor::GetAllSyncedEntries(const std::string &hashDev, std::vector &entries) const { int errCode = E_OK; sqlite3_stmt *statement = nullptr; - if (deviceName.empty()) { + if (hashDev.empty()) { std::string sql = (executorState_ == ExecutorState::CACHE_ATTACH_MAIN ? SELECT_ALL_SYNC_ENTRIES_FROM_CACHEHANDLE : SELECT_ALL_SYNC_ENTRIES); errCode = SQLiteUtils::GetStatement(dbHandle_, sql, statement); @@ -1465,10 +1432,8 @@ int SQLiteSingleVerStorageExecutor::GetAllSyncedEntries(const std::string &devic return errCode; } - // When removing device data in cache mode, key is "remove", value is deviceID's hash string. - // Therefore, no need to transfer hash string when migrating. - std::string devName = isSyncMigrating_ ? deviceName : DBCommon::TransferHashString(deviceName); - std::vector devVect(devName.begin(), devName.end()); + // deviceName always hash string + std::vector devVect(hashDev.begin(), hashDev.end()); errCode = SQLiteUtils::BindBlobToStatement(statement, 1, devVect, true); // bind the 1st to device. if (errCode != E_OK) { LOGE("Failed to bind the synced device for all entries:%d", errCode); @@ -1514,34 +1479,6 @@ int SQLiteSingleVerStorageExecutor::GetAllEntries(sqlite3_stmt *statement, std:: return errCode; } -int SQLiteSingleVerStorageExecutor::GetAllKeys(sqlite3_stmt *statement, std::vector &keys) const -{ - if (statement == nullptr) { - return -E_INVALID_DB; - } - int errCode; - do { - errCode = SQLiteUtils::StepWithRetry(statement, isMemDb_); - if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { - Key key; - errCode = SQLiteUtils::GetColumnBlobValue(statement, 0, key); - if (errCode != E_OK) { - break; - } - - keys.push_back(std::move(key)); - } else if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) { - errCode = E_OK; - break; - } else { - LOGE("SQLite step for getting all keys failed:%d", errCode); - break; - } - } while (true); - - return errCode; -} - int SQLiteSingleVerStorageExecutor::BindSavedSyncData(sqlite3_stmt *statement, const DataItem &dataItem, const Key &hashKey, const SyncDataDevices &devices, bool isUpdate) { @@ -1796,9 +1733,8 @@ int SQLiteSingleVerStorageExecutor::RemoveDeviceData(const std::string &deviceNa goto ERROR; } } else { - // Transfer the device name. - std::string devName = DBCommon::TransferHashString(deviceName); - std::vector devVect(devName.begin(), devName.end()); + // device name always hash string. + std::vector devVect(deviceName.begin(), deviceName.end()); errCode = SQLiteUtils::GetStatement(dbHandle_, REMOVE_DEV_DATA_SQL, statement); if (errCode != E_OK) { goto ERROR; @@ -2236,20 +2172,90 @@ uint64_t SQLiteSingleVerStorageExecutor::GetLogFileSize() const int SQLiteSingleVerStorageExecutor::GetExistsDevicesFromMeta(std::set &devices) { - int errCode = GetMetaKeysByKeyPrefix(DBConstant::DEVICEID_PREFIX_KEY, devices); + return SqliteMetaExecutor::GetExistsDevicesFromMeta(dbHandle_, + attachMetaMode_ ? SqliteMetaExecutor::MetaMode::KV_ATTACH : SqliteMetaExecutor::MetaMode::KV, + isMemDb_, devices); +} + +int SQLiteSingleVerStorageExecutor::UpdateKey(const UpdateKeyCallback &callback) +{ + if (dbHandle_ == nullptr) { + return -E_INVALID_DB; + } + UpdateContext context; + context.callback = callback; + int errCode = CreateFuncUpdateKey(context, &Translate, &CalHashKey); if (errCode != E_OK) { - LOGE("Get meta data key failed. err=%d", errCode); return errCode; } - errCode = GetMetaKeysByKeyPrefix(DBConstant::QUERY_SYNC_PREFIX_KEY, devices); + int executeErrCode = SQLiteUtils::ExecuteRawSQL(dbHandle_, UPDATE_SYNC_DATA_KEY_SQL); + context.callback = nullptr; + errCode = CreateFuncUpdateKey(context, nullptr, nullptr); + if (context.errCode != E_OK) { + return context.errCode; + } + if (executeErrCode != E_OK) { + return executeErrCode; + } if (errCode != E_OK) { - LOGE("Get meta data key failed. err=%d", errCode); return errCode; } - errCode = GetMetaKeysByKeyPrefix(DBConstant::DELETE_SYNC_PREFIX_KEY, devices); - if (errCode != E_OK) { - LOGE("Get meta data key failed. err=%d", errCode); + return E_OK; +} + +int SQLiteSingleVerStorageExecutor::CreateFuncUpdateKey(UpdateContext &context, + void(*translateFunc)(sqlite3_context *ctx, int argc, sqlite3_value **argv), + void(*calHashFunc)(sqlite3_context *ctx, int argc, sqlite3_value **argv)) const +{ + int errCode = sqlite3_create_function_v2(dbHandle_, FUNC_NAME_TRANSLATE_KEY, 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, + &context, translateFunc, nullptr, nullptr, nullptr); + if (errCode != SQLITE_OK) { + LOGE("[SqlSinExe][UpdateKey] Create func=translate_key failed=%d", errCode); + return SQLiteUtils::MapSQLiteErrno(errCode); } - return errCode; + errCode = sqlite3_create_function_v2(dbHandle_, FUNC_NAME_CAL_HASH_KEY, 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, + &context, calHashFunc, nullptr, nullptr, nullptr); + if (errCode != SQLITE_OK) { + LOGE("[SqlSinExe][UpdateKey] Create func=translate_key failed=%d", errCode); + return SQLiteUtils::MapSQLiteErrno(errCode); + } + return E_OK; +} + +void SQLiteSingleVerStorageExecutor::Translate(sqlite3_context *ctx, int argc, sqlite3_value **argv) +{ + if (ctx == nullptr || argc != 1 || argv == nullptr) { // i parameters, which are key + LOGW("[SqlSinExe][Translate] invalid param=%d", argc); + return; + } + auto context = static_cast(sqlite3_user_data(ctx)); + auto keyBlob = static_cast(sqlite3_value_blob(argv[0])); + int keyBlobLen = sqlite3_value_bytes(argv[0]); + Key oldKey; + if (keyBlob != nullptr && keyBlobLen > 0) { + oldKey = Key(keyBlob, keyBlob + keyBlobLen); + } + Key newKey; + context->callback(oldKey, newKey); + if (newKey.size() >= DBConstant::MAX_KEY_SIZE || newKey.empty()) { + LOGE("[SqlSinExe][Translate] invalid key len=%zu", newKey.size()); + context->errCode = -E_INVALID_ARGS; + sqlite3_result_error(ctx, "Update key is invalid", -1); + return; + } + context->newKey = newKey; + sqlite3_result_blob(ctx, newKey.data(), static_cast(newKey.size()), SQLITE_TRANSIENT); +} + +void SQLiteSingleVerStorageExecutor::CalHashKey(sqlite3_context *ctx, int argc, sqlite3_value **argv) +{ + if (ctx == nullptr || argc != 1 || argv == nullptr) { + LOGW("[SqlSinExe][Translate] invalid param=%d", argc); + return; + } + auto context = static_cast(sqlite3_user_data(ctx)); + Key hashKey; + DBCommon::CalcValueHash(context->newKey, hashKey); + sqlite3_result_blob(ctx, hashKey.data(), static_cast(hashKey.size()), SQLITE_TRANSIENT); } } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.h index 255792ccb48051f3c7775b39f74de686c2216298..57a3a1623ffb9c62edfa555cdb19848e66aba8f9 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.h @@ -121,9 +121,8 @@ public: // Get all the meta keys. int GetAllMetaKeys(std::vector &keys) const; - int GetMetaKeysByKeyPrefix(const std::string &keyPre, std::set &outKeys) const; - int GetAllSyncedEntries(const std::string &deviceName, std::vector &entries) const; + int GetAllSyncedEntries(const std::string &hashDev, std::vector &entries) const; int SaveSyncDataItem(DataItem &dataItem, const DeviceInfo &deviceInfo, Timestamp &maxStamp, SingleVerNaturalStoreCommitNotifyData *committedData, bool isPermitForceWrite = true); @@ -136,7 +135,7 @@ public: int RemoveDeviceData(const std::string &deviceName); - int RemoveDeviceDataInCacheMode(const std::string &deviceName, bool isNeedNotify, uint64_t recordVersion) const; + int RemoveDeviceDataInCacheMode(const std::string &hashDev, bool isNeedNotify, uint64_t recordVersion) const; void InitCurrentMaxStamp(Timestamp &maxStamp); @@ -251,6 +250,8 @@ public: int GetExistsDevicesFromMeta(std::set &devices); + int UpdateKey(const UpdateKeyCallback &callback); + private: struct SaveRecordStatements { sqlite3_stmt *queryStatement = nullptr; @@ -265,6 +266,12 @@ private: } }; + struct UpdateContext { + int errCode = E_OK; + Key newKey; + UpdateKeyCallback callback; + }; + void PutIntoCommittedData(const DataItem &itemPut, const DataItem &itemGet, const DataOperStatus &status, SingleVerNaturalStoreCommitNotifyData *committedData); @@ -301,8 +308,6 @@ private: int InitResultSet(QueryObject &queryObj, sqlite3_stmt *&countStmt); - int GetAllKeys(sqlite3_stmt *statement, std::vector &keys) const; - int GetAllEntries(sqlite3_stmt *statement, std::vector &entries) const; int BindPutKvData(sqlite3_stmt *statement, const Key &key, const Value &value, Timestamp timestamp, @@ -396,6 +401,14 @@ private: int CheckMissQueryDataItem(sqlite3_stmt *stmt, const std::string &deviceName, DataItem &item); + int CreateFuncUpdateKey(UpdateContext &context, + void(*translateFunc)(sqlite3_context *ctx, int argc, sqlite3_value **argv), + void(*calHashFunc)(sqlite3_context *ctx, int argc, sqlite3_value **argv)) const; + + static void Translate(sqlite3_context *ctx, int argc, sqlite3_value **argv); + + static void CalHashKey(sqlite3_context *ctx, int argc, sqlite3_value **argv); + sqlite3_stmt *getSyncStatement_; sqlite3_stmt *getResultRowIdStatement_; sqlite3_stmt *getResultEntryStatement_; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp index af15b3710944e41e87f230360e78f20e03ebe371..82ec7a98750b49bd6f931892342f334bc05452d3 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp @@ -77,12 +77,11 @@ int SQLiteSingleVerStorageExecutor::ResetForMigrateCacheData() return CheckCorruptedStatus(errCode); } -int SQLiteSingleVerStorageExecutor::RemoveDeviceDataInCacheMode(const std::string &deviceName, +int SQLiteSingleVerStorageExecutor::RemoveDeviceDataInCacheMode(const std::string &hashDev, bool isNeedNotify, uint64_t recordVersion) const { - // Transfer the device name. - std::string devName = DBCommon::TransferHashString(deviceName); - std::vector devVect(devName.begin(), devName.end()); + // device name always hash string. + std::vector devVect(hashDev.begin(), hashDev.end()); Key hashKey; int errCode = DBCommon::CalcValueHash(REMOVE_DEVICE_DATA_KEY, hashKey); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_sql.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_sql.h index 5fceeaebb415b255acb25d90ebc0c97dd261b5da..17ad51839d86f031a4685599c0d77de19e4a5289 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_sql.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_sql.h @@ -230,6 +230,13 @@ namespace DistributedDB { const std::string GET_SYNC_DATA_TIRGGER_SQL = "SELECT name FROM SQLITE_MASTER WHERE TYPE = 'trigger' AND TBL_NAME = 'sync_data' AND name like ?;"; + constexpr const char *UPDATE_SYNC_DATA_KEY_SQL = + "UPDATE sync_data SET key=translate_key(key), hash_key=cal_hash_key(key) WHERE flag&0x01=0"; + + constexpr const char *FUNC_NAME_TRANSLATE_KEY = "translate_key"; + + constexpr const char *FUNC_NAME_CAL_HASH_KEY = "cal_hash_key"; + const int BIND_KV_KEY_INDEX = 1; const int BIND_KV_VAL_INDEX = 2; const int BIND_LOCAL_TIMESTAMP_INDEX = 3; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp index 7d222b79ce142d12bfad08ad675f181bbe1201de..ec0dac0eafc1eda098d82c45fbf2b3a40095c949 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp @@ -1091,20 +1091,31 @@ int SQLiteUtils::SetUserVer(sqlite3 *db, int version) int SQLiteUtils::MapSQLiteErrno(int errCode) { - if (errCode == SQLITE_OK) { - return E_OK; - } else if (errCode == SQLITE_IOERR) { - if (errno == EKEYREVOKED) { - return -E_EKEYREVOKED; - } - } else if (errCode == SQLITE_CORRUPT || errCode == SQLITE_NOTADB) { - return -E_INVALID_PASSWD_OR_CORRUPTED_DB; - } else if (errCode == SQLITE_LOCKED || errCode == SQLITE_BUSY) { - return -E_BUSY; - } else if (errCode == SQLITE_ERROR && errno == EKEYREVOKED) { - return -E_EKEYREVOKED; - } else if (errCode == SQLITE_AUTH) { - return -E_DENIED_SQL; + switch (errCode) { + case SQLITE_OK: + return E_OK; + case SQLITE_IOERR: + if (errno == EKEYREVOKED) { + return -E_EKEYREVOKED; + } + break; + case SQLITE_CORRUPT: + case SQLITE_NOTADB: + return -E_INVALID_PASSWD_OR_CORRUPTED_DB; + case SQLITE_LOCKED: + case SQLITE_BUSY: + return -E_BUSY; + case SQLITE_ERROR: + if (errno == EKEYREVOKED) { + return -E_EKEYREVOKED; + } + break; + case SQLITE_AUTH: + return -E_DENIED_SQL; + case SQLITE_CONSTRAINT: + return -E_CONSTRAINT; + default: + break; } return -errCode; } diff --git a/frameworks/libs/distributeddb/storage/src/storage_proxy.cpp b/frameworks/libs/distributeddb/storage/src/storage_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0dba8147c8f2d5c00e8ea16fbd926484f278e01c --- /dev/null +++ b/frameworks/libs/distributeddb/storage/src/storage_proxy.cpp @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2023 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 "storage_proxy.h" + +#include "cloud/schema_mgr.h" +#include "store_types.h" + +namespace DistributedDB { +StorageProxy::StorageProxy(ICloudSyncStorageInterface *iCloud) + :store_(iCloud), + transactionExeFlag_(false), + isWrite_(false) +{ +} + +std::shared_ptr StorageProxy::GetCloudDb(ICloudSyncStorageInterface *iCloud) +{ + std::shared_ptr proxy = std::shared_ptr(new StorageProxy(iCloud)); + proxy->Init(); + return proxy; +} + +void StorageProxy::Init() +{ + cloudMetaData_ = std::make_shared(store_); +} + +int StorageProxy::Close() +{ + std::unique_lock writeLock(storeMutex_); + if (transactionExeFlag_.load()) { + LOGE("the transaction has been started, storage proxy can not closed"); + return -E_BUSY; + } + store_ = nullptr; + return E_OK; +} + +int StorageProxy::GetLocalWaterMark(const std::string &tableName, LocalWaterMark &localMark) +{ + std::shared_lock readLock(storeMutex_); + if (cloudMetaData_ == nullptr) { + return -E_INVALID_DB; + } + if (transactionExeFlag_.load() && isWrite_.load()) { + LOGE("the write transaction has been started, can not get meta"); + return -E_BUSY; + } + return cloudMetaData_->GetLocalWaterMark(tableName, localMark); +} + +int StorageProxy::PutLocalWaterMark(const std::string &tableName, LocalWaterMark &localMark) +{ + std::shared_lock readLock(storeMutex_); + if (cloudMetaData_ == nullptr) { + return -E_INVALID_DB; + } + if (transactionExeFlag_.load() && isWrite_.load()) { + LOGE("the write transaction has been started, can not put meta"); + return -E_BUSY; + } + return cloudMetaData_->SetLocalWaterMark(tableName, localMark); +} + +int StorageProxy::GetCloudWaterMark(const std::string &tableName, CloudWaterMark &cloudMark) +{ + std::shared_lock readLock(storeMutex_); + if (cloudMetaData_ == nullptr) { + return -E_INVALID_DB; + } + return cloudMetaData_->GetCloudWaterMark(tableName, cloudMark); +} + +int StorageProxy::PutCloudWaterMark(const std::string &tableName, CloudWaterMark &cloudMark) +{ + std::shared_lock readLock(storeMutex_); + if (cloudMetaData_ == nullptr) { + return -E_INVALID_DB; + } + return cloudMetaData_->SetCloudWaterMark(tableName, cloudMark); +} + +int StorageProxy::StartTransaction(TransactType type) +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + int errCode = store_->StartTransaction(type); + if (errCode == E_OK) { + transactionExeFlag_.store(true); + isWrite_.store(type == TransactType::IMMEDIATE); + } + return errCode; +} + +int StorageProxy::Commit() +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + int errCode = store_->Commit(); + if (errCode == E_OK) { + transactionExeFlag_.store(false); + } + return errCode; +} + +int StorageProxy::Rollback() +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + int errCode = store_->Rollback(); + if (errCode == E_OK) { + transactionExeFlag_.store(false); + } + return errCode; +} + +int StorageProxy::GetUploadCount(const std::string &tableName, const LocalWaterMark &localMark, int64_t &count) +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + if (!transactionExeFlag_.load()) { + LOGE("the transaction has not been started"); + return -E_TRANSACT_STATE; + } + return store_->GetUploadCount(tableName, localMark, count); +} + +int StorageProxy::FillCloudGid(const CloudSyncData &data) +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + if (!transactionExeFlag_.load()) { + LOGE("the transaction has not been started"); + return -E_TRANSACT_STATE; + } + return store_->FillCloudGid(data); +} + +int StorageProxy::GetCloudData(const std::string &tableName, const Timestamp &timeRange, + ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + if (!transactionExeFlag_.load()) { + LOGE("the transaction has not been started"); + return -E_TRANSACT_STATE; + } + TableSchema tableSchema; + int errCode = store_->GetCloudTableSchema(tableName, tableSchema); + if (errCode != E_OK) { + return errCode; + } + return store_->GetCloudData(tableSchema, timeRange, continueStmtToken, cloudDataResult); +} + +int StorageProxy::GetCloudDataNext(ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) const +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + if (!transactionExeFlag_.load()) { + LOGE("the transaction has not been started"); + return -E_TRANSACT_STATE; + } + return store_->GetCloudDataNext(continueStmtToken, cloudDataResult); +} + +int StorageProxy::GetLogInfoByPrimaryKeyOrGid(const std::string &tableName, const VBucket &vBucket, LogInfo &logInfo) +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + if (!transactionExeFlag_.load()) { + LOGE("the transaction has not been started"); + return -E_TRANSACT_STATE; + } + + return store_->GetLogInfoByPrimaryKeyOrGid(tableName, vBucket, logInfo); +} + +int StorageProxy::PutCloudSyncData(const std::string &tableName, const DownloadData &downloadData) +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + if (!transactionExeFlag_.load()) { + LOGE("the transaction has not been started"); + return -E_TRANSACT_STATE; + } + + return store_->PutCloudSyncData(tableName, downloadData); +} + +int StorageProxy::ReleaseContinueToken(ContinueToken &continueStmtToken) +{ + return store_->ReleaseCloudDataToken(continueStmtToken); +} + +int StorageProxy::CheckSchema(const TableName &tableName) const +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + return store_->ChkSchema(tableName); +} + +int StorageProxy::CheckSchema(std::vector &tables) +{ + std::shared_lock readLock(storeMutex_); + if (store_ == nullptr) { + return -E_INVALID_DB; + } + for (auto table : tables) { + return store_->ChkSchema(table); + } + return E_OK; +} + +} diff --git a/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp b/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp index 811eca0ab4545f05055687c2ded645fb7eb19777..b00f26ba2a925365bf58ce392991ed174ef8f08d 100644 --- a/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp @@ -94,7 +94,10 @@ uint64_t SyncAbleEngine::GetTimestamp() int SyncAbleEngine::EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash, const std::string &tableName) { if (NeedStartSyncer()) { - StartSyncer(); + int errCode = StartSyncer(); + if (errCode != E_OK && errCode != -E_NO_NEED_ACTIVE) { + return errCode; + } } return syncer_.EraseDeviceWaterMark(deviceId, isNeedHash, tableName); } @@ -286,4 +289,12 @@ bool SyncAbleEngine::NeedStartSyncer() const // equivalent to !(!isSyncNeedActive_ && isSyncModuleActiveCheck_) return !started_ && (isSyncNeedActive_ || !isSyncModuleActiveCheck_); } + +int SyncAbleEngine::GetHashDeviceId(const std::string &clientId, std::string &hashDevId) +{ + if (NeedStartSyncer()) { + StartSyncer(); + } + return syncer_.GetHashDeviceId(clientId, hashDevId); +} } diff --git a/frameworks/libs/distributeddb/storage/src/sync_able_engine.h b/frameworks/libs/distributeddb/storage/src/sync_able_engine.h index 0747d1fd41dfe709a118626eb005b7cd65815785..3b45461fc082d74719e7c671f6cdc7da77f92629 100644 --- a/frameworks/libs/distributeddb/storage/src/sync_able_engine.h +++ b/frameworks/libs/distributeddb/storage/src/sync_able_engine.h @@ -54,6 +54,8 @@ public: int RemoteQuery(const std::string &device, const RemoteCondition &condition, uint64_t timeout, uint64_t connectionId, std::shared_ptr &result); + + int GetHashDeviceId(const std::string &clientId, std::string &hashDevId); private: // Start syncer int StartSyncer(bool isCheckSyncActive = false, bool isNeedActive = true); diff --git a/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp b/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp index 1e9507d57dbba1976203398e27b447e2e3ef88b1..f7b21544e56ddf5cc4aa9a26a53e747b94d3efc6 100644 --- a/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp +++ b/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp @@ -285,7 +285,10 @@ uint32_t SyncAbleKvDB::GetAppendedLen() const int SyncAbleKvDB::EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash) { if (NeedStartSyncer()) { - StartSyncer(); + int errCode = StartSyncer(); + if (errCode != E_OK && errCode != -E_NO_NEED_ACTIVE) { + return errCode; + } } return syncer_.EraseDeviceWaterMark(deviceId, isNeedHash); } @@ -420,4 +423,12 @@ bool SyncAbleKvDB::NeedStartSyncer() const // equivalent to !(!isSyncNeedActive_ && isSyncModuleActiveCheck_) return !started_ && (isSyncNeedActive_ || !isSyncModuleActiveCheck_); } + +int SyncAbleKvDB::GetHashDeviceId(const std::string &clientId, std::string &hashDevId) +{ + if (NeedStartSyncer()) { + StartSyncer(); + } + return syncer_.GetHashDeviceId(clientId, hashDevId); +} } diff --git a/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.h b/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.h index ceb1c08885acab7ecd62c1f2581df6994e18162b..c5e08092dceafd1ad5ea55a08c17f02127075010 100644 --- a/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.h +++ b/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.h @@ -87,6 +87,8 @@ public: int GetSyncDataSize(const std::string &device, size_t &size) const; + int GetHashDeviceId(const std::string &clientId, std::string &hashDevId); + protected: virtual IKvDBSyncInterface *GetSyncInterface() = 0; diff --git a/frameworks/libs/distributeddb/syncer/include/isyncer.h b/frameworks/libs/distributeddb/syncer/include/isyncer.h index 42a3320d9c6badfa0b916eb5440a20c179759143..2ac1bb9a14fb212aef881b59fc9faba33d583cd7 100644 --- a/frameworks/libs/distributeddb/syncer/include/isyncer.h +++ b/frameworks/libs/distributeddb/syncer/include/isyncer.h @@ -123,6 +123,8 @@ public: uint64_t timeout, uint64_t connectionId, std::shared_ptr &result) = 0; virtual int GetSyncDataSize(const std::string &device, size_t &size) const = 0; + + virtual int GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const = 0; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/syncer/include/syncer_proxy.h b/frameworks/libs/distributeddb/syncer/include/syncer_proxy.h index 1d6294af478547c6360d7ea5146d08a438587f15..7beecb1b9dcb3dca932c90d77eaf78d1ef1ec272 100644 --- a/frameworks/libs/distributeddb/syncer/include/syncer_proxy.h +++ b/frameworks/libs/distributeddb/syncer/include/syncer_proxy.h @@ -107,6 +107,7 @@ public: int GetSyncDataSize(const std::string &device, size_t &size) const override; + int GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const override; private: std::mutex syncerLock_; std::shared_ptr syncer_; diff --git a/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp b/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp index 5fce45efebc4f0f0ed491550a12ff040bf94382f..9daa5e365a2330c2f864f0310ea954a387b9aa78 100644 --- a/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp +++ b/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp @@ -466,7 +466,8 @@ int AbilitySync::AckNotifyRecv(const Message *message, ISyncTaskContext *context uint32_t remoteSoftwareVersion = packet->GetSoftwareVersion(); context->SetRemoteSoftwareVersion(remoteSoftwareVersion); AbilitySyncAckPacket sendPacket; - errCode = HandleVersionV3AckSchemaParam(packet, sendPacket, context, false); + std::pair schemaSyncStatus; + errCode = HandleVersionV3AckSchemaParam(packet, sendPacket, context, false, schemaSyncStatus); int ackCode = errCode; LOGI("[AckNotifyRecv] receive dev = %s ack notify, remoteSoftwareVersion = %u, ackCode = %d", STR_MASK(deviceId_), remoteSoftwareVersion, errCode); @@ -537,12 +538,13 @@ void AbilitySync::HandleVersionV3AckSecOptionParam(const AbilitySyncAckPacket *p } int AbilitySync::HandleVersionV3AckSchemaParam(const AbilitySyncAckPacket *recvPacket, - AbilitySyncAckPacket &sendPacket, ISyncTaskContext *context, bool sendOpinion) const + AbilitySyncAckPacket &sendPacket, ISyncTaskContext *context, bool sendOpinion, + std::pair &schemaSyncStatus) const { if (IsSingleRelationalVer()) { - return HandleRelationAckSchemaParam(recvPacket, sendPacket, context, sendOpinion); + return HandleRelationAckSchemaParam(recvPacket, sendPacket, context, sendOpinion, schemaSyncStatus); } - HandleKvAckSchemaParam(recvPacket, context, sendPacket); + HandleKvAckSchemaParam(recvPacket, context, sendPacket, schemaSyncStatus); return E_OK; } @@ -1134,7 +1136,7 @@ RelationalSyncOpinion AbilitySync::MakeRelationSyncOpinion(const AbilitySyncRequ } void AbilitySync::HandleKvAckSchemaParam(const AbilitySyncAckPacket *recvPacket, - ISyncTaskContext *context, AbilitySyncAckPacket &sendPacket) const + ISyncTaskContext *context, AbilitySyncAckPacket &sendPacket, std::pair &schemaSyncStatus) const { std::string remoteSchema = recvPacket->GetSchema(); uint8_t remoteSchemaType = recvPacket->GetSchemaType(); @@ -1146,10 +1148,14 @@ void AbilitySync::HandleKvAckSchemaParam(const AbilitySyncAckPacket *recvPacket, SyncStrategy localStrategy = SchemaNegotiate::ConcludeSyncStrategy(syncOpinion, remoteOpinion); SetAbilityAckSyncOpinionInfo(sendPacket, syncOpinion); (static_cast(context))->SetSyncStrategy(localStrategy, true); + schemaSyncStatus = { + localStrategy.permitSync, + true + }; } int AbilitySync::HandleRelationAckSchemaParam(const AbilitySyncAckPacket *recvPacket, AbilitySyncAckPacket &sendPacket, - ISyncTaskContext *context, bool sendOpinion) const + ISyncTaskContext *context, bool sendOpinion, std::pair &schemaSyncStatus) const { std::string remoteSchema = recvPacket->GetSchema(); uint8_t remoteSchemaType = recvPacket->GetSchemaType(); @@ -1178,6 +1184,12 @@ int AbilitySync::HandleRelationAckSchemaParam(const AbilitySyncAckPacket *recvPa if (sendOpinion) { sendPacket.SetRelationalSyncOpinion(localOpinion); } + auto singleVerContext = static_cast(context); + auto strategy = localStrategy.find(singleVerContext->GetQuery().GetRelationTableName()); + schemaSyncStatus = { + !(strategy == localStrategy.end()) && strategy->second.permitSync, + true + }; return errCode; } @@ -1186,14 +1198,14 @@ int AbilitySync::AckRecvWithHighVersion(const Message *message, ISyncTaskContext { HandleVersionV3AckSecOptionParam(packet, context); AbilitySyncAckPacket ackPacket; - int errCode = HandleVersionV3AckSchemaParam(packet, ackPacket, context, true); + std::pair schemaSyncStatus; + int errCode = HandleVersionV3AckSchemaParam(packet, ackPacket, context, true, schemaSyncStatus); if (errCode != E_OK) { context->SetTaskErrCode(errCode); return errCode; } auto singleVerContext = static_cast(context); auto query = singleVerContext->GetQuery(); - std::pair schemaSyncStatus = (singleVerContext->GetSchemaSyncStatus(query)); if (!schemaSyncStatus.first) { singleVerContext->SetTaskErrCode(-E_SCHEMA_MISMATCH); LOGE("[AbilitySync][AckRecv] scheme check failed"); diff --git a/frameworks/libs/distributeddb/syncer/src/ability_sync.h b/frameworks/libs/distributeddb/syncer/src/ability_sync.h index 27b9406d54c812a8e785350fb4b5afb0aef523b3..08c03e5a4877eff95c0253d8981090d521a0ca58 100644 --- a/frameworks/libs/distributeddb/syncer/src/ability_sync.h +++ b/frameworks/libs/distributeddb/syncer/src/ability_sync.h @@ -195,13 +195,15 @@ private: ISyncTaskContext *context) const; int HandleVersionV3AckSchemaParam(const AbilitySyncAckPacket *recvPacket, - AbilitySyncAckPacket &sendPacket, ISyncTaskContext *context, bool sendOpinion) const; + AbilitySyncAckPacket &sendPacket, ISyncTaskContext *context, bool sendOpinion, + std::pair &schemaSyncStatus) const; void HandleKvAckSchemaParam(const AbilitySyncAckPacket *recvPacket, - ISyncTaskContext *context, AbilitySyncAckPacket &sendPacket) const; + ISyncTaskContext *context, AbilitySyncAckPacket &sendPacket, std::pair &schemaSyncStatus) const; int HandleRelationAckSchemaParam(const AbilitySyncAckPacket *recvPacket, - AbilitySyncAckPacket &sendPacket, ISyncTaskContext *context, bool sendOpinion) const; + AbilitySyncAckPacket &sendPacket, ISyncTaskContext *context, bool sendOpinion, + std::pair &schemaSyncStatus) const; void GetPacketSecOption(SecurityOption &option) const; diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.cpp b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..380b07ffa9060cb046a751e4c41b8b845d183aa5 --- /dev/null +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.cpp @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2023 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 "cloud_db_proxy.h" +#include "db_errno.h" +#include "log_print.h" +#include "runtime_context.h" + +namespace DistributedDB { +CloudDBProxy::CloudDBProxy() + : timeout_(0), + asyncTaskCount_(0) +{ +} + +int CloudDBProxy::SetCloudDB(const std::shared_ptr &cloudDB) +{ + std::unique_lock writeLock(cloudMutex_); + iCloudDb_ = cloudDB; + return E_OK; +} + +int CloudDBProxy::BatchInsert(const std::string &tableName, std::vector &record, + std::vector &extend, Info &uploadInfo) +{ + std::shared_lock readLock(cloudMutex_); + if (iCloudDb_ == nullptr) { + return -E_CLOUD_ERROR; + } + std::shared_ptr cloudDb = iCloudDb_; + std::shared_ptr context = std::make_shared(); + context->MoveInRecordAndExtend(record, extend); + context->SetTableName(tableName); + int errCode = InnerAction(context, cloudDb, INSERT); + uploadInfo = context->GetInfo(); + if (errCode != E_OK) { + return -E_CLOUD_UPLOAD_FAILED; + } + return errCode; +} + +int CloudDBProxy::BatchUpdate(const std::string &tableName, std::vector &record, + std::vector &extend, Info &uploadInfo) +{ + std::shared_lock readLock(cloudMutex_); + if (iCloudDb_ == nullptr) { + return -E_CLOUD_ERROR; + } + std::shared_ptr cloudDb = iCloudDb_; + std::shared_ptr context = std::make_shared(); + context->MoveInRecordAndExtend(record, extend); + context->SetTableName(tableName); + int errCode = InnerAction(context, cloudDb, UPDATE); + context->MoveOutRecordAndExtend(record, extend); + uploadInfo = context->GetInfo(); + if (errCode != E_OK) { + return -E_CLOUD_UPLOAD_FAILED; + } + return errCode; +} + +int CloudDBProxy::BatchDelete(const std::string &tableName, std::vector &record, + std::vector &extend, Info &uploadInfo) +{ + std::shared_lock readLock(cloudMutex_); + if (iCloudDb_ == nullptr) { + return -E_CLOUD_ERROR; + } + std::shared_ptr cloudDb = iCloudDb_; + std::shared_ptr context = std::make_shared(); + context->MoveInRecordAndExtend(record, extend); + context->SetTableName(tableName); + int errCode = InnerAction(context, cloudDb, DELETE); + uploadInfo = context->GetInfo(); + if (errCode != E_OK) { + return -E_CLOUD_UPLOAD_FAILED; + } + return errCode; +} + +int CloudDBProxy::Query(const std::string &tableName, VBucket &extend, std::vector &data) +{ + std::shared_lock readLock(cloudMutex_); + if (iCloudDb_ == nullptr) { + return -E_CLOUD_ERROR; + } + std::shared_ptr cloudDb = iCloudDb_; + std::shared_ptr context = std::make_shared(); + context->MoveInQueryExtendAndData(extend, data); + context->SetTableName(tableName); + int errCode = InnerAction(context, cloudDb, QUERY); + if (errCode != E_OK) { + return -E_CLOUD_ERROR; + } + return errCode; +} + +std::pair CloudDBProxy::Lock() +{ + std::shared_lock readLock(cloudMutex_); + if (iCloudDb_ == nullptr) { + return { -E_CLOUD_ERROR, 0u }; + } + std::shared_ptr cloudDb = iCloudDb_; + std::shared_ptr context = std::make_shared(); + std::pair lockContext; + int errCode = InnerAction(context, cloudDb, LOCK); + context->MoveOutLockContext(lockContext); + return lockContext; +} + +int CloudDBProxy::UnLock() +{ + std::shared_lock readLock(cloudMutex_); + if (iCloudDb_ == nullptr) { + return -E_CLOUD_ERROR; + } + std::shared_ptr cloudDb = iCloudDb_; + std::shared_ptr context = std::make_shared(); + + return InnerAction(context, cloudDb, UNLOCK); +} + +int CloudDBProxy::Close() +{ + std::shared_ptr iCloudDb = nullptr; + { + std::unique_lock writeLock(cloudMutex_); + if (iCloudDb_ == nullptr) { + return E_OK; + } + iCloudDb = iCloudDb_; + iCloudDb_ = nullptr; + } + { + std::unique_lock uniqueLock(asyncTaskMutex_); + LOGD("[CloudDBProxy] wait for all asyncTask begin"); + asyncTaskCv_.wait(uniqueLock, [this]() { + return asyncTaskCount_ <= 0; + }); + LOGD("[CloudDBProxy] wait for all asyncTask end"); + } + LOGD("[CloudDBProxy] call cloudDb close begin"); + DBStatus status = iCloudDb->Close(); + LOGD("[CloudDBProxy] call cloudDb close end"); + return status == OK ? E_OK : -E_CLOUD_ERROR; +} + +int CloudDBProxy::HeartBeat() +{ + std::shared_lock readLock(cloudMutex_); + if (iCloudDb_ == nullptr) { + return -E_CLOUD_ERROR; + } + + std::shared_ptr cloudDb = iCloudDb_; + std::shared_ptr context = std::make_shared(); + return InnerAction(context, cloudDb, HEARTBEAT); +} + +int CloudDBProxy::InnerAction(const std::shared_ptr &context, + const std::shared_ptr &cloudDb, InnerActionCode action) +{ + if (action >= InnerActionCode::INVALID_ACTION) { + return -E_INVALID_ARGS; + } + { + std::lock_guard uniqueLock(asyncTaskMutex_); + asyncTaskCount_++; + } + int errCode = RuntimeContext::GetInstance()->ScheduleTask([cloudDb, context, action, this]() { + InnerActionTask(context, cloudDb, action); + }); + if (errCode != E_OK) { + { + std::lock_guard uniqueLock(asyncTaskMutex_); + asyncTaskCount_--; + } + asyncTaskCv_.notify_all(); + LOGW("[CloudDBProxy] Schedule async task error %d", errCode); + return errCode; + } + if (context->WaitForRes(timeout_)) { + errCode = context->GetActionRes(); + } else { + errCode = -E_TIMEOUT; + } + return errCode; +} + +void CloudDBProxy::InnerActionTask(const std::shared_ptr &context, + const std::shared_ptr &cloudDb, InnerActionCode action) +{ + std::vector record; + std::vector extend; + VBucket queryExtend; + std::vector data; + std::pair lockContext; + context->MoveOutRecordAndExtend(record, extend); + size_t recordSize = record.size(); + context->MoveOutQueryExtendAndData(queryExtend, data); + DBStatus status; + LOGD("[CloudDBProxy] action %" PRIu8 " begin", static_cast(action)); + switch (action) { + case INSERT: + status = cloudDb->BatchInsert(context->GetTableName(), std::move(record), extend); + break; + case UPDATE: + status = cloudDb->BatchUpdate(context->GetTableName(), std::move(record), extend); + break; + case DELETE: + status = cloudDb->BatchDelete(context->GetTableName(), std::move(record), extend); + break; + case QUERY: + status = cloudDb->Query(context->GetTableName(), queryExtend, data); + break; + case LOCK: { + std::pair lockContext; + lockContext = cloudDb->Lock(); + status = lockContext.first == OK ? OK : CLOUD_ERROR; + break; + } + case UNLOCK: { + status = cloudDb->UnLock(); + break; + } + case HEARTBEAT: { + status = cloudDb->HeartBeat(); + break; + } + default: // should not happen + status = DB_ERROR; + } + LOGD("[CloudDBProxy] action %" PRIu8 " end", static_cast(action)); + context->MoveInLockContext(lockContext); + bool isCloudBatchUpload = (action == INSERT || action == UPDATE || action == DELETE); + if (status == REACH_END) { + context->SetActionRes(-E_REACH_END); + } else if (status != OK) { + if (isCloudBatchUpload) { + LOGE("[CloudSyncer] Cloud BATCH UPLOAD failed, %d.", status); + context->SetInfo(recordSize, 0u, recordSize); + } + context->SetActionRes(-E_CLOUD_ERROR); + } else { + if (isCloudBatchUpload) { + context->SetInfo(recordSize,recordSize, 0u); + } + context->SetActionRes(E_OK); + } + context->MoveInRecordAndExtend(record, extend); + context->FinishAndNotify(); + { + std::lock_guard uniqueLock(asyncTaskMutex_); + asyncTaskCount_--; + } + asyncTaskCv_.notify_all(); +} + +CloudDBProxy::CloudActionContext::CloudActionContext() + : actionFinished_(false), + actionRes_(OK), + totalCount_(0u), + successCount_(0u), + failedCount_(0u) +{ +} + +void CloudDBProxy::CloudActionContext::MoveInRecordAndExtend(std::vector &record, + std::vector &extend) +{ + std::lock_guard autoLock(actionMutex_); + record_ = std::move(record); + extend_ = std::move(extend); +} + +void CloudDBProxy::CloudActionContext::MoveOutRecordAndExtend(std::vector &record, + std::vector &extend) +{ + std::lock_guard autoLock(actionMutex_); + record = std::move(record_); + extend = std::move(extend_); +} + +void CloudDBProxy::CloudActionContext::MoveInQueryExtendAndData(VBucket &extend, std::vector &data) +{ + std::lock_guard autoLock(actionMutex_); + queryExtend_ = std::move(extend); + data_ = std::move(data); +} + +void CloudDBProxy::CloudActionContext::MoveOutQueryExtendAndData(VBucket &extend, std::vector &data) +{ + std::lock_guard autoLock(actionMutex_); + extend = std::move(queryExtend_); + data = std::move(data_); +} + +void CloudDBProxy::CloudActionContext::MoveInLockContext(std::pair &lockContext) +{ + std::lock_guard autoLock(actionMutex_); + lockContext_ = std::move(lockContext); +} + +void CloudDBProxy::CloudActionContext::MoveOutLockContext(std::pair &lockContext) +{ + std::lock_guard autoLock(actionMutex_); + lockContext = std::move(lockContext_); +} + +bool CloudDBProxy::CloudActionContext::WaitForRes(int64_t timeout) +{ + std::unique_lock uniqueLock(actionMutex_); + if (timeout == 0) { + actionCv_.wait(uniqueLock, [this]() { + return actionFinished_; + }); + return true; + } + return actionCv_.wait_for(uniqueLock, std::chrono::milliseconds(timeout), [this]() { + return actionFinished_; + }); +} + +void CloudDBProxy::CloudActionContext::FinishAndNotify() +{ + { + std::lock_guard autoLock(actionMutex_); + actionFinished_ = true; + } + actionCv_.notify_all(); +} + +void CloudDBProxy::CloudActionContext::SetActionRes(int res) +{ + std::lock_guard autoLock(actionMutex_); + actionRes_ = res; +} + +int CloudDBProxy::CloudActionContext::GetActionRes() +{ + std::lock_guard autoLock(actionMutex_); + return actionRes_; +} + +Info CloudDBProxy::CloudActionContext::GetInfo() +{ + std::lock_guard autoLock(actionMutex_); + return { + .total = totalCount_, + .successCount = successCount_, + .failCount = failedCount_ + }; +} + +void CloudDBProxy::CloudActionContext::SetInfo(const uint32_t &totalCount, const uint32_t &successCount, const uint32_t &failedCount) +{ + totalCount_ = totalCount; + successCount_ = successCount; + failedCount_ = failedCount; +} + +void CloudDBProxy::CloudActionContext::SetTableName(const std::string &tableName) +{ + std::lock_guard autoLock(actionMutex_); + tableName_ = tableName; +} + +std::string CloudDBProxy::CloudActionContext::GetTableName() +{ + std::lock_guard autoLock(actionMutex_); + return tableName_; +} +} \ No newline at end of file diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.h b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..3fbd7e00f96ce3ba18d05d782cad9ba7e528b46e --- /dev/null +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_db_proxy.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2023 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 CLOUD_DB_PROXY_H +#define CLOUD_DB_PROXY_H +#include +#include +#include +#include +#include "icloud_db.h" + +namespace DistributedDB { +class CloudDBProxy { +public: + CloudDBProxy(); + ~CloudDBProxy() = default; + + int SetCloudDB(const std::shared_ptr &cloudDB); + + int BatchInsert(const std::string &tableName, std::vector &record, + std::vector &extend, Info &uploadInfo); + + int BatchUpdate(const std::string &tableName, std::vector &record, + std::vector &extend, Info &uploadInfo); + + int BatchDelete(const std::string &tableName, std::vector &record, + std::vector &extend, Info &uploadInfo); + + int Query(const std::string &tableName, VBucket &extend, std::vector &data); + + std::pair Lock(); + + int UnLock(); + + int Close(); + + int HeartBeat(); + +private: + class CloudActionContext { + public: + CloudActionContext(); + ~CloudActionContext() = default; + + void MoveInRecordAndExtend(std::vector &record, std::vector &extend); + + void MoveOutRecordAndExtend(std::vector &record, std::vector &extend); + + void MoveInQueryExtendAndData(VBucket &extend, std::vector &data); + + void MoveOutQueryExtendAndData(VBucket &extend, std::vector &data); + + void MoveInLockContext(std::pair &lockContext); + + void MoveOutLockContext(std::pair &lockContext); + + bool WaitForRes(int64_t timeout); + + void SetActionRes(int res); + + int GetActionRes(); + + void FinishAndNotify(); + + Info GetInfo(); + + void SetInfo(const uint32_t &totalCount, const uint32_t &successCount, const uint32_t &failedCount); + + void SetTableName(const std::string &tableName); + + std::string GetTableName(); + private: + std::mutex actionMutex_; + std::condition_variable actionCv_; + bool actionFinished_; + int actionRes_; + uint32_t totalCount_; + uint32_t successCount_; + uint32_t failedCount_; + + std::string tableName_; + std::vector record_; + std::vector extend_; + VBucket queryExtend_; + std::vector data_; + std::pair lockContext_; + + }; + enum InnerActionCode : uint8_t { + INSERT = 0, + UPDATE, + DELETE, + QUERY, + LOCK, + UNLOCK, + HEARTBEAT, + // add action code before INVALID_ACTION + INVALID_ACTION + }; + int InnerAction(const std::shared_ptr &context, + const std::shared_ptr &cloudDb, InnerActionCode action); + + void InnerActionTask(const std::shared_ptr &context, + const std::shared_ptr &cloudDb, InnerActionCode action); + + std::shared_mutex cloudMutex_; + std::shared_ptr iCloudDb_; + std::atomic timeout_; + + std::mutex asyncTaskMutex_; + std::condition_variable asyncTaskCv_; + int32_t asyncTaskCount_; +}; +} +#endif // CLOUD_DB_PROXY_H diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_merge_strategy.cpp b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_merge_strategy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87c51c41062cdad5f86e94ce167a1aa14e50b383 --- /dev/null +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_merge_strategy.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 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 "cloud_merge_strategy.h" + +#include "db_common.h" +#include "db_errno.h" +namespace DistributedDB { + +OpType CloudMergeStrategy::TagSyncDataStatus(bool existInLocal, LogInfo &localInfo, LogInfo &cloudInfo) +{ + if (!existInLocal) { + return OpType::INSERT; + } + OpType type = OpType::NOT_HANDLE; + if (localInfo.timestamp > cloudInfo.timestamp) { + if (localInfo.cloudGid.empty()) { + type = OpType::ONLY_UPDATE_GID; + } + return type; + } + if ((cloudInfo.flag & 0x1) == 1) { + type = OpType::DELETE; + } else { + type = OpType::UPDATE; + } + return type; +} + +bool CloudMergeStrategy::JudgeUpdateCursor() +{ + return true; +} + +bool CloudMergeStrategy::JudgeUpload() +{ + return true; +} +} \ No newline at end of file diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_merge_strategy.h b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_merge_strategy.h new file mode 100644 index 0000000000000000000000000000000000000000..f09d1238bef06321bee9c1612a75943f7f14902b --- /dev/null +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_merge_strategy.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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 DIFFERENTIAL_STRATEGY_H +#define DIFFERENTIAL_STRATEGY_H +#include "cloud_sync_strategy.h" +namespace DistributedDB { +class CloudMergeStrategy : public CloudSyncStrategy { +public: + OpType TagSyncDataStatus(bool existInLocal, LogInfo &localInfo, LogInfo &cloudInfo) override; + + bool JudgeUpdateCursor() override; + + bool JudgeUpload() override; +}; +} +#endif // DIFFERENTIAL_STRATEGY_H diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_sync_strategy.h b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_sync_strategy.h new file mode 100644 index 0000000000000000000000000000000000000000..bd051a5115f6e0a7800bbf6ddb08fcfab6091d08 --- /dev/null +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_sync_strategy.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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 CLOUD_SYNC_STRATEGY_H +#define CLOUD_SYNC_STRATEGY_H + +#include "data_transformer.h" +#include "db_errno.h" +#include "db_types.h" +#include "icloud_sync_storage_interface.h" +namespace DistributedDB { +class CloudSyncStrategy { +public: + virtual OpType TagSyncDataStatus(bool existInLocal, LogInfo &localInfo, LogInfo &cloudInfo) + { + return OpType::NOT_HANDLE; + } + + virtual bool JudgeUpdateCursor() + { + return false; + } + + virtual bool JudgeUpload() + { + return false; + } +}; +} +#endif // CLOUD_SYNC_STRATEGY_H diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.cpp b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..84e923e4ce6fbe6b18e021bcbc650080e676d59d --- /dev/null +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.cpp @@ -0,0 +1,831 @@ +/* + * Copyright (c) 2023 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 +#include +#include "cloud_syncer.h" +#include "db_errno.h" +#include "icloud_db.h" +#include "kv_store_errno.h" +#include "log_print.h" +#include "runtime_context.h" +#include "securec.h" +#include "strategy_factory.h" +#include "storage_proxy.h" +#include "store_types.h" + +namespace DistributedDB { +namespace { + const TaskId INVALID_TASK_ID = 0u; + const char *CLOUD_DEVICE = "cloud"; +} +CloudSyncer::CloudSyncer(std::shared_ptr storageProxy) + : currentTaskId_(INVALID_TASK_ID), + storageProxy_(std::move(storageProxy)), + queuedManualSyncLimit_(DBConstant::QUEUED_SYNC_LIMIT_DEFAULT), + closed_(false) +{ +} + +int CloudSyncer::Sync(const std::vector &devices, SyncMode mode, + const std::vector &tables, const SyncProcessCallback &onProcess, + int64_t waitTime) +{ + int errCode = CheckParamValid(devices, mode); + if (errCode != E_OK) { + return errCode; + } + CloudTaskInfo taskInfo = { + .mode = mode, + .table = tables, + .callback = onProcess, + .timeout = waitTime + }; + errCode = TryToAddSyncTask(std::move(taskInfo)); + if (errCode != E_OK) { + return errCode; + } + return TriggerSync(); +} + +int CloudSyncer::SetCloudDB(const std::shared_ptr &cloudDB) +{ + cloudDB_.SetCloudDB(cloudDB); + LOGI("[CloudSyncer] SetCloudDB finish"); + return E_OK; +} + +void CloudSyncer::Close() +{ + closed_ = true; + cloudDB_.Close(); + { + LOGD("[CloudSyncer] begin wait current task finished"); + std::unique_lock uniqueLock(contextLock_); + contextCv_.wait(uniqueLock, [this]() { + return currentContext_.currentTaskId == INVALID_TASK_ID; + }); + LOGD("[CloudSyncer] current task has been finished"); + } + + // copy all task from queue + std::vector infoList; + { + std::lock_guard autoLock(queueLock_); + for (const auto &item: cloudTaskInfos_) { + infoList.push_back(item.second); + } + taskQueue_.clear(); + cloudTaskInfos_.clear(); + } + // notify all busy + for (auto &info: infoList) { + info.status = ProcessStatus::FINISHED; + info.errCode = -E_BUSY; + ProcessNotifier notifier; + notifier.Init(info.table); + notifier.NotifyProcess(info, {}); + } +} + +void CloudSyncer::ProcessNotifier::Init(const std::vector &tableName) +{ + std::lock_guard autoLock(processMutex_); + syncProcess_.errCode = OK; + syncProcess_.process = ProcessStatus::PROCESSING; + for (const auto &table: tableName) { + TableProcessInfo tableInfo = { + .process = ProcessStatus::PREPARED + }; + syncProcess_.tableProcess[table] = tableInfo; + } +} + +void CloudSyncer::ProcessNotifier::UpdateProcess(const CloudSyncer::InnerProcessInfo &process) +{ + std::lock_guard autoLock(processMutex_); + syncProcess_.tableProcess[process.tableName].process = process.tableStatus; + if (process.downLoadInfo.batchIndex != 0u) { + LOGD("[ProcessNotifier] update download process index: %" PRIu32, process.downLoadInfo.batchIndex); + syncProcess_.tableProcess[process.tableName].downLoadInfo.batchIndex = process.downLoadInfo.batchIndex; + syncProcess_.tableProcess[process.tableName].downLoadInfo.total += process.downLoadInfo.total; + syncProcess_.tableProcess[process.tableName].downLoadInfo.failCount += process.downLoadInfo.failCount; + syncProcess_.tableProcess[process.tableName].downLoadInfo.successCount += process.downLoadInfo.successCount; + } + if (process.upLoadInfo.batchIndex != 0u) { + LOGD("[ProcessNotifier] update upload process index: %" PRIu32, process.downLoadInfo.batchIndex); + syncProcess_.tableProcess[process.tableName].upLoadInfo.batchIndex = process.upLoadInfo.batchIndex; + syncProcess_.tableProcess[process.tableName].upLoadInfo.total += process.upLoadInfo.total; + syncProcess_.tableProcess[process.tableName].upLoadInfo.failCount += process.upLoadInfo.failCount; + syncProcess_.tableProcess[process.tableName].upLoadInfo.successCount += process.upLoadInfo.successCount; + } +} + +void CloudSyncer::ProcessNotifier::NotifyProcess(const CloudTaskInfo &taskInfo, const InnerProcessInfo &process) +{ + UpdateProcess(process); + SyncProcess currentProcess; + { + std::lock_guard autoLock(processMutex_); + syncProcess_.errCode = TransferDBErrno(taskInfo.errCode); + syncProcess_.process = taskInfo.status; + currentProcess = syncProcess_; + } + SyncProcessCallback callback = taskInfo.callback; + if (!callback) { + return; + } + int errCode = RuntimeContext::GetInstance()->ScheduleTask([callback, currentProcess]() { + callback(currentProcess); + LOGD("[ProcessNotifier] notify process finish"); + }); + if (errCode != E_OK) { + LOGW("[ProcessNotifier] schedule notify process failed %d", errCode); + } +} + +int CloudSyncer::TriggerSync() +{ + if (closed_) { + return -E_BUSY; + } + RefObject::IncObjRef(this); + int errCode = RuntimeContext::GetInstance()->ScheduleTask([this]() { + DoSyncIfNeed(); + RefObject::DecObjRef(this); + }); + if (errCode != E_OK) { + LOGW("[CloudSyncer] schedule sync task failed %d", errCode); + RefObject::DecObjRef(this); + } + return errCode; +} + +void CloudSyncer::DoSyncIfNeed() +{ + if (closed_) { + return; + } + // get taskId from queue + TaskId triggerTaskId; + { + std::lock_guard autoLock(queueLock_); + if (taskQueue_.empty()) { + return; + } + triggerTaskId = taskQueue_.front(); + } + // pop taskId in queue + if (PrepareSync(triggerTaskId) != E_OK) { + return; + } + // do sync logic + int errCode = DoSync(triggerTaskId); + // finished after sync + DoFinished(triggerTaskId, errCode, {}); + // do next task async + (void)TriggerSync(); +} + +int CloudSyncer::DoSync(TaskId taskId) +{ + CloudTaskInfo taskInfo; + { + std::lock_guard autoLock(queueLock_); + taskInfo = cloudTaskInfos_[taskId]; + } + int errCode = E_OK; + for (const auto &table: taskInfo.table) { + if (closed_) { + LOGD("[CloudSyncer] syncer is closed, abort sync"); + return -E_BUSY; + } + { + std::lock_guard autoLock(contextLock_); + currentContext_.tableName = table; + } + errCode = DoDownload(taskId); + if (errCode != E_OK) { + LOGD("[CloudSyncer] download failed %d", errCode); + return errCode; + } + } + for (const auto &table: taskInfo.table) { + if (closed_) { + LOGD("[CloudSyncer] syncer is closed, abort sync"); + return -E_BUSY; + } + { + std::lock_guard autoLock(contextLock_); + currentContext_.tableName = table; + } + errCode = DoUpload(taskId); + if (errCode != E_OK) { + LOGD("[CloudSyncer] upload failed %d", errCode); + return errCode; + } + } + return E_OK; +} + +void CloudSyncer::DoFinished(TaskId taskId, int errCode, const InnerProcessInfo &processInfo) +{ + std::shared_ptr notifier = nullptr; + { + // check current task is running or not + std::lock_guard autoLock(contextLock_); + if (currentContext_.currentTaskId != taskId) { // should not happen + LOGW("[CloudSyncer] task %" PRIu32 " not exist in context!", taskId); + return; + } + currentContext_.currentTaskId = INVALID_TASK_ID; + notifier = currentContext_.notifier; + currentContext_.notifier = nullptr; + currentContext_.strategy = nullptr; + currentContext_.tableName.clear(); + } + CloudTaskInfo info; + { + std::lock_guard autoLock(queueLock_); + if (cloudTaskInfos_.find(taskId) == cloudTaskInfos_.end()) { // should not happen + LOGW("[CloudSyncer] task %" PRIu32 " has been finished!", taskId); + contextCv_.notify_one(); + return; + } + info = std::move(cloudTaskInfos_[taskId]); + cloudTaskInfos_.erase(taskId); + } + contextCv_.notify_one(); + info.errCode = errCode; + info.status = ProcessStatus::FINISHED; + if (notifier != nullptr) { + notifier->NotifyProcess(info, processInfo); + } +} + +int CloudSyncer::SaveData(const TableName &tableName, DownloadData &downloadData, Info &downloadInfo) +{ + // Update download btach Info + downloadInfo.batchIndex += 1; + downloadInfo.total += downloadData.data.size(); + // Tag every datum in data set + int ret = E_OK; + for (size_t i = 0; i < downloadData.data.size(); i++) { + LogInfo localLogInfo; + bool isExist = true; + ret = storageProxy_->GetLogInfoByPrimaryKeyOrGid(tableName, downloadData.data[i], localLogInfo); + if (ret == -E_NOT_FOUND) { + isExist = false; + } else if (ret != E_OK) { + LOGE("[CloudSyncer] Cannot get cloud water level from cloud meta data: %d.", ret); + return ret; + } + // Get cloudLogInfo from cloud data + LogInfo cloudLogInfo = { + .timestamp = (Timestamp)std::get(downloadData.data[i][CloudDbConstant::MODIFY_FIELD]), + .wTimestamp = (Timestamp)std::get(downloadData.data[i][CloudDbConstant::CREATE_FIELD]), + .flag = (std::get(downloadData.data[i][CloudDbConstant::DELETE_FIELD])) == true ? 1u : 0u, + .cloudGid = std::get(downloadData.data[i][CloudDbConstant::GID_FIELD]), + }; + // Tag datum and get opType + downloadData.opType[i] = currentContext_.strategy->TagSyncDataStatus(isExist, localLogInfo, cloudLogInfo); + } + // save the data to the database by batch + // TODO: the interface needs to return successCnt + int successCnt = 0; + ret = storageProxy_->PutCloudSyncData(tableName, downloadData); + if (ret != E_OK) { + LOGE("[CloudSyncer] Cannot save the data to databse with error code: %d.", ret); + return ret; + } + // Update downloadInfo + downloadInfo.successCount = successCnt; + downloadInfo.failCount = downloadData.data.size() - successCnt; + return E_OK; +} + +int CloudSyncer::PreCheck(CloudSyncer::TaskId &taskId, std::string &tableName) +{ + // Check Input and Context Validity + if (closed_) { + LOGE("DB is closed."); + return E_INVALID_DB; + } + { + std::lock_guard autoLock(queueLock_); + if (cloudTaskInfos_.find(taskId) == cloudTaskInfos_.end()) { + LOGE("[CloudSyncer] Cloud Task Info does not exist Task Id: , %" PRIu64 ".", taskId); + return -E_INVALID_ARGS; + } + } + int ret = GetCurrentTableName(tableName); + if (ret != E_OK) { + LOGE("[CloudSyncer] Invalid table name for syncing: %d", ret); + return ret; + } + ret = storageProxy_->CheckSchema(tableName); + if (ret != E_OK) { + LOGE("A schema error occurred on the table to be synced, %d", ret); + return ret; + } + return E_OK; +} + +int CloudSyncer::DoDownload(CloudSyncer::TaskId taskId) +{ + TableName tableName; + int ret = PreCheck(taskId, tableName); + if (ret != E_OK) { + return ret; + } + InnerProcessInfo innerProcessInfo; + DownloadData downloadData; + bool reachEnd = false; + // Query data by batch until reaching end and not more data need to be download + while (!reachEnd) { + // Get cloud data after cloud water mark + ret = QueryCloudData(tableName, downloadData.data); + if (ret == -E_REACH_END) { + reachEnd = true; + } else if (ret != E_OK) { + return ret; + } + ret = storageProxy_->StartTransaction(TransactType::DEFERRED); + if (ret != E_OK) { + LOGE("[CloudSyncer] Cannot start a transaction: %d.", ret); + return ret; + } + ret = SaveData(tableName, downloadData, innerProcessInfo.downLoadInfo); + if (ret != E_OK) { + { + std::lock_guard autoLock(contextLock_); + currentContext_.notifier->UpdateProcess(innerProcessInfo); + } + return storageProxy_->Rollback(); + } + ret = storageProxy_->Commit(); + if (ret != E_OK) { + LOGE("[CloudSyncer] Cannot commit a transaction: %d.", ret); + return ret; + } + { + std::lock_guard autoLock(contextLock_); + currentContext_.notifier->NotifyProcess(cloudTaskInfos_[taskId], innerProcessInfo); + } + // use the cursor of the last datum in data set to update cloud water mark + CloudWaterMark newCloudWaterMark; + VBucket lastData = downloadData.data.back(); + newCloudWaterMark = std::get(lastData[CloudDbConstant::CURSOR_FIELD]); + ret = storageProxy_->PutCloudWaterMark(tableName, newCloudWaterMark); + if (ret != E_OK) { + LOGE("[CloudSyncer] Cannot set cloud water mark while downloading, %d.", ret); + return ret; + } + } + return E_OK; +} + +int CloudSyncer::PreCheckUpload(CloudSyncer::TaskId &taskId, std::string &tableName) +{ + int ret = PreCheck(taskId, tableName); + if (ret != E_OK) { + return ret; + } + if ((cloudTaskInfos_[taskId].mode < SYNC_MODE_CLOUD_MERGE) || (cloudTaskInfos_[taskId].mode > SYNC_MODE_CLOUD_FORCE_PUSH)) { + LOGE("[CloudSyncer] Upload failed, invalid sync mode: %d.", static_cast(cloudTaskInfos_[taskId].mode)); + return -E_INVALID_ARGS; + } + return E_OK; +} + +bool CloudSyncer:: CheckCloudSyncDataEmpty(CloudSyncData &uploadData) +{ + return uploadData.insData.extend.empty() && uploadData.insData.record.empty() && + uploadData.updData.extend.empty() && uploadData.updData.record.empty() && + uploadData.delData.extend.empty() && uploadData.delData.record.empty(); +} + +int CloudSyncer::DoBatchUpload(CloudSyncData &uploadData, const int64_t &count, const TaskId taskId, InnerProcessInfo &innerProcessInfo) +{ + int errCode = E_OK; + Info insertInfo; + Info updateInfo; + Info deleteInfo; + errCode = cloudDB_.BatchInsert(uploadData.tableName, uploadData.insData.record, uploadData.insData.extend, insertInfo); + innerProcessInfo.upLoadInfo.total += insertInfo.total; + if (errCode != E_OK) { + innerProcessInfo.upLoadInfo.failCount += insertInfo.failCount; + // if the upload is partilly successed, call UpdateProcess; + { + std::lock_guard autoLock(contextLock_); + currentContext_.notifier->UpdateProcess(innerProcessInfo); + } + return errCode; + } else { + innerProcessInfo.upLoadInfo.successCount += insertInfo.successCount; + // we need to fill back gid after insert data to cloud. + int ret = storageProxy_->FillCloudGid(uploadData); + if (ret != E_OK) { + LOGE("[CloudSyncer] Failed to fill back gid when doing upload, %d.", ret); + return ret; + } + } + + errCode = cloudDB_.BatchUpdate(uploadData.tableName, uploadData.updData.record, uploadData.updData.extend, updateInfo); + innerProcessInfo.upLoadInfo.total += updateInfo.total; + if (errCode != E_OK) { + innerProcessInfo.upLoadInfo.failCount += updateInfo.failCount; + { + std::lock_guard autoLock(contextLock_); + currentContext_.notifier->UpdateProcess(innerProcessInfo); + } + return errCode; + } else { + innerProcessInfo.upLoadInfo.successCount += updateInfo.successCount; + } + + errCode = cloudDB_.BatchDelete(uploadData.tableName, uploadData.delData.record, uploadData.delData.extend, deleteInfo); + innerProcessInfo.upLoadInfo.total += deleteInfo.total; + if (errCode != E_OK) { + innerProcessInfo.upLoadInfo.failCount += deleteInfo.failCount; + { + std::lock_guard autoLock(contextLock_); + currentContext_.notifier->UpdateProcess(innerProcessInfo); + } + return errCode; + } else { + innerProcessInfo.upLoadInfo.successCount += deleteInfo.successCount; + } + + // if the upload process is totally successed, call NotifyProcess + { + std::lock_guard autoLock(contextLock_); + currentContext_.notifier->NotifyProcess(cloudTaskInfos_[taskId], innerProcessInfo); + } + + // // update local water mark + // LocalWaterMark localMark; + // int ret = GetLatestLocalWatrMark(uploadData, localMark, count, taskId); + // if (ret != E_OK) { + // LOGE("[CloudSyncer] Failed to get new local water mark in Cloud Sync Data, %d.", ret); + // return ret; + // } + + // ret = storageProxy_->PutLocalWaterMark(uploadData.tableName, localMark); + // if (ret != E_OK) { + // LOGE("[CloudSyncer] Failed to set local water mark when doing upload, %d.", ret); + // return ret; + // } + + // The cloud water mark cannot be updated here, because the cloud api doesn't return cursor here. + + return E_OK; +} + +int CloudSyncer::DoUpload(CloudSyncer::TaskId taskId) +{ + storageProxy_->StartTransaction(); + int errCode = DoUploadInner(taskId); + if (errCode == E_OK) { + storageProxy_->Commit(); + } else { + storageProxy_->Rollback(); + } + return errCode; +} + +int CloudSyncer::DoUploadInner(CloudSyncer::TaskId taskId) +{ + std::string tableName; + int ret = PreCheckUpload(taskId, tableName); + if (ret != E_OK) { + LOGE("[CloudSyncer] Doing upload sync pre check failed, %d.", ret); + return ret; + } + + LocalWaterMark localMark; + ret = storageProxy_->GetLocalWaterMark(tableName, localMark); + if (ret != E_OK) { + LOGE("[CloudSyncer] Failed to get local water mark when upload, %d.", ret); + return ret; + } + + int64_t count = 0; + ret = storageProxy_->GetUploadCount(tableName, localMark, count); + if (ret != E_OK) { + // GetUploadCount will return E_OK when upload count is zero. + LOGE("[CloudSyncer] Failed to get Upload Data Count, %d.", ret); + return ret; + } + if (count == 0) { + LOGI("[CloudSyncer] There is no need to doing upload, as the upload data count is zero."); + return E_OK; + } + + ContinueToken continueStmtToken = NULL; + CloudSyncData uploadData(tableName); + + ret = storageProxy_->GetCloudData(tableName, localMark, continueStmtToken, uploadData); + if ((ret != E_OK) && (ret != -E_UNFINISHED)) { + LOGE("[CloudSyncer] Failed to get cloud data when upload, %d.", ret); + return ret; + } + + InnerProcessInfo innerProcessInfo; + innerProcessInfo.upLoadInfo.total = count; + uint32_t batchIndex = 0; + + while (!CheckCloudSyncDataEmpty(uploadData)) { + bool getDataUnfinished = ret == -E_UNFINISHED ? true : false; + if (closed_) { + LOGE("[CloudSyncer] DB is closed."); + if (getDataUnfinished) { + storageProxy_->ReleaseContinueToken(continueStmtToken); + } + return -E_INVALID_DB; + } + ret = CheckCloudSyncDataValid(uploadData, tableName, count, taskId); + if (ret != E_OK) { + LOGE("[CloudSyncer] Invalid Cloud Sync Data of Upload, %d.", ret); + if (getDataUnfinished) { + storageProxy_->ReleaseContinueToken(continueStmtToken); + } + return ret; + } + + innerProcessInfo.upLoadInfo.batchIndex = ++batchIndex; + + // update local water mark + LocalWaterMark localMark; + int ret = GetLatestLocalWatrMark(uploadData, localMark, count, taskId); + if (ret != E_OK) { + LOGE("[CloudSyncer] Failed to get new local water mark in Cloud Sync Data, %d.", ret); + if (getDataUnfinished) { + storageProxy_->ReleaseContinueToken(continueStmtToken); + } + return ret; + } + + ret = DoBatchUpload(uploadData, count, taskId, innerProcessInfo); + if (ret != E_OK) { + LOGE("[CloudSyncer] Failed to do upload, %d", ret); + if (getDataUnfinished) { + storageProxy_->ReleaseContinueToken(continueStmtToken); + } + return ret; + } + // if batch upload successed, update local water mark + ret = storageProxy_->PutLocalWaterMark(uploadData.tableName, localMark); + if (ret != E_OK) { + LOGE("[CloudSyncer] Failed to set local water mark when doing upload, %d.", ret); + if (getDataUnfinished) { + storageProxy_->ReleaseContinueToken(continueStmtToken); + } + return ret; + } + + // After each batch upload successed, call NotifyProcess. + { + std::lock_guard autoLock(contextLock_); + currentContext_.notifier->NotifyProcess(cloudTaskInfos_[taskId], innerProcessInfo); + } + + ClearCloudSyncData(uploadData); + + ret = storageProxy_->GetCloudDataNext(continueStmtToken, uploadData); + if ((ret != E_OK) && (ret != -E_UNFINISHED)) { + LOGE("[CloudSyncer] Failed to get cloud data next when doing upload, %d.", ret); + return ret; + } + } + return E_OK; +} + +int CloudSyncer::CheckDataValid(const DownloadData &data, std::string &cursor) +{ + return E_OK; +} + +int CloudSyncer::QueryCloudData(const std::string &tableName, std::vector &data) +{ + CloudWaterMark cloudWaterMark; + int ret = storageProxy_->GetCloudWaterMark(tableName, cloudWaterMark); + if (ret != E_OK) { + LOGE("[CloudSyncer] Cannot get cloud water level from cloud meta data: %d.", ret); + return ret; + } + VBucket extend = { + {CloudDbConstant::CURSOR_FIELD, cloudWaterMark} + }; + ret = cloudDB_.Query(tableName, extend, data); + if (ret == -E_REACH_END) { + LOGI("[CloudSyncer] Download data from cloud database usuccess and no more data need to be downloaded"); + return -E_REACH_END; + } + if (ret == OK) { + LOGI("[CloudSyncer] Download data from cloud database usuccess but still has data to download"); + return E_OK; + } + LOGE("[CloudSyncer] Download data from cloud database unsuccess"); + return -E_CLOUD_ERROR; +} + +int CloudSyncer::CheckParamValid(const std::vector &devices, SyncMode mode) +{ + if (devices.empty()) { + LOGE("[CloudSyncer] devices is empty"); + return -E_INVALID_ARGS; + } + if (devices.size() > 1) { + LOGE("[CloudSyncer] too much devices"); + return -E_INVALID_ARGS; + } + for (const auto &dev: devices) { + if (dev != CLOUD_DEVICE) { + LOGE("[CloudSyncer] invalid devices %s", STR_MASK(dev)); + return -E_INVALID_ARGS; + } + } + if (mode < SyncMode::SYNC_MODE_CLOUD_MERGE || mode > SyncMode::SYNC_MODE_CLOUD_FORCE_PULL) { + LOGE("[CloudSyncer] invalid mode %d", static_cast(mode)); + return -E_INVALID_ARGS; + } + return E_OK; +} + +bool CloudSyncer::CheckTaskIdValid(TaskId taskId) +{ + { + std::lock_guard autoLock(queueLock_); + if (cloudTaskInfos_.find(taskId) == cloudTaskInfos_.end()) { + return false; + } + } + std::lock_guard autoLock(contextLock_); + return currentContext_.currentTaskId == taskId; +} + +int CloudSyncer::GetCurrentTableName(std::string &tableName) +{ + std::lock_guard autoLock(contextLock_); + if (currentContext_.tableName.empty()) { + return -E_BUSY; + } + tableName = currentContext_.tableName; + return E_OK; +} + +int CloudSyncer::TryToAddSyncTask(CloudTaskInfo &&taskInfo) +{ + if (closed_) { + LOGW("[CloudSyncer] syncer is closed, should not sync now"); + return -E_BUSY; + } + std::lock_guard autoLock(queueLock_); + int errCode = CheckQueueSizeWithNoLock(); + if (errCode != E_OK) { + return errCode; + } + do { + currentTaskId_++; + } while (currentTaskId_ == 0); + taskInfo.taskId = currentTaskId_; + taskQueue_.push_back(currentTaskId_); + cloudTaskInfos_[currentTaskId_] = taskInfo; + LOGI("[CloudSyncer] Add task ok, taskId %" PRIu32, cloudTaskInfos_[currentTaskId_].taskId); + return E_OK; +} + +int CloudSyncer::CheckQueueSizeWithNoLock() +{ + int32_t limit = queuedManualSyncLimit_; + if (taskQueue_.size() >= static_cast(limit)) { + LOGW("[CloudSyncer] too much sync task"); + return -E_BUSY; + } + return E_OK; +} + +int CloudSyncer::PrepareSync(TaskId taskId) +{ + std::vector tableNames; + SyncMode mode; + { + std::lock_guard autoLock(queueLock_); + if (closed_ || cloudTaskInfos_.find(taskId) == cloudTaskInfos_.end()) { + LOGW("[CloudSyncer] Abort sync because syncer is closed"); + return -E_BUSY; + } + tableNames = cloudTaskInfos_[taskId].table; + mode = cloudTaskInfos_[taskId].mode; + } + { + // check current task is running or not + std::lock_guard autoLock(contextLock_); + if (closed_ || currentContext_.currentTaskId != INVALID_TASK_ID) { + LOGW("[CloudSyncer] Abort sync because syncer is closed or another task is running"); + return -E_BUSY; + } + currentContext_.currentTaskId = taskId; + currentContext_.notifier = std::make_shared(); + currentContext_.strategy = StrategyFactory::BuildSyncStrategy(mode); + currentContext_.notifier->Init(tableNames); + } + // remove task id from queue + std::lock_guard autoLock(queueLock_); + if (!taskQueue_.empty()) { + taskQueue_.pop_front(); + } + cloudTaskInfos_[taskId].status = ProcessStatus::PROCESSING; + return E_OK; +} + +int CloudSyncer::CheckCloudSyncDataValid(CloudSyncData uploadData, const std::string &tableName, const int64_t &count, TaskId &taskId) +{ + long unsigned int insRecordLen = uploadData.insData.record.size(); + long unsigned int insExtendLen = uploadData.insData.extend.size(); + long unsigned int updRecordLen = uploadData.updData.record.size(); + long unsigned int updExtendLen = uploadData.updData.extend.size(); + long unsigned int delRecordLen = uploadData.delData.record.size(); + long unsigned int delExtendLen = uploadData.delData.extend.size(); + + bool SyncDataValid = uploadData.tableName == tableName && + (insRecordLen > 0 && insExtendLen > 0 && insRecordLen == insExtendLen) || + (updRecordLen > 0 && updExtendLen > 0 && updRecordLen == updExtendLen) || + (delRecordLen > 0 && delExtendLen > 0 && delRecordLen == delExtendLen); + + if (!SyncDataValid) { + LOGE("upload data is empty but upload count is not zero or upload table name is not the same as table name of sync data."); + return -E_INVALID_CLOUD_SYNC_DATA; + } + int64_t SyncDataCount = uploadData.insData.record.size() + uploadData.updData.record.size() + uploadData.delData.record.size(); + + if (SyncDataCount > count) { + LOGE("Size of a batch of sync data is greater than upload data size."); + return -E_INVALID_CLOUD_SYNC_DATA; + } + + return E_OK; +} + +// After doing a batch upload, we need to use CloudSyncData's maximum timestamp to update the water mark; +int CloudSyncer::GetLatestLocalWatrMark(CloudSyncData &uploadData, LocalWaterMark &WaterMark, const int64_t &count, TaskId taskId) +{ + if (!CheckCloudSyncDataValid(uploadData, uploadData.tableName, count, taskId)) { + LOGE("[CloudSyncer] Invalid Sync Data when get local water mark.", -E_INVALID_CLOUD_SYNC_DATA); + return -E_INVALID_CLOUD_SYNC_DATA; + } + + if (uploadData.insData.extend.size() > 0) { + if (uploadData.insData.record.size() != uploadData.insData.extend.size()) { + LOGE("[CloudSyncer] Inconsistent size of inserted data.", -E_INVALID_CLOUD_SYNC_DATA); + return -E_INVALID_CLOUD_SYNC_DATA; + } + for(auto extendData : uploadData.insData.extend) { + WaterMark = std::max(int64_t(WaterMark), std::get(extendData[CloudDbConstant::MODIFY_FIELD])); + } + } + + if (uploadData.updData.extend.size() > 0) { + if (uploadData.updData.record.size() != uploadData.updData.extend.size()) { + LOGE("[CloudSyncer] Inconsistent size of updated data, %d.", -E_INVALID_CLOUD_SYNC_DATA); + return -E_INVALID_CLOUD_SYNC_DATA; + } + for(auto extendData : uploadData.updData.extend) { + WaterMark = std::max(int64_t(WaterMark), std::get(extendData[CloudDbConstant::MODIFY_FIELD])); + } + } + + if (uploadData.delData.extend.size() > 0) { + if (uploadData.delData.record.size() != uploadData.delData.extend.size()) { + LOGE("[CloudSyncer] Inconsistent size of deleted data, %d.", -E_INVALID_CLOUD_SYNC_DATA); + return -E_INVALID_CLOUD_SYNC_DATA; + } + for(auto extendData : uploadData.delData.extend) { + WaterMark = std::max(int64_t(WaterMark), std::get(extendData[CloudDbConstant::MODIFY_FIELD])); + } + } + return E_OK; +} + +void CloudSyncer::ClearCloudSyncData(CloudSyncData &uploadData) { + std::vector().swap(uploadData.insData.record); + std::vector().swap(uploadData.insData.extend); + std::vector().swap(uploadData.updData.record); + std::vector().swap(uploadData.updData.extend); + std::vector().swap(uploadData.delData.record); + std::vector().swap(uploadData.delData.extend); +} + +} // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h new file mode 100644 index 0000000000000000000000000000000000000000..0c98ef59f0a689c91452528f2e37bcee0c355118 --- /dev/null +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2023 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 CLOUD_SYNCER_H +#define CLOUD_SYNCER_H +#include +#include +#include +#include "cloud_db_proxy.h" +#include "cloud_store_types.h" +#include "cloud_sync_strategy.h" +#include "db_common.h" +#include "data_transformer.h" +#include "icloud_db.h" +#include "ref_object.h" +#include "storage_proxy.h" + +namespace DistributedDB { +using SyncProcessCallback = std::function; +class CloudSyncer : public RefObject{ +public: + explicit CloudSyncer(std::shared_ptr storageProxy); + ~CloudSyncer() override = default; + DISABLE_COPY_ASSIGN_MOVE(CloudSyncer); + + int Sync(const std::vector &devices, SyncMode mode, const std::vector &tables, + const SyncProcessCallback &callback, int64_t waitTime); + + int SetCloudDB(const std::shared_ptr &cloudDB); + + void Close(); +protected: + using TaskId = uint64_t; + struct CloudTaskInfo { + SyncMode mode = SyncMode::SYNC_MODE_PUSH_ONLY; + ProcessStatus status = ProcessStatus::PREPARED; + int errCode = 0; + TaskId taskId = 0u; + std::vector table; + SyncProcessCallback callback; + int64_t timeout; + }; + struct InnerProcessInfo { + std::string tableName; + ProcessStatus tableStatus = ProcessStatus::PREPARED; + Info downLoadInfo; + Info upLoadInfo; + }; + class ProcessNotifier { + public: + void Init(const std::vector &tableName); + + void UpdateProcess(const InnerProcessInfo &process); + + void NotifyProcess(const CloudTaskInfo &taskInfo, const InnerProcessInfo &process); + protected: + std::mutex processMutex_; + SyncProcess syncProcess_; + }; + struct TaskContext { + TaskId currentTaskId = 0u; + std::string tableName; + std::shared_ptr notifier; + std::shared_ptr strategy; + }; + + int TriggerSync(); + + void DoSyncIfNeed(); + + int DoSync(TaskId taskId); + + void DoFinished(TaskId taskId, int errCode, const InnerProcessInfo &processInfo); + + int DoDownload(TaskId taskId); + + int PreCheckUpload(TaskId &taskId, std::string &tableName); + + int PreCheck(TaskId &taskId, std::string &tableName); + + int DoBatchUpload(CloudSyncData &uploadData, const int64_t &count, const TaskId taskId, InnerProcessInfo &innerProcessInfo); + + int CheckCloudSyncDataValid(CloudSyncData uploadData, const std::string &tableName, const int64_t &count, TaskId &taskId); + + bool CheckCloudSyncDataEmpty(CloudSyncData &uploadData); + + int GetLatestLocalWatrMark(CloudSyncData &uploadData, LocalWaterMark &WaterMark, const int64_t &count, TaskId taskId); + + void ClearCloudSyncData(CloudSyncData &uploadData); + + int DoUpload(TaskId taskId); + + int DoUploadInner(TaskId taskId); + + int CheckDataValid(const DownloadData &data, std::string &cursor); + + int QueryCloudData(const std::string &tableName, std::vector &data); + + bool CheckTaskIdValid(TaskId taskId); + + int GetCurrentTableName(std::string &tableName); + + int TryToAddSyncTask(CloudTaskInfo &&taskInfo); + + int CheckQueueSizeWithNoLock(); + + int PrepareSync(TaskId taskId); + + int SaveData(const TableName &tablename, DownloadData &downloadData, Info &downloadInfo); + + static int CheckParamValid(const std::vector &devices, SyncMode mode); + + std::mutex queueLock_; + std::atomic currentTaskId_; + std::list taskQueue_; + std::map cloudTaskInfos_; + + std::mutex contextLock_; + TaskContext currentContext_; + std::condition_variable contextCv_; + + CloudDBProxy cloudDB_; + + std::shared_ptr storageProxy_; + std::atomic queuedManualSyncLimit_; + + std::atomic closed_; +}; +} +#endif // CLOUD_SYNCER_H diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/strategy_factory.cpp b/frameworks/libs/distributeddb/syncer/src/cloud/strategy_factory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a9d70d4903e23b5751a080d70c57426851cfb996 --- /dev/null +++ b/frameworks/libs/distributeddb/syncer/src/cloud/strategy_factory.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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 "strategy_factory.h" +#include "cloud_merge_strategy.h" +namespace DistributedDB { +std::shared_ptr StrategyFactory::BuildSyncStrategy(SyncMode mode) +{ + switch (mode) { + case SyncMode::SYNC_MODE_CLOUD_MERGE: + return std::make_shared(); + default: + LOGW("[StrategyFactory] Not support mode %d", static_cast(mode)); + return std::make_shared(); + } +} +} \ No newline at end of file diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/strategy_factory.h b/frameworks/libs/distributeddb/syncer/src/cloud/strategy_factory.h new file mode 100644 index 0000000000000000000000000000000000000000..dd3b9bcc019630571274ad110346dedae838f738 --- /dev/null +++ b/frameworks/libs/distributeddb/syncer/src/cloud/strategy_factory.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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 STRATEGY_FACTORY_H +#define STRATEGY_FACTORY_H +#include "cloud_sync_strategy.h" +#include "db_common.h" +#include "store_types.h" +namespace DistributedDB { +class StrategyFactory { +public: + static std::shared_ptr BuildSyncStrategy(SyncMode mode); +}; +} + +#endif // STRATEGY_FACTORY_H diff --git a/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp b/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp index 76952725f2127fe24c2873ca7be16543662629f5..6ed92a086a60dd50b8aa7ec2727315a08990440b 100644 --- a/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp +++ b/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp @@ -49,6 +49,7 @@ GenericSyncer::GenericSyncer() manualSyncEnable_(true), closing_(false), engineFinalize_(false), + timeChangeListenerFinalize_(true), timeChangedListener_(nullptr) { } @@ -93,24 +94,17 @@ int GenericSyncer::Initialize(ISyncInterface *syncInterface, bool isNeedActive) label.resize(3); // only show 3 Bytes enough label_ = DBCommon::VectorToHexString(label); - // As metadata_ will be used in EraseDeviceWaterMark, it should not be clear even if engine init failed. - // It will be clear in destructor. - int errCodeMetadata = InitMetaData(syncInterface); - - // As timeHelper_ will be used in GetTimestamp, it should not be clear even if engine init failed. - // It will be clear in destructor. - int errCodeTimeHelper = InitTimeHelper(syncInterface); - - if (!IsNeedActive(syncInterface)) { - return -E_NO_NEED_ACTIVE; + int errCode = InitStorageResource(syncInterface); + if (errCode != E_OK) { + return errCode; } // As timeChangedListener_ will record time change, it should not be clear even if engine init failed. // It will be clear in destructor. int errCodeTimeChangedListener = InitTimeChangedListener(); - if (errCodeMetadata != E_OK || errCodeTimeHelper != E_OK || errCodeTimeChangedListener != E_OK) { + if (errCodeTimeChangedListener != E_OK) { return -E_INTERNAL_ERROR; } - int errCode = CheckSyncActive(syncInterface, isNeedActive); + errCode = CheckSyncActive(syncInterface, isNeedActive); if (errCode != E_OK) { return errCode; } @@ -309,21 +303,35 @@ uint64_t GenericSyncer::GetTimestamp() void GenericSyncer::QueryAutoSync(const InternalSyncParma ¶m) { if (!initialized_) { - LOGE("[Syncer] Syncer has not Init"); + LOGW("[Syncer] Syncer has not Init"); return; } LOGI("[GenericSyncer] trigger query syncmode=%u,dev=%s", param.mode, GetSyncDevicesStr(param.devices).c_str()); - RefObject::IncObjRef(syncEngine_); - int retCode = RuntimeContext::GetInstance()->ScheduleTask([this, param] { + ISyncInterface *syncInterface = nullptr; + ISyncEngine *engine = nullptr; + { + std::lock_guard lock(syncerLock_); + if (syncInterface_ == nullptr || syncEngine_ == nullptr) { + LOGW("[Syncer] Syncer has not Init"); + return; + } + syncInterface = syncInterface_; + engine = syncEngine_; + syncInterface->IncRefCount(); + RefObject::IncObjRef(engine); + } + int retCode = RuntimeContext::GetInstance()->ScheduleTask([this, param, engine, syncInterface] { int errCode = Sync(param); if (errCode != E_OK) { LOGE("[GenericSyncer] sync start by QueryAutoSync failed err %d", errCode); } - RefObject::DecObjRef(syncEngine_); + RefObject::DecObjRef(engine); + syncInterface->DecRefCount(); }); if (retCode != E_OK) { LOGE("[GenericSyncer] QueryAutoSync triggler sync retCode:%d", retCode); - RefObject::DecObjRef(syncEngine_); + RefObject::DecObjRef(engine); + syncInterface->DecRefCount(); } } @@ -788,7 +796,7 @@ int GenericSyncer::StatusCheck() const { if (!initialized_) { LOGE("[Syncer] Syncer is not initialized, return!"); - return -E_NOT_INIT; + return -E_BUSY; } if (closing_) { LOGW("[Syncer] Syncer is closing, return!"); @@ -914,11 +922,22 @@ int GenericSyncer::InitTimeChangedListener() timeChangedListener_ = RuntimeContext::GetInstance()->RegisterTimeChangedLister( [this](void *changedOffset) { RecordTimeChangeOffset(changedOffset); + }, + [this]() { + { + std::lock_guard autoLock(timeChangeListenerMutex_); + timeChangeListenerFinalize_ = true; + } + timeChangeCv_.notify_all(); }, errCode); if (timeChangedListener_ == nullptr) { LOGE("[GenericSyncer] Init RegisterTimeChangedLister failed"); return errCode; } + { + std::lock_guard autoLock(timeChangeListenerMutex_); + timeChangeListenerFinalize_ = false; + } return E_OK; } @@ -938,6 +957,12 @@ void GenericSyncer::ReleaseInnerResource() timeChangedListener->Drop(true); RuntimeContext::GetInstance()->StopTimeTickMonitorIfNeed(); } + std::unique_lock uniqueLock(timeChangeListenerMutex_); + LOGD("[GenericSyncer] Begin wait time change listener finalize"); + timeChangeCv_.wait(uniqueLock, [this]() { + return timeChangeListenerFinalize_; + }); + LOGD("[GenericSyncer] End wait time change listener finalize"); } void GenericSyncer::RecordTimeChangeOffset(void *changedOffset) @@ -1051,4 +1076,33 @@ bool GenericSyncer::IsNeedActive(ISyncInterface *syncInterface) } return true; } + +int GenericSyncer::GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const +{ + (void)clientId; + (void)hashDevId; + return -E_NOT_SUPPORT; +} + +int GenericSyncer::InitStorageResource(ISyncInterface *syncInterface) +{ + // As metadata_ will be used in EraseDeviceWaterMark, it should not be clear even if engine init failed. + // It will be clear in destructor. + int errCode = InitMetaData(syncInterface); + if (errCode != E_OK) { + return errCode; + } + + // As timeHelper_ will be used in GetTimestamp, it should not be clear even if engine init failed. + // It will be clear in destructor. + errCode = InitTimeHelper(syncInterface); + if (errCode != E_OK) { + return errCode; + } + + if (!IsNeedActive(syncInterface)) { + return -E_NO_NEED_ACTIVE; + } + return errCode; +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/syncer/src/generic_syncer.h b/frameworks/libs/distributeddb/syncer/src/generic_syncer.h index 2b7ea6c4cfac79b306b78cccfb3f97b6eb3a00cf..3b5c315a247b762b257e18f3fdda33fc8c1a7630 100644 --- a/frameworks/libs/distributeddb/syncer/src/generic_syncer.h +++ b/frameworks/libs/distributeddb/syncer/src/generic_syncer.h @@ -104,6 +104,7 @@ public: int GetSyncDataSize(const std::string &device, size_t &size) const override; + int GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const override; protected: // trigger query auto sync or auto subscribe @@ -187,6 +188,8 @@ protected: int CloseInner(bool isClosedOperation); + int InitStorageResource(ISyncInterface *syncInterface); + static int SyncModuleInit(); static int SyncResourceInit(); @@ -221,6 +224,9 @@ protected: bool engineFinalize_; std::condition_variable engineFinalizeCv_; + std::mutex timeChangeListenerMutex_; + bool timeChangeListenerFinalize_; + std::condition_variable timeChangeCv_; NotificationChain::Listener *timeChangedListener_; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/syncer/src/isync_task_context.h b/frameworks/libs/distributeddb/syncer/src/isync_task_context.h index 3c51184b44a40afe66c7b8f0d4e67182669904f6..e489afd54955979faa31aee5c22ac15ca8d6a356 100644 --- a/frameworks/libs/distributeddb/syncer/src/isync_task_context.h +++ b/frameworks/libs/distributeddb/syncer/src/isync_task_context.h @@ -68,7 +68,7 @@ public: // Move to next target to sync virtual void MoveToNextTarget() = 0; - virtual int GetNextTarget(bool isNeedSetFinished) = 0; + virtual int GetNextTarget() = 0; // Get the current task syncId virtual uint32_t GetSyncId() const = 0; diff --git a/frameworks/libs/distributeddb/syncer/src/meta_data.cpp b/frameworks/libs/distributeddb/syncer/src/meta_data.cpp index 5bfc2b5a232fda015508cef07a63841a0730214d..257537adf9366a77b20cefa813d913ce8544d6e5 100644 --- a/frameworks/libs/distributeddb/syncer/src/meta_data.cpp +++ b/frameworks/libs/distributeddb/syncer/src/meta_data.cpp @@ -16,6 +16,7 @@ #include "meta_data.h" #include + #include "db_common.h" #include "db_constant.h" #include "db_errno.h" @@ -30,6 +31,7 @@ namespace { const int STR_TO_LL_BY_DEVALUE = 10; // store local timeoffset;this is a special key; const std::string LOCALTIME_OFFSET_KEY = "localTimeOffset"; + const char *CLIENT_ID_PREFIX_KEY = "clientId"; } Metadata::Metadata() @@ -124,7 +126,7 @@ int Metadata::SavePeerWaterMark(const DeviceID &deviceId, uint64_t inValue, bool GetMetaDataValue(deviceId, metadata, isNeedHash); metadata.peerWaterMark = inValue; LOGD("Metadata::SavePeerWaterMark = %" PRIu64, inValue); - return SaveMetaDataValue(deviceId, metadata); + return SaveMetaDataValue(deviceId, metadata, isNeedHash); } int Metadata::SaveLocalTimeOffset(TimeOffset timeOffset) @@ -157,12 +159,13 @@ int Metadata::EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash) int Metadata::EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash, const std::string &tableName) { + std::lock_guard autoLock(waterMarkMutex_); // try to erase all the waterMark // erase deleteSync recv waterMark WaterMark waterMark = 0; - int errCodeDeleteSync = SetRecvDeleteSyncWaterMark(deviceId, waterMark); + int errCodeDeleteSync = SetRecvDeleteSyncWaterMark(deviceId, waterMark, isNeedHash); // erase querySync recv waterMark - int errCodeQuerySync = ResetRecvQueryWaterMark(deviceId, tableName); + int errCodeQuerySync = ResetRecvQueryWaterMark(deviceId, tableName, isNeedHash); // peerWaterMark must be erased at last int errCode = SavePeerWaterMark(deviceId, 0, isNeedHash); if (errCode != E_OK) { @@ -194,7 +197,7 @@ Timestamp Metadata::GetLastLocalTime() const return lastLocalTime_; } -int Metadata::SaveMetaDataValue(const DeviceID &deviceId, const MetaDataValue &inValue) +int Metadata::SaveMetaDataValue(const DeviceID &deviceId, const MetaDataValue &inValue, bool isNeedHash) { std::vector value; int errCode = SerializeMetaData(inValue, value); @@ -203,7 +206,7 @@ int Metadata::SaveMetaDataValue(const DeviceID &deviceId, const MetaDataValue &i } DeviceID hashDeviceId; - GetHashDeviceId(deviceId, hashDeviceId, true); + GetHashDeviceId(deviceId, hashDeviceId, isNeedHash); std::vector key; DBCommon::StringToVector(hashDeviceId, key); errCode = SetMetadataToDb(key, value); @@ -232,12 +235,11 @@ int Metadata::SerializeMetaData(const MetaDataValue &inValue, std::vector &inValue, MetaDataValue &outValue) const +int Metadata::DeSerializeMetaData(const std::vector &inValue, MetaDataValue &outValue) { if (inValue.empty()) { return -E_INVALID_ARGS; } - errno_t err = memcpy_s(&outValue, sizeof(MetaDataValue), inValue.data(), inValue.size()); if (err != EOK) { return -E_SECUREC_ERROR; @@ -457,14 +459,14 @@ int Metadata::GetRecvDeleteSyncWaterMark(const DeviceID &deviceId, WaterMark &wa return E_OK; } -int Metadata::SetRecvDeleteSyncWaterMark(const DeviceID &deviceId, const WaterMark &waterMark) +int Metadata::SetRecvDeleteSyncWaterMark(const DeviceID &deviceId, const WaterMark &waterMark, bool isNeedHash) { - return querySyncWaterMarkHelper_.SetRecvDeleteSyncWaterMark(deviceId, waterMark); + return querySyncWaterMarkHelper_.SetRecvDeleteSyncWaterMark(deviceId, waterMark, isNeedHash); } -int Metadata::ResetRecvQueryWaterMark(const DeviceID &deviceId, const std::string &tableName) +int Metadata::ResetRecvQueryWaterMark(const DeviceID &deviceId, const std::string &tableName, bool isNeedHash) { - return querySyncWaterMarkHelper_.ResetRecvQueryWaterMark(deviceId, tableName); + return querySyncWaterMarkHelper_.ResetRecvQueryWaterMark(deviceId, tableName, isNeedHash); } void Metadata::GetDbCreateTime(const DeviceID &deviceId, uint64_t &outValue) @@ -511,7 +513,7 @@ int Metadata::ResetMetaDataAfterRemoveData(const DeviceID &deviceId) GetHashDeviceId(deviceId, hashDeviceId, true); if (metadataMap_.find(hashDeviceId) != metadataMap_.end()) { metadata = metadataMap_[hashDeviceId]; - metadata.clearDeviceDataMark = 0; + metadata.clearDeviceDataMark = 0; // clear mark return SaveMetaDataValue(deviceId, metadata); } return -E_NOT_FOUND; @@ -570,4 +572,75 @@ void Metadata::RemoveQueryFromRecordSet(const DeviceID &deviceId, const std::str iter->second.erase(hashqueryId); } } + +int Metadata::SaveClientId(const std::string &deviceId, const std::string &clientId) +{ + { + // already save in cache + std::lock_guard autoLock(clientIdLock_); + if (clientIdCache_[deviceId] == clientId) { + return E_OK; + } + } + std::string keyStr; + keyStr.append(CLIENT_ID_PREFIX_KEY).append(clientId); + std::string valueStr = DBCommon::TransferHashString(deviceId); + Key key; + DBCommon::StringToVector(keyStr, key); + Value value; + DBCommon::StringToVector(valueStr, value); + int errCode = SetMetadataToDb(key, value); + if (errCode != E_OK) { + return errCode; + } + std::lock_guard autoLock(clientIdLock_); + clientIdCache_[deviceId] = clientId; + return E_OK; +} + +int Metadata::GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const +{ + // don't use cache here avoid invalid cache + std::string keyStr; + keyStr.append(CLIENT_ID_PREFIX_KEY).append(clientId); + Key key; + DBCommon::StringToVector(keyStr, key); + Value value; + int errCode = GetMetadataFromDb(key, value); + if (errCode == -E_NOT_FOUND) { + LOGD("[Metadata] not found clientId"); + return -E_NOT_SUPPORT; + } + if (errCode != E_OK) { + LOGE("[Metadata] reload clientId failed %d", errCode); + return errCode; + } + DBCommon::VectorToString(value, hashDevId); + return E_OK; +} + +void Metadata::LockWaterMark() const +{ + waterMarkMutex_.lock(); +} + +void Metadata::UnlockWaterMark() const +{ + waterMarkMutex_.unlock(); +} + +Metadata::MetaWaterMarkAutoLock::MetaWaterMarkAutoLock(std::shared_ptr metadata) + : metadataPtr_(std::move(metadata)) +{ + if (metadataPtr_ != nullptr) { + metadataPtr_->LockWaterMark(); + } +} + +Metadata::MetaWaterMarkAutoLock::~MetaWaterMarkAutoLock() +{ + if (metadataPtr_ != nullptr) { + metadataPtr_->UnlockWaterMark(); + } +} } // namespace DistributedDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/syncer/src/meta_data.h b/frameworks/libs/distributeddb/syncer/src/meta_data.h index 26e2287bf5fac7df735fe291101e80f38eb7eaac..19ec075e667e8b74f25017222059e0dc900d7fd1 100644 --- a/frameworks/libs/distributeddb/syncer/src/meta_data.h +++ b/frameworks/libs/distributeddb/syncer/src/meta_data.h @@ -37,6 +37,15 @@ struct MetaDataValue { class Metadata { public: + class MetaWaterMarkAutoLock final { + public: + explicit MetaWaterMarkAutoLock(std::shared_ptr metadata); + ~MetaWaterMarkAutoLock(); + private: + DISABLE_COPY_ASSIGN_MOVE(MetaWaterMarkAutoLock); + const std::shared_ptr metadataPtr_; + }; + Metadata(); virtual ~Metadata(); @@ -93,7 +102,7 @@ public: // if the sendWatermark less than device watermark int GetSendDeleteSyncWaterMark(const std::string &deviceId, WaterMark &waterMark, bool isAutoLift = true); - int SetRecvDeleteSyncWaterMark(const std::string &deviceId, const WaterMark &waterMark); + int SetRecvDeleteSyncWaterMark(const std::string &deviceId, const WaterMark &waterMark, bool isNeedHash = true); // the deleteSync's recvWatermark will increase by the device watermark // if the recvWatermark less than device watermark @@ -111,16 +120,24 @@ public: uint64_t GetQueryLastTimestamp(const DeviceID &deviceId, const std::string &queryId) const; void RemoveQueryFromRecordSet(const DeviceID &deviceId, const std::string &queryId); + + int SaveClientId(const std::string &deviceId, const std::string &clientId); + + int GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const; + + void LockWaterMark() const; + + void UnlockWaterMark() const; private: - int SaveMetaDataValue(const DeviceID &deviceId, const MetaDataValue &inValue); + int SaveMetaDataValue(const DeviceID &deviceId, const MetaDataValue &inValue, bool isNeedHash = true); // sync module need hash devices id void GetMetaDataValue(const DeviceID &deviceId, MetaDataValue &outValue, bool isNeedHash); - int SerializeMetaData(const MetaDataValue &inValue, std::vector &outValue); + static int SerializeMetaData(const MetaDataValue &inValue, std::vector &outValue); - int DeSerializeMetaData(const std::vector &inValue, MetaDataValue &outValue) const; + static int DeSerializeMetaData(const std::vector &inValue, MetaDataValue &outValue); int GetMetadataFromDb(const std::vector &key, std::vector &outValue) const; @@ -143,7 +160,7 @@ private: int LoadDeviceIdDataToMap(const Key &key); // reset the waterMark to zero - int ResetRecvQueryWaterMark(const DeviceID &deviceId, const std::string &tableName = ""); + int ResetRecvQueryWaterMark(const DeviceID &deviceId, const std::string &tableName, bool isNeedHash); // store localTimeOffset in ram; if change, should add a lock first, change here and metadata, // then release lock @@ -167,6 +184,11 @@ private: // queryId is not in set while key is not found from db first time, and return lastTimestamp = INT64_MAX // if query is in set return 0 while not found from db, means already sync before, don't trigger again mutable std::map> queryIdMap_; + + std::mutex clientIdLock_; + std::map clientIdCache_; + + mutable std::recursive_mutex waterMarkMutex_; }; } // namespace DistributedDB #endif diff --git a/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp b/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp index e15ba593d1be8c20872b4d5e7d003f9648243cd5..575d8c233caa3aa5237b7add1e035c6d59a9062f 100644 --- a/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp +++ b/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp @@ -317,9 +317,10 @@ int QuerySyncWaterMarkHelper::SetSendDeleteSyncWaterMark(const DeviceID &deviceI return UpdateDeleteSyncCacheAndSave(hashId, deleteWaterMark); } -int QuerySyncWaterMarkHelper::SetRecvDeleteSyncWaterMark(const DeviceID &deviceId, const WaterMark &waterMark) +int QuerySyncWaterMarkHelper::SetRecvDeleteSyncWaterMark(const DeviceID &deviceId, const WaterMark &waterMark, + bool isNeedHash) { - std::string hashId = GetHashDeleteSyncDeviceId(deviceId); + std::string hashId = GetHashDeleteSyncDeviceId(deviceId, isNeedHash); DeleteWaterMark deleteWaterMark; // lock prevent different thread visit deleteSyncCache_ std::lock_guard autoLock(deleteSyncLock_); @@ -398,12 +399,13 @@ int QuerySyncWaterMarkHelper::SaveDeleteWaterMarkToDB(const DeviceID &hashDevice return errCode; } -DeviceID QuerySyncWaterMarkHelper::GetHashDeleteSyncDeviceId(const DeviceID &deviceId) +DeviceID QuerySyncWaterMarkHelper::GetHashDeleteSyncDeviceId(const DeviceID &deviceId, bool isNeedHash) { DeviceID hashDeleteSyncId; std::lock_guard autoLock(deleteSyncLock_); if (deviceIdToHashDeleteSyncIdMap_.count(deviceId) == 0) { - hashDeleteSyncId = DBConstant::DELETE_SYNC_PREFIX_KEY + DBCommon::TransferHashString(deviceId); + hashDeleteSyncId = DBConstant::DELETE_SYNC_PREFIX_KEY + + (isNeedHash ? DBCommon::TransferHashString(deviceId) : deviceId); deviceIdToHashDeleteSyncIdMap_.insert(std::pair(deviceId, hashDeleteSyncId)); } else { hashDeleteSyncId = deviceIdToHashDeleteSyncIdMap_[deviceId]; @@ -508,11 +510,13 @@ int QuerySyncWaterMarkHelper::RemoveLeastUsedQuerySyncItems(const std::vector autoLock(queryWaterMarkLock_); - std::string prefixKeyStr = DBConstant::QUERY_SYNC_PREFIX_KEY + DBCommon::TransferHashString(deviceId); + std::string prefixKeyStr = DBConstant::QUERY_SYNC_PREFIX_KEY + + (isNeedHash ? DBCommon::TransferHashString(deviceId) : deviceId); if (!tableName.empty()) { std::string hashTableName = DBCommon::TransferHashString(tableName); std::string hexTableName = DBCommon::TransferStringToHex(hashTableName); diff --git a/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.h b/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.h index ab36f91eee88503a00ad43d30bc4c6488ce85e69..bb76a50319155f89453f18e96c30558b401791e5 100644 --- a/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.h +++ b/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.h @@ -66,7 +66,7 @@ public: int SetSendDeleteSyncWaterMark(const std::string &deviceId, const WaterMark &waterMark); - int SetRecvDeleteSyncWaterMark(const std::string &deviceId, const WaterMark &waterMark); + int SetRecvDeleteSyncWaterMark(const std::string &deviceId, const WaterMark &waterMark, bool isNeedHash); // this function will read deleteWaterMark from db by it's deleteWaterMarkKey // and then serialize it and put to cache @@ -76,7 +76,7 @@ public: int RemoveLeastUsedQuerySyncItems(const std::vector &querySyncIds); // reset the waterMark to zero - int ResetRecvQueryWaterMark(const DeviceID &deviceId, const std::string &tableName); + int ResetRecvQueryWaterMark(const DeviceID &deviceId, const std::string &tableName, bool isNeedHash); static std::string GetQuerySyncPrefixKey(); @@ -118,7 +118,7 @@ private: // get the deleteSync hashId in cache_ or generate one and then put it in to cache_ // the hashId is made up of "DELETE_SYNC_PREFIX_KEY" + hash(deviceId) - DeviceID GetHashDeleteSyncDeviceId(const DeviceID &deviceId); + DeviceID GetHashDeleteSyncDeviceId(const DeviceID &deviceId, bool isNeedHash = true); int SaveDeleteWaterMarkToDB(const DeviceID &hashDeviceId, const DeleteWaterMark &deleteWaterMark); diff --git a/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp b/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp index aedf9d19f3160cfb459173b77c213634c31dc3e0..36fe8f5630941bda2f179ae4864aab8c2294e2a2 100644 --- a/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp +++ b/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp @@ -202,18 +202,18 @@ void RemoteExecutor::ParseOneRequestMessage(const std::string &device, Message * LOGW("[RemoteExecutor][ParseOneRequestMessage] closed"); return; } - int errCode = CheckPermissions(device); + int errCode = CheckPermissions(device, inMsg); if (errCode != E_OK) { - ResponseFailed(errCode, inMsg->GetSessionId(), inMsg->GetSequenceId(), device); + (void)ResponseFailed(errCode, inMsg->GetSessionId(), inMsg->GetSequenceId(), device); return; } errCode = SendRemoteExecutorData(device, inMsg); if (errCode != E_OK) { - ResponseFailed(errCode, inMsg->GetSessionId(), inMsg->GetSequenceId(), device); + (void)ResponseFailed(errCode, inMsg->GetSessionId(), inMsg->GetSequenceId(), device); } } -int RemoteExecutor::CheckPermissions(const std::string &device) +int RemoteExecutor::CheckPermissions(const std::string &device, Message *inMsg) { SyncGenericInterface *storage = static_cast(GetAndIncSyncInterface()); if (storage == nullptr) { @@ -229,7 +229,16 @@ int RemoteExecutor::CheckPermissions(const std::string &device) { userId, appId, storeId, device, instanceId }, CHECK_FLAG_SEND); if (errCode != E_OK) { LOGE("[RemoteExecutor][CheckPermissions] check permission errCode = %d.", errCode); + storage->DecRefCount(); + return errCode; + } + const auto *requestPacket = inMsg->GetObject(); + if (requestPacket == nullptr) { + LOGE("[RemoteExecutor] get packet object failed"); + storage->DecRefCount(); + return -E_INVALID_ARGS; } + errCode = CheckRemoteRecvData(device, storage, requestPacket->GetSecLabel()); storage->DecRefCount(); return errCode; } @@ -507,17 +516,17 @@ int RemoteExecutor::RequestStart(uint32_t sessionId) return errCode; } -void RemoteExecutor::ResponseFailed(int errCode, uint32_t sessionId, uint32_t sequenceId, +int RemoteExecutor::ResponseFailed(int errCode, uint32_t sessionId, uint32_t sequenceId, const std::string &device) { RemoteExecutorAckPacket *packet = new (std::nothrow) RemoteExecutorAckPacket(); if (packet == nullptr) { LOGE("[RemoteExecutor][ResponseFailed] new RemoteExecutorAckPacket error"); - return; + return -E_OUT_OF_MEMORY; } packet->SetAckCode(errCode); packet->SetLastAck(); - (void)ResponseStart(packet, sessionId, sequenceId, device); + return ResponseStart(packet, sessionId, sequenceId, device); } int RemoteExecutor::ResponseData(RelationalRowDataSet &&dataSet, const SendMessage &sendMessage, @@ -712,6 +721,17 @@ void RemoteExecutor::ClearInnerSource() int RemoteExecutor::FillRequestPacket(RemoteExecutorRequestPacket *packet, uint32_t sessionId, std::string &target) { + ISyncInterface *storage = GetAndIncSyncInterface(); + if (storage == nullptr) { + return -E_BUSY; + } + SecurityOption localOption; + int errCode = storage->GetSecurityOption(localOption); + storage->DecRefCount(); + storage = nullptr; + if (errCode != E_OK && errCode != -E_NOT_SUPPORT) { + return -E_SECURITY_OPTION_CHECK_ERROR; + } Task task; { std::lock_guard autoLock(taskLock_); @@ -726,6 +746,7 @@ int RemoteExecutor::FillRequestPacket(RemoteExecutorRequestPacket *packet, uint3 packet->SetSql(task.condition.sql); packet->SetBindArgs(task.condition.bindArgs); packet->SetNeedResponse(); + packet->SetSecLabel(errCode == E_NOT_SUPPORT ? NOT_SURPPORT_SEC_CLASSIFICATION : localOption.securityLabel); target = task.target; return E_OK; } @@ -944,7 +965,7 @@ int RemoteExecutor::CheckSecurityOption(ISyncInterface *storage, ICommunicator * std::string device; communicator->GetLocalIdentity(device); SecurityOption localOption; - int errCode = static_cast(storage)->GetSecurityOption(localOption); + int errCode = storage->GetSecurityOption(localOption); if (errCode != E_OK && errCode != -E_NOT_SUPPORT) { return -E_SECURITY_OPTION_CHECK_ERROR; } @@ -958,4 +979,24 @@ int RemoteExecutor::CheckSecurityOption(ISyncInterface *storage, ICommunicator * } return errCode; } + +int RemoteExecutor::CheckRemoteRecvData(const std::string &device, SyncGenericInterface *storage, + int32_t remoteSecLabel) +{ + SecurityOption localOption; + int errCode = storage->GetSecurityOption(localOption); + if (errCode == -E_NOT_SUPPORT) { + return E_OK; + } + if (errCode != E_OK) { + return -E_SECURITY_OPTION_CHECK_ERROR; + } + if (remoteSecLabel == UNKNOWN_SECURITY_LABEL || remoteSecLabel == NOT_SURPPORT_SEC_CLASSIFICATION) { + return E_OK; + } + if (RuntimeContext::GetInstance()->CheckDeviceSecurityAbility(device, localOption)) { + return E_OK; + } + return -E_SECURITY_OPTION_CHECK_ERROR; +} } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/syncer/src/remote_executor.h b/frameworks/libs/distributeddb/syncer/src/remote_executor.h index 68a878d5c7b2331fe1c9d3925d777377e75b4654..8c369574be2b33cdedd28b46a889ce8587854b71 100644 --- a/frameworks/libs/distributeddb/syncer/src/remote_executor.h +++ b/frameworks/libs/distributeddb/syncer/src/remote_executor.h @@ -77,7 +77,7 @@ protected: virtual bool IsPacketValid(uint32_t sessionId); - void ResponseFailed(int errCode, uint32_t sessionId, uint32_t sequenceId, const std::string &device); + int ResponseFailed(int errCode, uint32_t sessionId, uint32_t sequenceId, const std::string &device); private: struct SendMessage { @@ -93,7 +93,7 @@ private: int ReceiveRemoteExecutorAck(const std::string &targetDev, Message *inMsg); - int CheckPermissions(const std::string &device); + int CheckPermissions(const std::string &device, Message *inMsg); int SendRemoteExecutorData(const std::string &device, const Message *inMsg); @@ -143,6 +143,7 @@ private: ICommunicator *GetAndIncCommunicator() const; ISyncInterface *GetAndIncSyncInterface() const; + static int CheckRemoteRecvData(const std::string &device, SyncGenericInterface *storage, int32_t remoteSecLabel); std::mutex taskLock_; std::map> searchTaskQueue_; // key is device, value is sessionId queue diff --git a/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp b/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp index 5c0360a5d76cc1998557d9eb3a5fadcb0659b2fe..999bb0a4722b82e8865180224ece6d3502c9b5b6 100644 --- a/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp +++ b/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp @@ -95,6 +95,7 @@ uint32_t RemoteExecutorRequestPacket::CalculateLen() const } } len = Parcel::GetEightByteAlign(len); // 8-byte align + len += Parcel::GetIntLen(); return len; } @@ -120,6 +121,7 @@ int RemoteExecutorRequestPacket::Serialization(Parcel &parcel) const parcel.WriteString(entry.second); } parcel.EightByteAlign(); + parcel.WriteInt(secLabel_); if (parcel.IsError()) { return -E_PARSE_FAIL; } @@ -155,6 +157,9 @@ int RemoteExecutorRequestPacket::DeSerialization(Parcel &parcel) extraConditions_[conditionKey] = conditionVal; } parcel.EightByteAlign(); + if (version_ >= REQUEST_PACKET_VERSION_V3) { + parcel.ReadInt(secLabel_); + } if (parcel.IsError()) { return -E_PARSE_FAIL; } @@ -176,6 +181,16 @@ void RemoteExecutorRequestPacket::SetBindArgs(const std::vector &bi preparedStmt_.SetBindArgs(bindArgs); } +void RemoteExecutorRequestPacket::SetSecLabel(int32_t secLabel) +{ + secLabel_ = secLabel; +} + +int32_t RemoteExecutorRequestPacket::GetSecLabel() const +{ + return secLabel_; +} + RemoteExecutorRequestPacket* RemoteExecutorRequestPacket::Create() { return new (std::nothrow) RemoteExecutorRequestPacket(); diff --git a/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.h b/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.h index d5549709f3a9bede0f0b4d1ecc8d8132af7ec991..5d25262cc296757adb0a383bfe59a15f9bbebae4 100644 --- a/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.h +++ b/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.h @@ -59,18 +59,24 @@ public: void SetBindArgs(const std::vector &bindArgs); + void SetSecLabel(int32_t secLabel); + + int32_t GetSecLabel() const; + static RemoteExecutorRequestPacket* Create(); static void Release(RemoteExecutorRequestPacket *&packet); static const uint32_t REQUEST_PACKET_VERSION_V1 = SOFTWARE_VERSION_RELEASE_6_0; static const uint32_t REQUEST_PACKET_VERSION_V2 = SOFTWARE_VERSION_RELEASE_6_0 + 1; - static const uint32_t REQUEST_PACKET_VERSION_CURRENT = REQUEST_PACKET_VERSION_V2; + static const uint32_t REQUEST_PACKET_VERSION_V3 = SOFTWARE_VERSION_RELEASE_6_0 + 2; + static const uint32_t REQUEST_PACKET_VERSION_CURRENT = REQUEST_PACKET_VERSION_V3; private: uint32_t version_ = 0u; uint32_t flag_ = 0u; // 0x01 mean need reply ack PreparedStmt preparedStmt_; std::map extraConditions_; + int32_t secLabel_ = UNKNOWN_SECURITY_LABEL; // source sec label }; class RemoteExecutorAckPacket : public ISyncPacket { diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp index c940626a2835237c710bff29b11745130f1b1fd2..5077c233a26a1564d00d2dfd599af27fa0ced0c2 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp @@ -51,11 +51,6 @@ bool SingleVerDataMessageSchedule::IsNeedReloadQueue() Message *SingleVerDataMessageSchedule::MoveNextMsg(SingleVerSyncTaskContext *context, bool &isNeedHandle, bool &isNeedContinue) { - uint32_t remoteVersion = context->GetRemoteSoftwareVersion(); - if (remoteVersion < SOFTWARE_VERSION_RELEASE_3_0) { - // just get last msg when remote version is < 103 or >=103 but just open db now - return GetLastMsgFromQueue(); - } { std::lock_guard lock(workingLock_); if (isWorking_) { @@ -64,6 +59,11 @@ Message *SingleVerDataMessageSchedule::MoveNextMsg(SingleVerSyncTaskContext *con } isWorking_ = true; } + uint32_t remoteVersion = context->GetRemoteSoftwareVersion(); + if (remoteVersion < SOFTWARE_VERSION_RELEASE_3_0) { + // just get last msg when remote version is < 103 or >=103 but just open db now + return GetLastMsgFromQueue(); + } ResetTimer(context); UpdateMsgMap(); Message *msg = GetMsgFromMap(isNeedHandle); diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp index f2ee817c191e0362457250e61433dbc37ddea5ff..5301e977628e74488fa7c0003de3535f5caa926a 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp @@ -66,13 +66,16 @@ int SingleVerDataSync::Initialize(ISyncInterface *inStorage, ICommunicator *inCo int SingleVerDataSync::SyncStart(int mode, SingleVerSyncTaskContext *context) { std::lock_guard lock(lock_); + int errCode = CheckPermitSendData(mode, context); + if (errCode != E_OK) { + return errCode; + } if (sessionId_ != 0) { // auto sync timeout resend return ReSendData(context); } ResetSyncStatus(mode, context); LOGI("[DataSync] SendStart,mode=%d,label=%s,device=%s", mode_, label_.c_str(), STR_MASK(deviceId_)); int tmpMode = SyncOperation::TransferSyncMode(mode); - int errCode = E_OK; if (tmpMode == SyncModeType::PUSH) { errCode = PushStart(context); } else if (tmpMode == SyncModeType::PUSH_AND_PULL) { @@ -100,6 +103,10 @@ int SingleVerDataSync::SyncStart(int mode, SingleVerSyncTaskContext *context) int SingleVerDataSync::InnerSyncStart(SingleVerSyncTaskContext *context) { + int errCode = CheckPermitSendData(mode_, context); + if (errCode != E_OK) { + return errCode; + } while (true) { if (windowSize_ <= 0 || isAllDataHasSent_) { LOGD("[DataSync] InnerDataSync winSize=%d,isAllSent=%d,label=%s,device=%s", windowSize_, isAllDataHasSent_, @@ -111,7 +118,6 @@ int SingleVerDataSync::InnerSyncStart(SingleVerSyncTaskContext *context) LOGE("[DataSync] unexpected error"); return -E_INVALID_ARGS; } - int errCode; context->IncSequenceId(); if (mode == SyncModeType::PUSH || mode == SyncModeType::PUSH_AND_PULL) { errCode = PushStart(context); @@ -395,6 +401,19 @@ int SingleVerDataSync::SaveData(const SingleVerSyncTaskContext *context, const s if (inData.empty()) { return E_OK; } + StoreInfo info = { + storage_->GetDbProperties().GetStringProp(DBProperties::USER_ID, ""), + storage_->GetDbProperties().GetStringProp(DBProperties::APP_ID, ""), + storage_->GetDbProperties().GetStringProp(DBProperties::STORE_ID, "") + }; + std::string clientId; + int errCode = E_OK; + if (RuntimeContext::GetInstance()->TranslateDeviceId(context->GetDeviceId(), info, clientId) == E_OK) { + errCode = metadata_->SaveClientId(context->GetDeviceId(), clientId); + if (errCode != E_OK) { + LOGW("[DataSync] record clientId failed %d", errCode); + } + } PerformanceAnalysis *performance = PerformanceAnalysis::GetInstance(); if (performance != nullptr) { performance->StepTimeRecordStart(PT_TEST_RECORDS::RECORD_SAVE_DATA); @@ -402,7 +421,6 @@ int SingleVerDataSync::SaveData(const SingleVerSyncTaskContext *context, const s const std::string localHashName = DBCommon::TransferHashString(GetLocalDeviceName()); SingleVerDataSyncUtils::TransSendDataItemToLocal(context, localHashName, inData); - int errCode = E_OK; // query only support prefix key and don't have query in packet in 104 version errCode = storage_->PutSyncDataWithQuery(query, inData, context->GetDeviceId()); if (performance != nullptr) { @@ -979,6 +997,7 @@ int SingleVerDataSync::DataRequestRecv(SingleVerSyncTaskContext *context, const if (errCode != E_OK) { return errCode; } + Metadata::MetaWaterMarkAutoLock autoLock(metadata_); if (WaterMarkErrHandle(curType, context, message)) { return E_OK; } diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp index 0667fccbb11984fadaa9b68345a1f533c0c577e0..095781144c698975a644ea444ec07c407716c719 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp @@ -158,7 +158,6 @@ void SingleVerDataSyncUtils::TransSendDataItemToLocal(const SingleVerSyncTaskCon const std::string &localHashName, const std::vector &data) { TimeOffset offset = context->GetTimeOffset(); - Timestamp currentLocalTime = context->GetCurrentLocalTime(); for (auto &item : data) { if (item == nullptr) { continue; @@ -171,6 +170,7 @@ void SingleVerDataSyncUtils::TransSendDataItemToLocal(const SingleVerSyncTaskCon item->SetWriteTimestamp(tempWriteTimestamp - static_cast(offset)); } + Timestamp currentLocalTime = context->GetCurrentLocalTime(); if (item->GetTimestamp() > currentLocalTime) { item->SetTimestamp(currentLocalTime); } diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp index c5fd92349d0b5c6e25b335216eb1fc31fa17290f..e7541fb568fe5deb19a4f0ddf3821b1670c94e70 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp @@ -239,6 +239,17 @@ void SingleVerKVSyncer::TriggerSubQuerySync(const std::vector &devi LOGE("[Syncer] Syncer has not Init"); return; } + std::shared_ptr metadata = nullptr; + ISyncInterface *syncInterface = nullptr; + { + std::lock_guard lock(syncerLock_); + if (metadata_ == nullptr || syncInterface_ == nullptr) { + return; + } + metadata = metadata_; + syncInterface = syncInterface_; + syncInterface->IncRefCount(); + } int errCode; for (auto &device : devices) { std::vector queries; @@ -246,15 +257,8 @@ void SingleVerKVSyncer::TriggerSubQuerySync(const std::vector &devi for (auto &query : queries) { std::string queryId = query.GetIdentify(); WaterMark queryWaterMark = 0; - uint64_t lastTimestamp = 0; - { - std::lock_guard lock(syncerLock_); - if (metadata_ == nullptr) { - return; - } - lastTimestamp = metadata_->GetQueryLastTimestamp(device, queryId); - errCode = metadata_->GetSendQueryWaterMark(queryId, device, queryWaterMark, false); - } + uint64_t lastTimestamp = metadata->GetQueryLastTimestamp(device, queryId); + errCode = metadata->GetSendQueryWaterMark(queryId, device, queryWaterMark, false); if (errCode != E_OK) { LOGE("[Syncer] get queryId=%s,dev=%s watermark failed", STR_MASK(queryId), STR_MASK(device)); continue; @@ -274,6 +278,7 @@ void SingleVerKVSyncer::TriggerSubQuerySync(const std::vector &devi QueryAutoSync(param); } } + syncInterface->DecRefCount(); } SyncerBasicInfo SingleVerKVSyncer::DumpSyncerBasicInfo() diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp index f51fa6edc37be16f3c6851bb426c25656da13ebe..efc27dd01a6c7f0646cb1eb8e0850ea47467b486 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp @@ -796,6 +796,7 @@ void SingleVerSyncStateMachine::ScheduleMsgAndHandle(Message *inMsg) if (dataSync_->IsNeedReloadQueue()) { continue; } + dataSync_->ScheduleInfoHandle(false, false, nullptr); break; } bool isNeedClearMap = false; @@ -1112,6 +1113,9 @@ void SingleVerSyncStateMachine::DataRecvErrCodeHandle(uint32_t sessionId, int er switch (errCode) { case E_OK: break; + case -E_NOT_PERMIT: + context_->SetOperationStatus(SyncOperation::OP_PERMISSION_CHECK_FAILED); + break; case -E_RECV_FINISHED: context_->SetOperationStatus(SyncOperation::OP_RECV_FINISHED); SwitchStateAndStep(Event::RECV_FINISHED_EVENT); diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp index aa753b1d753a64a767a0f473df26abc2a7da0aac..49bc519074ed79a6ee816d2f22a80f467da3279e 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp @@ -324,11 +324,13 @@ void SingleVerSyncTaskContext::SetReceiveWaterMarkErr(bool isErr) void SingleVerSyncTaskContext::SetRemoteSeccurityOption(SecurityOption secOption) { + std::lock_guard autoLock(securityOptionMutex_); remoteSecOption_ = secOption; } SecurityOption SingleVerSyncTaskContext::GetRemoteSeccurityOption() const { + std::lock_guard autoLock(securityOptionMutex_); return remoteSecOption_; } diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.h b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.h index 19145a8baf08a58aacadcc26209977bf714845d3..d4500b71f7406442e9cbbe85ce0b9d117a4be4ba 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.h +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.h @@ -158,6 +158,7 @@ private: volatile uint32_t responseSessionId_ = 0; bool needClearRemoteStaleData_; + mutable std::mutex securityOptionMutex_; SecurityOption remoteSecOption_ = {0, 0}; // remote targe can handle secOption data or not. volatile bool isReceivcPermitChecked_ = false; volatile bool isSendPermitChecked_ = false; diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp index fd754fb4a96fbd4a5b91eff47500d90f205c532c..2016f6375334e10d8cb5bb2f060d2b51e600d68c 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp @@ -56,11 +56,20 @@ int SingleVerSyncer::EraseDeviceWaterMark(const std::string &deviceId, bool isNe int SingleVerSyncer::EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash, const std::string &tableName) { - std::lock_guard lock(syncerLock_); - if (metadata_ == nullptr) { - return -E_NOT_INIT; + std::shared_ptr metadata; + ISyncInterface *storage = nullptr; + { + std::lock_guard lock(syncerLock_); + if (metadata_ == nullptr || syncInterface_ == nullptr) { + return -E_NOT_INIT; + } + metadata = metadata_; + storage = syncInterface_; + storage->IncRefCount(); } - return metadata_->EraseDeviceWaterMark(deviceId, isNeedHash, tableName); + int errCode = metadata->EraseDeviceWaterMark(deviceId, isNeedHash, tableName); + storage->DecRefCount(); + return errCode; } int SingleVerSyncer::SetStaleDataWipePolicy(WipePolicy policy) @@ -92,4 +101,17 @@ ISyncEngine *SingleVerSyncer::CreateSyncEngine() { return new (std::nothrow) SingleVerSyncEngine(); } + +int SingleVerSyncer::GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const +{ + std::shared_ptr metadata = nullptr; + { + std::lock_guard lock(syncerLock_); + if (metadata_ == nullptr) { + return -E_NOT_INIT; + } + metadata = metadata_; + } + return metadata->GetHashDeviceId(clientId, hashDevId); +} } diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.h b/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.h index 9dc5e0e1781185a7d96d9bedab6d5c8c7012d3b9..825607041a41c4695e3a4ad2392ebbc67c29603b 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.h +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.h @@ -34,6 +34,7 @@ public: int EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash, const std::string &tableName) override; + int GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const override; protected: // Create a sync engine, if has memory error, will return nullptr. ISyncEngine *CreateSyncEngine() override; diff --git a/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp b/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp index 61733a69c15e2de2de17ac3306ec14baa60cbdb4..938fcacf9ed05efd4d45ea96a20966c42f1b0f4a 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp @@ -661,36 +661,39 @@ int SyncEngine::ExecSyncTask(ISyncTaskContext *context) if (IsKilled()) { return -E_OBJ_IS_KILLED; } - AutoLock lockGuard(context); int status = context->GetTaskExecStatus(); if ((status == SyncTaskContext::RUNNING) || context->IsKilled()) { return -E_NOT_SUPPORT; } context->SetTaskExecStatus(ISyncTaskContext::RUNNING); - if (!context->IsTargetQueueEmpty()) { - int errCode = context->GetNextTarget(true); + while (!context->IsTargetQueueEmpty()) { + int errCode = context->GetNextTarget(); if (errCode != E_OK) { - return errCode; + // current task execute failed, try next task + context->ClearSyncOperation(); + continue; } if (context->IsCurrentSyncTaskCanBeSkipped()) { context->SetOperationStatus(SyncOperation::OP_FINISHED_ALL); context->ClearSyncOperation(); - context->SetTaskExecStatus(ISyncTaskContext::FINISHED); - return E_OK; + continue; } context->UnlockObj(); errCode = context->StartStateMachine(); context->LockObj(); if (errCode != E_OK) { - LOGE("[SyncEngine] machine StartSync failed"); + // machine start failed because timer start failed, try to execute next task + LOGW("[SyncEngine] machine StartSync failed"); context->SetOperationStatus(SyncOperation::OP_FAILED); - return errCode; + context->ClearSyncOperation(); + continue; } - } else { - LOGD("[SyncEngine] ExecSyncTask finished"); - context->SetTaskExecStatus(ISyncTaskContext::FINISHED); + // now task is running just return here + return errCode; } + LOGD("[SyncEngine] ExecSyncTask finished"); + context->SetTaskExecStatus(ISyncTaskContext::FINISHED); return E_OK; } diff --git a/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp b/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp index 9115edd0e41144d4900a67f66f0486ebe10a19f2..374ce91535375d01188aaa578da5a90eca972d32 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp @@ -174,18 +174,21 @@ int SyncStateMachine::ExecNextTask() { syncContext_->Clear(); while (!syncContext_->IsTargetQueueEmpty()) { - int errCode = syncContext_->GetNextTarget(false); + int errCode = syncContext_->GetNextTarget(); if (errCode != E_OK) { continue; } if (syncContext_->IsCurrentSyncTaskCanBeSkipped()) { syncContext_->SetOperationStatus(SyncOperation::OP_FINISHED_ALL); + syncContext_->Clear(); continue; } errCode = PrepareNextSyncTask(); if (errCode != E_OK) { LOGE("[SyncStateMachine] PrepareSync failed"); syncContext_->SetOperationStatus(SyncOperation::OP_FAILED); + syncContext_->Clear(); + continue; // try to execute next task } return errCode; } diff --git a/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp b/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp index 97499394e7f1e68ab4ae5af16e657259f3d881d2..d9b0c6eab0524d9ee8ca7724b40ceb42ea9cced7 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp +++ b/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp @@ -89,13 +89,18 @@ int SyncTaskContext::AddSyncTarget(ISyncTarget *target) return -E_INVALID_ARGS; } } - CancelCurrentSyncRetryIfNeed(targetMode); - if (taskExecStatus_ == RUNNING) { - return E_OK; + RefObject::IncObjRef(this); + auto syncId = static_cast(target->GetSyncId()); + int errCode = RuntimeContext::GetInstance()->ScheduleTask([this, targetMode, syncId]() { + CancelCurrentSyncRetryIfNeed(targetMode, syncId); + RefObject::DecObjRef(this); + }); + if (errCode != E_OK) { + RefObject::DecObjRef(this); } if (onSyncTaskAdd_) { RefObject::IncObjRef(this); - int errCode = RuntimeContext::GetInstance()->ScheduleTask([this]() { + errCode = RuntimeContext::GetInstance()->ScheduleTask([this]() { onSyncTaskAdd_(); RefObject::DecObjRef(this); }); @@ -260,15 +265,12 @@ void SyncTaskContext::MoveToNextTarget() } } -int SyncTaskContext::GetNextTarget(bool isNeedSetFinished) +int SyncTaskContext::GetNextTarget() { MoveToNextTarget(); int checkErrCode = RunPermissionCheck(GetPermissionCheckFlag(IsAutoSync(), GetMode())); if (checkErrCode != E_OK) { SetOperationStatus(SyncOperation::OP_PERMISSION_CHECK_FAILED); - if (isNeedSetFinished) { - SetTaskExecStatus(ISyncTaskContext::FINISHED); - } return checkErrCode; } return E_OK; @@ -540,22 +542,13 @@ int SyncTaskContext::TimeOut(TimerId id) if (!timeOutCallback_) { return E_OK; } - int errCode = IncUsedCount(); - if (errCode != E_OK) { - LOGW("[SyncTaskContext][TimeOut] IncUsedCount failed! errCode=", errCode); - // if return is not E_OK, the timer will be removed - // we removed timer when context call StopTimer - return E_OK; - } IncObjRef(this); - errCode = RuntimeContext::GetInstance()->ScheduleTask([this, id]() { + int errCode = RuntimeContext::GetInstance()->ScheduleTask([this, id]() { timeOutCallback_(id); - SafeExit(); DecObjRef(this); }); if (errCode != E_OK) { LOGW("[SyncTaskContext][TimeOut] Trigger TimeOut Async Failed! TimerId=" PRIu64 " errCode=%d", id, errCode); - SafeExit(); DecObjRef(this); } return E_OK; @@ -598,8 +591,8 @@ void SyncTaskContext::CopyTargetData(const ISyncTarget *target, const TaskParam void SyncTaskContext::KillWait() { StopTimer(); - stateMachine_->NotifyClosing(); UnlockObj(); + stateMachine_->NotifyClosing(); stateMachine_->AbortImmediately(); LockObj(); LOGW("[SyncTaskContext] Try to kill a context, now wait."); @@ -631,12 +624,15 @@ void SyncTaskContext::ClearSyncOperation() } } -void SyncTaskContext::CancelCurrentSyncRetryIfNeed(int newTargetMode) +void SyncTaskContext::CancelCurrentSyncRetryIfNeed(int newTargetMode, uint32_t syncId) { AutoLock lock(this); if (!isAutoSync_) { return; } + if (syncId_ >= syncId) { + return; + } int mode = SyncOperation::TransferSyncMode(newTargetMode); if (newTargetMode == mode_ || mode == SyncModeType::PUSH_AND_PULL) { SetRetryTime(AUTO_RETRY_TIMES); diff --git a/frameworks/libs/distributeddb/syncer/src/sync_task_context.h b/frameworks/libs/distributeddb/syncer/src/sync_task_context.h index 1eb06538c2aaf55550a184329505fd3d12ca47e6..983015614705fc52db2dcd99102cf64f6651a854 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_task_context.h +++ b/frameworks/libs/distributeddb/syncer/src/sync_task_context.h @@ -70,7 +70,7 @@ public: // Move to next target to sync void MoveToNextTarget() override; - int GetNextTarget(bool isNeedSetFinished) override; + int GetNextTarget() override; // Get the current task syncId uint32_t GetSyncId() const override; @@ -227,7 +227,7 @@ protected: void ClearSyncTarget(); - void CancelCurrentSyncRetryIfNeed(int newTargetMode); + void CancelCurrentSyncRetryIfNeed(int newTargetMode, uint32_t syncId); virtual void SaveLastPushTaskExecStatus(int finalStatus); diff --git a/frameworks/libs/distributeddb/syncer/src/sync_types.h b/frameworks/libs/distributeddb/syncer/src/sync_types.h index 29253e548b9870a60b3fbc7791710c3f382692ac..26323c90a13df63178e51ebd56b015d672e8c78d 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_types.h +++ b/frameworks/libs/distributeddb/syncer/src/sync_types.h @@ -76,6 +76,7 @@ struct InternalSyncParma { QuerySyncObject syncQuery; }; +constexpr int32_t UNKNOWN_SECURITY_LABEL = -1; constexpr int NOT_SURPPORT_SEC_CLASSIFICATION = 0xff; constexpr uint8_t QUERY_SYNC_MODE_BASE = SyncModeType::QUERY_PUSH; constexpr int AUTO_RETRY_TIMES = 3; diff --git a/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp b/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp index 324b4ea05cd667597ffed9046e84b04b3813175a..e66d1b277e655316e7bda73c7340da57f3b58363 100644 --- a/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp +++ b/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp @@ -231,4 +231,12 @@ int SyncerProxy::GetSyncDataSize(const std::string &device, size_t &size) const } return syncer_->GetSyncDataSize(device, size); } + +int SyncerProxy::GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const +{ + if (syncer_ == nullptr) { + return -E_NOT_INIT; + } + return syncer_->GetHashDeviceId(clientId, hashDevId); +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/test/BUILD.gn b/frameworks/libs/distributeddb/test/BUILD.gn index e812b2ab872641a43170de886020b26f06a20a64..4edcc5c5f69c8c65da75dd7508f85ddba023116a 100644 --- a/frameworks/libs/distributeddb/test/BUILD.gn +++ b/frameworks/libs/distributeddb/test/BUILD.gn @@ -184,6 +184,7 @@ ohos_source_set("src_file") { "../storage/src/relationaldb_properties.cpp", "../storage/src/result_entries_window.cpp", "../storage/src/single_ver_natural_store_commit_notify_data.cpp", + "../storage/src/sqlite/cloud_sync_log_table_manager.cpp", "../storage/src/sqlite/collaboration_log_table_manager.cpp", "../storage/src/sqlite/log_table_manager_factory.cpp", "../storage/src/sqlite/query_object.cpp", @@ -201,6 +202,7 @@ ohos_source_set("src_file") { "../storage/src/sqlite/sqlite_local_storage_engine.cpp", "../storage/src/sqlite/sqlite_local_storage_executor.cpp", "../storage/src/sqlite/sqlite_log_table_manager.cpp", + "../storage/src/sqlite/sqlite_meta_executor.cpp", "../storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", "../storage/src/sqlite/sqlite_multi_ver_transaction.cpp", "../storage/src/sqlite/sqlite_query_helper.cpp", @@ -229,6 +231,10 @@ ohos_source_set("src_file") { "../storage/src/upgrader/single_ver_database_upgrader.cpp", "../storage/src/upgrader/single_ver_schema_database_upgrader.cpp", "../syncer/src/ability_sync.cpp", + "../syncer/src/cloud/cloud_merge_strategy.cpp", + "../syncer/src/cloud/cloud_db_proxy.cpp", + "../syncer/src/cloud/cloud_syncer.cpp", + "../syncer/src/cloud/strategy_factory.cpp", "../syncer/src/commit_history_sync.cpp", "../syncer/src/communicator_proxy.cpp", "../syncer/src/db_ability.cpp", @@ -273,7 +279,9 @@ ohos_source_set("src_file") { "unittest/common/common/distributeddb_tools_unit_test.cpp", "unittest/common/common/native_sqlite.cpp", "unittest/common/common/system_timer.cpp", + "unittest/common/common/thread_pool_test_stub.cpp", "unittest/common/interfaces/process_system_api_adapter_impl.cpp", + "unittest/common/syncer/cloud/virtual_cloud_db.cpp", "unittest/common/syncer/generic_virtual_device.cpp", "unittest/common/syncer/kv_virtual_device.cpp", "unittest/common/syncer/relational_virtual_device.cpp", @@ -366,6 +374,10 @@ distributeddb_unittest("DistributedDBInterfacesImportAndExportTest") { sources = [ "unittest/common/interfaces/distributeddb_interfaces_import_and_export_test.cpp" ] } +distributeddb_unittest("DistributedDBStorageSaveCloudDataTest") { + sources = [ "unittest/common/storage/cloud/distributeddb_save_cloud_data_test.cpp" ] +} + distributeddb_unittest("DistributedDBStorageDataOperationTest") { sources = [ "unittest/common/storage/distributeddb_storage_data_operation_test.cpp", @@ -451,6 +463,10 @@ distributeddb_unittest("DistributedDBInterfacesNBDelegateTest") { ] } +distributeddb_unittest("DistributedDBInterfacesRelationalExtTest") { + sources = [ "unittest/common/interfaces/distributeddb_interfaces_relational_ext_test.cpp" ] +} + distributeddb_unittest("DistributedDBCommonTest") { sources = [ "unittest/common/common/distributeddb_common_test.cpp" ] } @@ -572,6 +588,10 @@ distributeddb_unittest("DistributedDBTimeSyncTest") { ] } +distributeddb_unittest("DistributedDBThreadPoolTest") { + sources = [ "unittest/common/common/distributeddb_thread_pool_test.cpp" ] +} + distributeddb_unittest("DistributedDBDeviceIdentifierTest") { sources = [ "unittest/common/interfaces/distributeddb_interfaces_device_identifier_test.cpp" ] } @@ -766,6 +786,10 @@ distributeddb_unittest("DistributedDBRelationalSyncableStorageTest") { sources = [ "unittest/common/storage/distributeddb_relational_syncable_storage_test.cpp" ] } +distributeddb_unittest("DistributedDBRelationalCloudSyncableStorageTest") { + sources = [ "unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp" ] +} + distributeddb_unittest("DistributedDBSqliteUtilsTest") { sources = [ "unittest/common/storage/distributeddb_sqlite_utils_test.cpp" ] } @@ -818,6 +842,7 @@ group("unittest") { ":DistributedDBMultiVerVacuumTest", ":DistributedDBNotificationChainTest", ":DistributedDBParcelTest", + ":DistributedDBRelationalCloudSyncableStorageTest", ":DistributedDBRelationalEncryptedDbTest", ":DistributedDBRelationalGetDataTest", ":DistributedDBRelationalRemoteQueryTest", @@ -848,6 +873,7 @@ group("unittest") { ":DistributedDBStorageRegisterConflictTest", ":DistributedDBStorageRegisterObserverTest", ":DistributedDBStorageResultAndJsonOptimizeTest", + ":DistributedDBStorageSaveCloudDataTest", ":DistributedDBStorageSQLiteSingleVerNaturalExecutorTest", ":DistributedDBStorageSQLiteSingleVerNaturalStoreTest", ":DistributedDBStorageSQLiteSingleVerStorageEngineTest", @@ -855,6 +881,7 @@ group("unittest") { ":DistributedDBStorageTransactionDataTest", ":DistributedDBStorageTransactionRecordTest", ":DistributedDBSyncerDeviceManagerTest", + ":DistributedDBThreadPoolTest", ":DistributedDBTimeSyncTest", ":DistributedInterfacesRelationalTest", ":RuntimeContextProcessSystemApiAdapterImplTest", diff --git a/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp b/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp index f21b4ae63ce18e5be873c76356da6e6b85d18da7..f06718b404ae3ffa283f1d67e525481fa7757615 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp +++ b/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp @@ -55,8 +55,12 @@ uint64_t FuzzerData::GetUInt64() return *r; } -std::vector FuzzerData::GetSequence(size_t size) +std::vector FuzzerData::GetSequence(size_t size, uint32_t mod) { + if (mod == 0) { + return {}; + } + size = size % mod; if (curr_ + size > data_ + size_) { return {}; } @@ -71,7 +75,7 @@ std::string FuzzerData::GetString(size_t len) return ""; } - std::string res = std::string(curr_, curr_ + len - 1); + std::string res = std::string(curr_, curr_ + len); curr_ += len; return res; } diff --git a/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.h b/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.h index 447ec8cc08568134b3084b1fc073f34eaa5a1d35..135cabef97fa136be232270937e278f62acd6568 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.h +++ b/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.h @@ -22,6 +22,7 @@ #include namespace DistributedDBTest { + class FuzzerData final { public: FuzzerData(const uint8_t *data, size_t size); @@ -30,11 +31,13 @@ public: int GetInt(); uint32_t GetUInt32(); uint64_t GetUInt64(); - std::vector GetSequence(size_t size); + std::vector GetSequence(size_t size, uint32_t mod = MOD); std::string GetString(size_t len); std::vector GetStringVector(size_t size); std::vector GetU16StringVector(size_t size); private: + static const uint32_t MOD = 1024; // MOD length + const uint8_t *data_; const size_t size_; const uint8_t *curr_; diff --git a/frameworks/libs/distributeddb/test/fuzztest/delegate_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/delegate_fuzzer/BUILD.gn index c76f6e9e6a744d9ce649c3ecf5976280d08d4d8c..1f3c8f9ebc4850b3faf14b8906c132000eb7df37 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/delegate_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/delegate_fuzzer/BUILD.gn @@ -26,12 +26,18 @@ ohos_fuzztest("DelegateFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -57,9 +63,201 @@ ohos_fuzztest("DelegateFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/delegate_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_data_generate_unit_test.cpp", "delegate_fuzzer.cpp", @@ -79,12 +277,15 @@ ohos_fuzztest("DelegateFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/fileoper_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/fileoper_fuzzer/BUILD.gn index 839275c83513f181d88ac6d353b987ab9ff034a2..4726054e039ad024c5dd90af85bfdab5e6d2a3a4 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/fileoper_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/fileoper_fuzzer/BUILD.gn @@ -26,18 +26,23 @@ ohos_fuzztest("FileOperFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//third_party/jsoncpp/include/json", "//third_party/skia/third_party/externals/spirv-headers/tools/buildHeaders/jsoncpp/dist/json", "//third_party/skia/third_party/externals/swiftshader/third_party/SPIRV-Headers/tools/buildHeaders/jsoncpp/dist/json", @@ -58,9 +63,201 @@ ohos_fuzztest("FileOperFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/fileoper_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_data_generate_unit_test.cpp", "fileoper_fuzzer.cpp", @@ -70,6 +267,8 @@ ohos_fuzztest("FileOperFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] defines = [ @@ -86,6 +285,7 @@ ohos_fuzztest("FileOperFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/importfile_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/importfile_fuzzer/BUILD.gn index de2338af598acd38690dc93dbde09199a5d688cf..3e214090588d59e66118ae043fc9d4e8facef627 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/importfile_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/importfile_fuzzer/BUILD.gn @@ -26,12 +26,18 @@ ohos_fuzztest("ImportFileFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -57,9 +63,201 @@ ohos_fuzztest("ImportFileFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/importfile_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_data_generate_unit_test.cpp", "importfile_fuzzer.cpp", @@ -79,12 +277,15 @@ ohos_fuzztest("ImportFileFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/iprocesscommunicator_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/iprocesscommunicator_fuzzer/BUILD.gn index 8f0ad1f28ea00cba474a88f64d5c44d4bdaa0f59..2b552af265e10d20df5922ec28eea9ebfc9b4889 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/iprocesscommunicator_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/iprocesscommunicator_fuzzer/BUILD.gn @@ -26,12 +26,18 @@ ohos_fuzztest("IProcessCommunicatorFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -57,9 +63,201 @@ ohos_fuzztest("IProcessCommunicatorFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/iprocesscommunicator_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "iprocesscommunicator_fuzzer.cpp", ] @@ -78,12 +276,15 @@ ohos_fuzztest("IProcessCommunicatorFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/kvdelegatemanager_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/kvdelegatemanager_fuzzer/BUILD.gn index 587b29e224156c3a3bc2ac36d9dca75f13459a92..12423b76766ed1224f8dba01870dd1178badb7f2 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/kvdelegatemanager_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/kvdelegatemanager_fuzzer/BUILD.gn @@ -26,12 +26,18 @@ ohos_fuzztest("KvDelegateManagerFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -57,9 +63,201 @@ ohos_fuzztest("KvDelegateManagerFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/kvdelegatemanager_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_data_generate_unit_test.cpp", "kvdelegatemanager_fuzzer.cpp", @@ -79,12 +277,15 @@ ohos_fuzztest("KvDelegateManagerFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/kvstoreresultset_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/kvstoreresultset_fuzzer/BUILD.gn index 7be73aca218e8dda44cd7cf80eeb64869f05d8ba..229ee3bd9f158f486c8889fb9f9792013d5fb9b5 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/kvstoreresultset_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/kvstoreresultset_fuzzer/BUILD.gn @@ -26,12 +26,18 @@ ohos_fuzztest("KvStoreResultSetFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -57,9 +63,201 @@ ohos_fuzztest("KvStoreResultSetFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/kvstoreresultset_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_data_generate_unit_test.cpp", "kvstoreresultset_fuzzer.cpp", @@ -79,12 +277,15 @@ ohos_fuzztest("KvStoreResultSetFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/nbdelegate_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/nbdelegate_fuzzer/BUILD.gn index e73260a66ee163541c7d4609e33751f967799b35..b912d80c3ca13b848f69ec896d66a8f730b5e6e7 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/nbdelegate_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/nbdelegate_fuzzer/BUILD.gn @@ -26,12 +26,18 @@ ohos_fuzztest("NbDelegateFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -57,9 +63,201 @@ ohos_fuzztest("NbDelegateFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/nbdelegate_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "nbdelegate_fuzzer.cpp", ] @@ -78,12 +276,15 @@ ohos_fuzztest("NbDelegateFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/nbdelegate_fuzzer/nbdelegate_fuzzer.cpp b/frameworks/libs/distributeddb/test/fuzztest/nbdelegate_fuzzer/nbdelegate_fuzzer.cpp index 2b1e494bf0f74e24c007132b103a6fdf74e123cf..0766f5e96ca098a284e0e91e18034cfecb7cbff5 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/nbdelegate_fuzzer/nbdelegate_fuzzer.cpp +++ b/frameworks/libs/distributeddb/test/fuzztest/nbdelegate_fuzzer/nbdelegate_fuzzer.cpp @@ -144,6 +144,24 @@ void FuzzSetInterceptorTest(KvStoreNbDelegate *kvNbDelegatePtr) ); } +void TestCRUD(const Key &key, const Value &value, KvStoreNbDelegate *kvNbDelegatePtr) +{ + Value valueRead; + kvNbDelegatePtr->PutLocal(key, value); + kvNbDelegatePtr->GetLocal(key, valueRead); + kvNbDelegatePtr->DeleteLocal(key); + kvNbDelegatePtr->Put(key, value); + kvNbDelegatePtr->Put(key, value); + kvNbDelegatePtr->UpdateKey([](const Key &origin, Key &newKey) { + newKey = origin; + newKey.push_back('0'); + }); + std::vector vect; + kvNbDelegatePtr->GetEntries(key, vect); + kvNbDelegatePtr->Delete(key); + kvNbDelegatePtr->Get(key, valueRead); +} + void FuzzCURD(const uint8_t* data, size_t size, KvStoreNbDelegate *kvNbDelegatePtr) { auto observer = new (std::nothrow) KvStoreObserverFuzzTest; @@ -156,17 +174,7 @@ void FuzzCURD(const uint8_t* data, size_t size, KvStoreNbDelegate *kvNbDelegateP kvNbDelegatePtr->SetConflictNotifier(size, [](const KvStoreNbConflictData &data) { (void)data.GetType(); }); - - Value valueRead; - kvNbDelegatePtr->PutLocal(key, value); - kvNbDelegatePtr->GetLocal(key, valueRead); - kvNbDelegatePtr->DeleteLocal(key); - kvNbDelegatePtr->Put(key, value); - kvNbDelegatePtr->Put(key, value); - std::vector vect; - kvNbDelegatePtr->GetEntries(key, vect); - kvNbDelegatePtr->Delete(key); - kvNbDelegatePtr->Get(key, valueRead); + TestCRUD(key, value, kvNbDelegatePtr); std::vector keys; std::vector tmp = CreateEntries(data, size, keys); kvNbDelegatePtr->PutBatch(tmp); diff --git a/frameworks/libs/distributeddb/test/fuzztest/parseckeck_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/parseckeck_fuzzer/BUILD.gn index d083e09ec06c3e4b749a0787795c7f7466d3f53c..d995db2ed836426a175800aaf0c88cb84525d847 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/parseckeck_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/parseckeck_fuzzer/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -#####################hydra-fuzz################### +#####################hydra-fuzz###################common\src\schema_constant. import("//build/config/features.gni") import("//build/test.gni") @@ -26,12 +26,18 @@ ohos_fuzztest("ParseCkeckFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -57,13 +63,201 @@ ohos_fuzztest("ParseCkeckFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/parseckeck_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_data_generate_unit_test.cpp", "parseckeck_fuzzer.cpp", @@ -83,12 +277,15 @@ ohos_fuzztest("ParseCkeckFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/query_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/query_fuzzer/BUILD.gn index f40c73a3d72f4a6630bfa65e3ea90a9d24ade785..d3ff70fbdf690b5548ba02f0a931af99946ac29f 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/query_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/query_fuzzer/BUILD.gn @@ -25,12 +25,18 @@ ohos_fuzztest("QueryFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -56,12 +62,201 @@ ohos_fuzztest("QueryFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/query_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_data_generate_unit_test.cpp", "query_fuzzer.cpp", ] @@ -80,12 +275,15 @@ ohos_fuzztest("QueryFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/rekey_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/rekey_fuzzer/BUILD.gn index f6c00e2c45cc6b9f8634c1e91851047d7bd02193..74f91697f980ad5bf18c98c9cb56a95a53e8afe3 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/rekey_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/rekey_fuzzer/BUILD.gn @@ -26,12 +26,18 @@ ohos_fuzztest("ReKeyFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -57,9 +63,201 @@ ohos_fuzztest("ReKeyFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/rekey_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_data_generate_unit_test.cpp", "rekey_fuzzer.cpp", @@ -79,12 +277,15 @@ ohos_fuzztest("ReKeyFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer/BUILD.gn index 10541455230d3a6530f2a69fe7edb16848af54d1..9c18e643f2820b0b2ef95d4b3dafb954e6991850 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer/BUILD.gn @@ -27,12 +27,18 @@ ohos_fuzztest("RelationalstoredelegateFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include/distributeddb", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -58,9 +64,201 @@ ohos_fuzztest("RelationalstoredelegateFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer/relationalstoredelegate_fuzzer.cpp", @@ -84,6 +282,7 @@ ohos_fuzztest("RelationalstoredelegateFuzzTest") { "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", "SQLITE_EXPORT_SYMBOLS", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ @@ -91,6 +290,7 @@ ohos_fuzztest("RelationalstoredelegateFuzzTest") { "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer/relationalstoredelegate_fuzzer.cpp b/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer/relationalstoredelegate_fuzzer.cpp index 64d5d60f91b0d210128fc6d60a1f1e0be2b8e108..2cf32a8a5651b7d4cbfeef346ea21111fe5c3629 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer/relationalstoredelegate_fuzzer.cpp +++ b/frameworks/libs/distributeddb/test/fuzztest/relationalstoredelegate_fuzzer/relationalstoredelegate_fuzzer.cpp @@ -118,6 +118,7 @@ void CombineTest(const uint8_t* data, size_t size) } g_delegate->Sync(device, mode, query, nullptr, len % 2); // 2 is mod num for wait parameter std::string deviceId = device.size() > 0 ? device[0] : tableName; + g_delegate->RemoveDeviceData(); g_delegate->RemoveDeviceData(deviceId); g_delegate->RemoveDeviceData(deviceId, tableName); diff --git a/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer/BUILD.gn index 558de907d0999f5d49d5ddb7287d073ae6ef3b04..6139ab5a43b28887c207c268800265103b6db518 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer/BUILD.gn @@ -25,14 +25,19 @@ ohos_fuzztest("RelationalstoremanagerFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/syncer", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include/distributeddb", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -58,9 +63,201 @@ ohos_fuzztest("RelationalstoremanagerFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer/relationalstoremanager_fuzzer.cpp", @@ -84,6 +281,7 @@ ohos_fuzztest("RelationalstoremanagerFuzzTest") { "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", "SQLITE_EXPORT_SYMBOLS", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ @@ -91,6 +289,7 @@ ohos_fuzztest("RelationalstoremanagerFuzzTest") { "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer/relationalstoremanager_fuzzer.cpp b/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer/relationalstoremanager_fuzzer.cpp index 5621535136dad18d134563499b1f569993d68d1e..c5fd1f9c82e0a40cb4e1a9d421b46d32816781c5 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer/relationalstoremanager_fuzzer.cpp +++ b/frameworks/libs/distributeddb/test/fuzztest/relationalstoremanager_fuzzer/relationalstoremanager_fuzzer.cpp @@ -79,6 +79,9 @@ void CombineTest(const uint8_t* data, size_t size) g_mgr.OpenStore(g_dbDir + appId + DB_SUFFIX, storeId, {}, g_delegate); g_mgr.GetRelationalStoreIdentifier(userId, appId, storeId, instanceId % 2); // 2 is mod num for last parameter RuntimeConfig::SetProcessLabel(appId, userId); + RuntimeConfig::SetTranslateToDeviceIdCallback([](const std::string &oriDevId, const StoreInfo &info) { + return oriDevId + "_" + info.appId; + }); } } diff --git a/frameworks/libs/distributeddb/test/fuzztest/schemadelegate_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/schemadelegate_fuzzer/BUILD.gn index e9fbd144dff3ba206fc4c194928c08194377eda4..5138b341d276c5a2c869afb701384624536ca003 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/schemadelegate_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/schemadelegate_fuzzer/BUILD.gn @@ -26,12 +26,18 @@ ohos_fuzztest("SchemaDelegateFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -55,9 +61,201 @@ ohos_fuzztest("SchemaDelegateFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/schemadelegate_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/common/distributeddb_data_generate_unit_test.cpp", @@ -78,12 +276,15 @@ ohos_fuzztest("SchemaDelegateFuzzTest") { "OMIT_FLATBUFFER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/fuzztest/sync_fuzzer/BUILD.gn b/frameworks/libs/distributeddb/test/fuzztest/sync_fuzzer/BUILD.gn index e30d87c59c7d93f7a5be6523404702b9a9e178b8..55cbb16d131a84af4e56369bb7a628d877578115 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/sync_fuzzer/BUILD.gn +++ b/frameworks/libs/distributeddb/test/fuzztest/sync_fuzzer/BUILD.gn @@ -26,12 +26,18 @@ ohos_fuzztest("SyncFuzzTest") { "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/storage", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include/relational", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src", @@ -57,9 +63,201 @@ ohos_fuzztest("SyncFuzzTest") { fuzz_config_file = "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/sync_fuzzer" sources = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/auto_launch.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_compression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/data_value.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_common.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dfx_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/db_dump_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_epoll.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/event_loop_select.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/evloop/src/ievent_loop.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/flatbuffer_schema.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/hash.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/json_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/lock_status_observer.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/notification_chain.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/param_check_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/parcel.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/performance_analysis.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/platform_specific.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/query_expression.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/ref_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/prepared_stmt.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/relational/table_info.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/runtime_context_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_constant.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/schema_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/semaphore_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_pool_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/task_queue.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/time_tick_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/types_export.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/user_change_monitor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/combine_status.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/communicator_linker.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_combiner.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/frame_retainer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/header_converter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/message_transform.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/network_adapter.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/communicator/src/serial_buffer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_errno.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src/runtime_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/data_transformer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/db_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/default_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/iconnection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/ikvdb_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_commit_notify_filterable_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_observer_handle.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/kvdb_windowed_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/generic_multi_ver_kv_entry.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_commit.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_kvdata_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_commit_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_natural_store_transfer_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_vacuum_executor_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver/multi_ver_value_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/local_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/multi_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/package_file.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_row_data_impl.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/result_entries_window.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/single_ver_natural_store_commit_notify_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/collaboration_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/log_table_manager_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/relational_remote_query_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb_snapshot.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_log_table_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_data_storage.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_multi_ver_transaction.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_forward_cursor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_continue_token.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/storage_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sync_able_kvdb_connection.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/upgrader/single_ver_schema_database_upgrader.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/ability_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/commit_history_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/communicator_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/db_ability.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/device_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/meta_data.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/multi_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/remote_executor_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_message_schedule.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_packet.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_kv_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_relational_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_serialize_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/single_ver_syncer.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_config.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_target.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/sync_task_context.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_factory.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/syncer_proxy.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_helper.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/time_sync.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/syncer/src/value_slice_sync.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/distributeddb_tools_test.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.cpp", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.cpp", @@ -81,14 +279,18 @@ ohos_fuzztest("SyncFuzzTest") { "LOW_LEVEL_MEM_DEV", "JSONCPP_USE_BUILDER", "OMIT_FLATBUFFER", + "OMIT_MULTI_VER", "RELATIONAL_STORE", "SQLITE_DISTRIBUTE_RELATIONAL", + "SQLITE_ENABLE_DROPTABLE_CALLBACK", ] deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", "//third_party/jsoncpp:jsoncpp", "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + "//third_party/zlib:shared_libz", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/moduletest/BUILD.gn b/frameworks/libs/distributeddb/test/moduletest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..eeb51b201b37a3e04334d951c402879e01e99177 --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/BUILD.gn @@ -0,0 +1,709 @@ +# Copyright (c) 2021 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. +import("//build/test.gni") + +module_output_path = "kv_store/distributeddb" + +mul_sources = [ + "common/distributeddb/src/auto_launch_callback.cpp", + "common/distributeddb/src/delegate_callback.cpp", + "common/distributeddb/src/delegate_kv_mgr_callback.cpp", + "common/distributeddb/src/distributed_test_tools.cpp", + "common/distributeddb/src/kv_store_observer_impl.cpp", + "common/distributeddb/src/kv_store_snapshot_callback.cpp", +] + +############################################################################### +config("module_private_config") { + visibility = [ ":*" ] + + include_dirs = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + + # "../adapter/include/communicator", + "//developtools/liblog", + "common/distributeddb/include", + "include", + "//commonlibrary/c_utils/base/include", + "//third_party/sqlite/include", + "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", + "//third_party/openssl/include/", + ] + + defines = [ + "_LARGEFILE64_SOURCE", + "_FILE_OFFSET_BITS=64", + "SQLITE_HAS_CODEC", + "USE_SQLITE_SYMBOLS", + "USING_HILOG_LOGGER", + "TESTCASES_USING_GTEST_EXT", + "OMIT_JSON", + "LOW_LEVEL_MEM_DEV", + "RELEASE_MODE_V2", + "RELEASE_MODE_V3", + "OMIT_MULTI_VER", + ] + ldflags = [ "-Wl,--exclude-libs,ALL" ] +} + +##############################moduletest########################################## +ohos_moduletest("DistributeddbKvTransactionTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributed_crud_transaction_tools.cpp", + "src/distributeddb_kv_transaction_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbKvTransactionPerfTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributed_crud_transaction_tools.cpp", + "src/distributeddb_kv_transaction_perf_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvConcurrencyCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_concurrency_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvBatchCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_batch_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvCreateTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_create_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvObserverTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_observer_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvObserverSnapTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_observer_snap_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbKvBackupTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_backup_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbKvRealdelTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_realdel_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbCreateTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_create_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbNbCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbNbObserverTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_observer_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbCursorTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_cursor_test.cpp", + "src/distributeddb_nb_cursor_testcase.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbBackupTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_backup_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbBatchCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_batch_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbLocalBatchCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_local_batch_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbSchemaDbTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_schema_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbPredicateQueryTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_predicate_query_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbPredicateQueryExpandTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_predicate_query_expand_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbAutolaunchTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_autolaunch_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributedbNbDbDamageTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_db_damage_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbCrudPowerTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_crud_power_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbSchemaTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_schema_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbSchemaUpgradeTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_schema_upgrade_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +############################################################################### +group("moduletest") { + testonly = true + deps = [ + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + "//third_party/sqlite:sqlite", + ] + + deps += [ + ":DistributedbNbDbDamageTest", + ":DistributeddbKvBackupTest", + ":DistributeddbKvBatchCrudTest", + ":DistributeddbKvConcurrencyCrudTest", + ":DistributeddbKvCreateTest", + ":DistributeddbKvCrudTest", + ":DistributeddbKvObserverSnapTest", + ":DistributeddbKvObserverTest", + ":DistributeddbKvRealdelTest", + ":DistributeddbKvTransactionPerfTest", + ":DistributeddbKvTransactionTest", + ":DistributeddbNbAutolaunchTest", + ":DistributeddbNbBackupTest", + ":DistributeddbNbBatchCrudTest", + ":DistributeddbNbCreateTest", + ":DistributeddbNbCrudPowerTest", + ":DistributeddbNbCrudTest", + ":DistributeddbNbCursorTest", + ":DistributeddbNbLocalBatchCrudTest", + ":DistributeddbNbObserverTest", + ":DistributeddbNbPredicateQueryExpandTest", + ":DistributeddbNbPredicateQueryTest", + ":DistributeddbNbSchemaTest", + ":DistributeddbNbSchemaUpgradeTest", + ] +} diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/auto_launch_callback.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/auto_launch_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..17e1f409e8e9ad5db1ac139e313bd4fb813e3b9d --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/auto_launch_callback.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 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 AUTO_LAUNCH_CALLBACK_H +#define AUTO_LAUNCH_CALLBACK_H + +#include +#include "auto_launch_export.h" +#include "types_export.h" + +#ifdef RELEASE_MODE_V2 +class AutoLaunchCallback { +public: + AutoLaunchCallback() {} + ~AutoLaunchCallback() {} + + // Delete the copy and assign constructors + AutoLaunchCallback(const AutoLaunchCallback &callback) = delete; + AutoLaunchCallback &operator=(const AutoLaunchCallback &callback) = delete; + AutoLaunchCallback(AutoLaunchCallback &&callback) = delete; + AutoLaunchCallback &operator=(AutoLaunchCallback &&callback) = delete; + + void AutoLaunchNotifier(const std::string &userId, const std::string &appId, const std::string &storeId, + DistributedDB::AutoLaunchStatus status); + int GetStatus(); + void Clear(); +#ifdef RELEASE_MODE_V3 + bool AutoLaunchRequestNotifier(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); + void AddHashIdentity(const std::string &hashIdentity); + void ClearHashIdentities(); + void SetAutoLaunchParam(DistributedDB::AutoLaunchParam &autoLaunchParam); +#endif + +private: + int realStatus_ = 0; + std::vector hashIdentities_; +#ifdef RELEASE_MODE_V3 + DistributedDB::AutoLaunchParam autoLaunchParam_; +#endif +}; +#endif // end of RELEASE_MODE_V2 +#endif // AUTO_LAUNCH_CALLBACK_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_callback.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..a6a045fc999bad3d715b81b24d60b6ba1b78dec3 --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_callback.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 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 DELEGATE_CALLBACK_H +#define DELEGATE_CALLBACK_H +#include "kv_store_snapshot_delegate.h" +#include "types_export.h" + +// DelegateCallback conclude the Callback implements of function< void(DBStatus, KvStoreSnapshotDelegate*)> +class DelegateCallback { +public: + DelegateCallback() {} + ~DelegateCallback() {} + + // Delete the copy and assign constructors + DelegateCallback(const DelegateCallback &callback) = delete; + DelegateCallback& operator=(const DelegateCallback &callback) = delete; + DelegateCallback(DelegateCallback &&callback) = delete; + DelegateCallback& operator=(DelegateCallback &&callback) = delete; + + void Callback(DistributedDB::DBStatus status, DistributedDB::KvStoreSnapshotDelegate *kvStoreSnapshotDelegate); + void CallbackKv(DistributedDB::DBStatus status, const DistributedDB::Value &value); + + DistributedDB::DBStatus GetStatus(); + const DistributedDB::Value &GetValue(); + + const DistributedDB::KvStoreSnapshotDelegate *GetKvStoreSnapshot() + { + return kvStoreSnapshotDelegate_; + } + +private: + DistributedDB::DBStatus status_ = DistributedDB::DBStatus::INVALID_ARGS; + DistributedDB::Value value_ = {}; + DistributedDB::KvStoreSnapshotDelegate *kvStoreSnapshotDelegate_ = nullptr; +}; + +#endif // DELEGATE_CALLBACK_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_kv_mgr_callback.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_kv_mgr_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..35b087093736b122859ea93414c9e3ca74cc3336 --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_kv_mgr_callback.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 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 DELEGATE_KV_MGR_CALLBACK_H +#define DELEGATE_KV_MGR_CALLBACK_H + +#include "kv_store_delegate.h" + +// DelegateKvMgrCallback conclude the Callback implements of function< void(DBStatus, KvStoreDelegate*)> +class DelegateKvMgrCallback { +public: + DelegateKvMgrCallback() {} + ~DelegateKvMgrCallback() {} + + // Delete the copy and assign constructors + DelegateKvMgrCallback(const DelegateKvMgrCallback &callback) = delete; + DelegateKvMgrCallback& operator=(const DelegateKvMgrCallback &callback) = delete; + DelegateKvMgrCallback(DelegateKvMgrCallback &&callback) = delete; + DelegateKvMgrCallback& operator=(DelegateKvMgrCallback &&callback) = delete; + + void Callback(DistributedDB::DBStatus status, DistributedDB::KvStoreDelegate *kvStoreDelegate); + + DistributedDB::DBStatus GetStatus(); + + const DistributedDB::KvStoreDelegate *GetKvStore(); + +private: + DistributedDB::DBStatus status_ = DistributedDB::DBStatus::INVALID_ARGS; + DistributedDB::KvStoreDelegate *kvStoreDelegate_ = nullptr; +}; + +#endif // DELEGATE_KV_MGR_CALLBACK_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_rdb_tools.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_rdb_tools.h new file mode 100644 index 0000000000000000000000000000000000000000..95b15b9d39e6e2044390ba3d6e9647687e8927fa --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_rdb_tools.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 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 DISTRIBUTED_RDB_MODULE_TEST_TOOLS_H +#define DISTRIBUTED_RDB_MODULE_TEST_TOOLS_H +#include +#include + +#include "relational_store_delegate.h" +#include "relational_store_manager.h" +#include "distributed_test_sysinfo.h" +#include "distributeddb_data_generator.h" +#include "log_print.h" +#ifdef TESTCASES_USING_GTEST +#define HWTEST_F(test_case_name, test_name, level) TEST_F(test_case_name, test_name) +#endif + +struct RdbParameters { + std::string path; + std::string storeId; + std::string appId; + std::string userId; + RdbParameters(str::string pathStr, std::string storeIdStr, std::string appIdStr, std::string userIdStr) + : pathStr(pathStr), storeId(storeIdStr), appId(appIdStr), userId(userIdStr) + { + } +}; + +const static std::string TAG = "DistributedRdbTools"; + +const static std::string NORMAL_PATH = "/data/test/"; +const static std::string NON_EXISTENT_PATH = "/data/test/nonExistent_rdb/"; +const static std::string UNREADABLE_PATH = "/data/test/unreadable_rdb/"; +const static std::string UNWRITABLE_PATH = "/data/test/unwritable_rdb/"; + +const static std::string NULL_STOREID = {}; +const static std::string ILLEGAL_STOREID = "rdb_$%#@~%"; +const static std::string MODE_STOREID = "rdb_mode"; +const static std::string FULL_STOREID = "rdb_full"; +const static std::string SUPER_STOREID = "rdb_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + +const static std::string NON_EXISTENT_TABLE = "non_table"; +const static std::string KEYWORD_START_TABLE = "naturalbase_rdb_a"; + +const static std::string NORMAL_TABLE = "NORMAL_RDB"; +const static std::string CONSTRAINT_TABLE = "CONSTRAINT_RDB"; + +const static RdbParameters g_rdbParameter1(NORMAL_PATH, DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter2(NORMAL_PATH, DistributedDBDataGenerator::STORE_ID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter3(NORMAL_PATH, ILLEGAL_STOREID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter4(NORMAL_PATH, MODE_STOREID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter5(NORMAL_PATH, SUPER_STOREID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter6(NON_EXISTENT_PATH, DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter7(UNREADABLE_PATH, DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter8(UNWRITABLE_PATH, DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter9(NORMAL_PATH, FULL_STOREID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +class DistributedRdbTools final { +public: + DistributedRdbTools() {} + ~DistributedRdbTools() {} + // Relational Database OpenStore And CreateDistributeTable + static DistributedDB::DBStatus GetOpenStoreStatus(const RelatetionalStoreManager *&manager, + RelatetionalStoreDelegate *&delegate, const RdbParameters ¶m); + static DistributedDB::DBStatus GetCreateDistributedTableStatus(const RelatetionalStoreDelegate *&delegate, + const std::string &tableName); + static bool CloseStore(const DistributedDB::RelatetionalStoreDelegate *&delegate); + + static bool InitSqlite3Store(sqlite3 *&db, const RdbParameters ¶m); + static bool InitTableDataAndTrigger(const sqlite3 *&db) ; + static bool AlterTableAttributes(const sqlite3 *&db); + static bool Sqlite3ExecOpration(const sqlite3 *&db, cont char *&sql_name); + static void CloseSqlite3Store(sqlite3 *&db); +} +#endif // DISTRIBUTED_RDB_MODULE_TEST_TOOLS_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_sysinfo.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_sysinfo.h new file mode 100644 index 0000000000000000000000000000000000000000..417e9979feac72e7ab232f82edb16c1834d84b63 --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_sysinfo.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2021 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 DISTRIBUTED_TEST_SYSINFO_H +#define DISTRIBUTED_TEST_SYSINFO_H + +#include +#include "distributeddb_log_print.h" +#if defined(RUNNING_ON_LINUX) +#include +#elif defined RUNNING_ON_WIN +#endif + +const uint64_t SYSTEM_INFO_BUFFER_SIZE = 20; +const uint64_t PROC_BUFFER_LENGTH = 4096; +const uint64_t DEFAULT_INTEVAL = 250000; +const uint64_t DEFAULT_COUNT = 5; + +#if defined(RUNNING_ON_LINUX) +const std::string SYS_MEM_FILE = "/proc/meminfo"; +const std::string SYS_CPU_FILE = "/proc/stat"; +const std::string POWER_FOLLOW_FILE = "/sys/class/power_supply/Battery/current_now"; +const std::string VOLTAGE_FILE = "/sys/class/power_supply/Battery/voltage_now"; +const std::string FILE_READ_PERMISSION = "r"; + +// struct of mem occupy +struct MemOccupy { + char memTotalName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t memTotal_; + char memFreeName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t memFree_; + char buffersName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t buffers_; + char cachedName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t cached_; + char swapCachedName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t swapCached_; +}; + +// struct of cpu occupy +struct CpuOccupy { + char name_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t user_; + uint64_t nice_; + uint64_t system_; + uint64_t idle_; + uint64_t iowait_; + uint64_t irq_; + uint64_t softirq_; +}; +#elif defined RUNNING_ON_WIN +#endif + +enum SeqNo { + FIRST = 1, + SECOND +}; + +// this class get system info, such as system or cpu storage and power at the moment +class DistributedTestSysInfo final { +public: + + DistributedTestSysInfo(); + ~DistributedTestSysInfo() {} + + // Delete the copy and assign constructors + DistributedTestSysInfo(const DistributedTestSysInfo &distributeTestSysInfo) = delete; + DistributedTestSysInfo& operator=(const DistributedTestSysInfo &distributeTestSysInfo) = delete; + DistributedTestSysInfo(DistributedTestSysInfo &&distributeTestSysInfo) = delete; + DistributedTestSysInfo& operator=(DistributedTestSysInfo &&distributeTestSysInfo) = delete; + + // read memory information from system file + void GetSysMemOccpy(SeqNo seqNo); + // read cpu information from system file sleep microSeconds between first and second read. + void GetSysCpuUsage(SeqNo seqNo, uint64_t microSeconds); + // read value from specific file + float ReadSysValFromFile(const std::string &filePath); + // read value from specific file and take the average within totalCount + float GetSysMeanCurrentVal(const std::string &filePath, int totalCount, uint64_t microSeconds); + // read power from specific file + void GetSysCurrentPower(SeqNo seqNo, int totalCount, uint64_t microSeconds); + + uint64_t GetFirstMemFree() const; + uint64_t GetSecondMemFree() const; + float GetFirstCpuUsage() const; + float GetSecondCpuUsage() const; + float GetFirstPower() const; + float GetSecondPower() const; + + void SaveSecondToFirst(); + +private: +#if defined(RUNNING_ON_LINUX) + MemOccupy memStatFirst_, memStatSecond_; + CpuOccupy cpuStatFirst_, cpuStatSecond_; +#elif defined RUNNING_ON_WIN +#endif + float cpuStatFirstUsage_, cpuStatSecondUsage_; + float powerStatFirst_, powerStatSecond_; + float val_; +}; +#endif // DISTRIBUTED_TEST_SYSINFO_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_tools.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_tools.h new file mode 100644 index 0000000000000000000000000000000000000000..6e1e512d949dca0996bdd9650df6564e623e9e30 --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_tools.h @@ -0,0 +1,436 @@ +/* + * Copyright (c) 2021 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 DISTRIBUTED_DB_MODULE_TEST_TOOLS_H +#define DISTRIBUTED_DB_MODULE_TEST_TOOLS_H +#include +#include + +#include "kv_store_delegate.h" +#include "kv_store_delegate_manager.h" +#include "kv_store_observer_impl.h" +#include "distributed_test_sysinfo.h" +#include "distributeddb_data_generator.h" +#include "log_print.h" +#ifdef RUN_MST_ON_TRUNCK // only need it in WAGNER env if run MST +#define HWTEST_F(test_case_name, test_name, level) TEST_F(test_case_name, test_name) +#endif +#define ULL(x) (static_cast(x)) +const int MAX_DIR_LENGTH = 4096; // the max length of directory +const int BUF_LEN = 8192; +const static std::string TAG = "DistributedTestTools"; // for log +const int AUTHORITY = 0755; +const int E_OK = 0; +const int E_ERROR = -1; +const std::string DIRECTOR = "/data/test/getstub/"; // default work dir. +static std::condition_variable g_conditionKvVar; + +struct KvDBParameters { + std::string storeId; + std::string appId; + std::string userId; + KvDBParameters(std::string storeIdStr, std::string appIdStr, std::string userIdStr) + : storeId(storeIdStr), appId(appIdStr), userId(userIdStr) + { + } +}; + +struct KvOption { + bool createIfNecessary = true; + bool localOnly = false; + bool isEncryptedDb = false; // whether need encrypt + DistributedDB::CipherType cipher = DistributedDB::CipherType::DEFAULT; // cipher type + std::vector passwd; // cipher password + KvOption(bool createIfNecessary1, bool isLocalOnly, + bool isEncryptedDb1, DistributedDB::CipherType cipher1, std::vector passwd1) + : createIfNecessary(createIfNecessary1), + localOnly(isLocalOnly), + isEncryptedDb(isEncryptedDb1), + cipher(cipher1), passwd(passwd1) + { + } + KvOption() + {} +}; + +struct EncrypteAttribute { + bool isEncryptedDb = false; + std::vector passwd; +}; + +const static KvDBParameters g_kvdbParameter1(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static KvDBParameters g_kvdbParameter2(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_2); +const static KvDBParameters g_kvdbParameter3(DistributedDBDataGenerator::STORE_ID_3, + DistributedDBDataGenerator::APP_ID_3, DistributedDBDataGenerator::USER_ID_3); +const static KvDBParameters g_kvdbParameter4(DistributedDBDataGenerator::STORE_ID_4, + DistributedDBDataGenerator::APP_ID_4, DistributedDBDataGenerator::USER_ID_4); +const static KvDBParameters g_kvdbParameter5(DistributedDBDataGenerator::STORE_ID_5, + DistributedDBDataGenerator::APP_ID_5, DistributedDBDataGenerator::USER_ID_5); +const static KvDBParameters g_kvdbParameter6(DistributedDBDataGenerator::STORE_ID_6, + DistributedDBDataGenerator::APP_ID_6, DistributedDBDataGenerator::USER_ID_6); +const static KvDBParameters g_kvdbParameter1_1_2(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_2); +const static KvDBParameters g_kvdbParameter1_2_1(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_1); +const static KvDBParameters g_kvdbParameter1_2_2(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_2); +const static KvDBParameters g_kvdbParameter2_1_1(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static KvDBParameters g_kvdbParameter2_1_2(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_2); +const static KvDBParameters KVDB_PARAMETER_PERFORM(DistributedDBDataGenerator::STORE_ID_PERFORM, + DistributedDBDataGenerator::APP_ID_PERFORM, DistributedDBDataGenerator::USER_ID_PERFORM); +const static KvOption g_createKvDiskUnencrypted(true, false, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +const static KvOption g_createKvDiskEncrypted(true, false, true, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::PASSWD_VECTOR_1); +const static KvOption g_createLocalDiskUnencrypted(true, true, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +const static KvOption g_createLocalDiskEncrypted(true, true, true, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::PASSWD_VECTOR_1); +static KvOption g_kvOption = g_createKvDiskEncrypted; +bool CompareVector(const std::vector& first, const std::vector& second); +bool CompareEntriesVector(std::vector& retVec, + std::vector& expectVec); +void PutUniqueKey(std::vector& entryVec, + const DistributedDB::Key &putKey, const DistributedDB::Value &putValue); +int Uint8VecToString(std::vector& vec, std::string& str); +int GetIntValue(DistributedDB::Value &value); +int RemoveDir(const std::string &directory); +int SetDir(const std::string &directory, const int authRight = AUTHORITY); +void CopyFile(const std::string &srcFile, const std::string &destFile); +void CopyDir(const std::string &srcDir, const std::string &destDir, const int authRight = AUTHORITY); +void CheckFileNumber(const std::string &filePath, int &fileCount); +DistributedDB::Value GetValueWithInt(int val); +std::vector GenRanKeyVal(int putGetTimes, int keyLength, int valueLength, char val); +std::vector GetKeysFromEntries(std::vector entries, bool random); +bool GetRandBool(); +bool PutEntries(DistributedDB::KvStoreNbDelegate *&delegate, std::vector &entries); + +using SysTime = std::chrono::time_point; +using SysDurTime = std::chrono::duration; + +struct PerformanceData { + int putGetTimes; + int keyLength; + int valueLength; + bool putBatch; + bool getBatch; + bool useClear; + bool getSysInfo; + bool isLocal; + double openDuration; + double putDuration; + double readPutDuration; + double updateDuration; + double readUpdateDuration; + double deleteDuration; + double closeDuration; + PerformanceData(int putGetTimes, int keyLength, int valueLength, + bool putBatch, bool getBatch, bool useClear, bool getSysInfo, bool isLocal) + : putGetTimes(putGetTimes), keyLength(keyLength), valueLength(valueLength), + putBatch(putBatch), getBatch(getBatch), useClear(useClear), + getSysInfo(getSysInfo), isLocal(isLocal), + openDuration(0.0), putDuration(0.0), readPutDuration(0.0), updateDuration(0.0), + readUpdateDuration(0.0), deleteDuration(0.0), closeDuration(0.0) + { + } +}; + +struct Duration { + double putDuration = 0.0; + double readDuration = 0.0; + double updateDuration = 0.0; + double deleteDuration = 0.0; + Duration() = default; + void Clear() + { + putDuration = readDuration = updateDuration = deleteDuration = 0.0; + } +}; + +struct BackupDuration { + double exportDuration = 0.0; + double importDuration = 0.0; + BackupDuration() = default; + BackupDuration(double exportDur, double importDur) + { + exportDuration = exportDur; + importDuration = importDur; + } + BackupDuration operator+(const BackupDuration &backupDur) const + { + return BackupDuration(exportDuration + backupDur.exportDuration, importDuration + backupDur.importDuration); + } + void Clear() + { + exportDuration = importDuration = 0; + } +}; + +enum KvDbType { + ENCRYED = 0, + UNENCRYED = 1 +}; + +enum OperRecordNum { + SINGLE = 1, + SMALL_BATCH = 100, + BATCH = 128, +}; + +enum class OperType { + PUT, + PUT_LOCAL, + UPDATE, + UPDATE_LOCAL, + DELETE, + DELETE_LOCAL +}; + +struct KvPerfData { + KvDbType kvDbType; + int testCnt; + OperRecordNum operRecordNum; + int keyLength; + int valueLength; + bool isPresetRecords; + int presetRecordsCnt; + std::vector allCrudDur; + KvPerfData(KvDbType kvDbType, int testCnt, OperRecordNum operRecordNum, int keyLength, int valueLength, + bool isPresetRecords, int presetRecordsCnt) + : kvDbType(kvDbType), testCnt(testCnt), operRecordNum(operRecordNum), + keyLength(keyLength), valueLength(valueLength), + isPresetRecords(isPresetRecords), presetRecordsCnt(presetRecordsCnt) + { + } +}; + +struct RekeyTypesDur { + double nullPasswdToPasswd1 = 0.0; + double passwd1ToPasswd1 = 0.0; + double passwd1ToPasswd2 = 0.0; + double passwd2ToNullPasswd = 0.0; + RekeyTypesDur() = default; + RekeyTypesDur(double nullPasswdToPasswd1, double passwd1ToPasswd1, + double passwd1ToPasswd2, double passwd2ToNullPasswd) + : nullPasswdToPasswd1(nullPasswdToPasswd1), passwd1ToPasswd1(passwd1ToPasswd1), + passwd1ToPasswd2(passwd1ToPasswd2), passwd2ToNullPasswd(passwd2ToNullPasswd) + { + } + RekeyTypesDur operator+(const RekeyTypesDur &rekeyTypesDur) const + { + return RekeyTypesDur(nullPasswdToPasswd1 + rekeyTypesDur.nullPasswdToPasswd1, + passwd1ToPasswd1 + rekeyTypesDur.passwd1ToPasswd1, + passwd1ToPasswd2 + rekeyTypesDur.passwd1ToPasswd2, + passwd2ToNullPasswd + rekeyTypesDur.passwd2ToNullPasswd); + } +}; + +struct KvRekeyPerfData { + int testCnt; + int presetRecordsCnt; + int keyLength; + int valueLength; + std::vector allRekeyDur; + KvRekeyPerfData(int testCnt, int presetRecordsCnt, int keyLength, int valueLength) + : testCnt(testCnt), presetRecordsCnt(presetRecordsCnt), keyLength(keyLength), valueLength(valueLength) + { + } +}; + +struct KvBackupPerfData { + KvDbType kvDbType; + int testCnt; + int presetRecordsCnt; + int keyLength; + int valueLength; + std::vector allBackupDur; + KvBackupPerfData(KvDbType kvDbType, int testCnt, int presetRecordsCnt, int keyLength, int valueLength) + : kvDbType(kvDbType), testCnt(testCnt), presetRecordsCnt(presetRecordsCnt), + keyLength(keyLength), valueLength(valueLength) + { + } +}; + +struct PerImageGallery { + uint64_t putDuration = 0; + uint64_t readDuration = 0; + void Clear() + { + putDuration = 0; + readDuration = 0; + } +}; +struct NbGalleryPerfData { + int testCnt; + unsigned int keyLength; + unsigned int valueLength; + bool isLocal; + bool isPresetRecords; + int presetRecordsCnt; + std::vector allCrudDur; + NbGalleryPerfData(int testCnt, int keyLength, int valueLength, + bool isLocal, bool isPresetRecords, int presetRecordsCnt) + : testCnt(testCnt), keyLength(keyLength), valueLength(valueLength), + isLocal(isLocal), isPresetRecords(isPresetRecords), presetRecordsCnt(presetRecordsCnt) + { + } +}; +struct NbLocalPerfData { + int testCnt; + unsigned int keyLength; + unsigned int valueLength; + bool isLocal; + bool isPresetRecords; + int presetRecordsCnt; + std::vector allCrudDur; + NbLocalPerfData(int testCnt, int keyLength, int valueLength, + bool isLocal, bool isPresetRecords, int presetRecordsCnt) + : testCnt(testCnt), keyLength(keyLength), valueLength(valueLength), + isLocal(isLocal), isPresetRecords(isPresetRecords), presetRecordsCnt(presetRecordsCnt) + { + } +}; + +struct QueryDur { + double getEntriesDuration = 0.0; + double getResultSetDuration = 0.0; + QueryDur() = default; + void Clear() + { + getEntriesDuration = getResultSetDuration = 0; + } +}; +struct NbSchemaCRUDPerfData { + int testCnt; + OperRecordNum operRecordNum; + unsigned int keyLength; + unsigned int valueLength; + bool isLocal; + bool isPresetRecords; + unsigned int presetRecordsCnt; + bool isQueryNeeded; + bool isIndexSchema; + std::vector allCrudDur; + std::vector allQueryDur; + NbSchemaCRUDPerfData(int testCnt, OperRecordNum operRecordNum, int keyLength, int valueLength, + bool isLocal, bool isPresetRecords, int presetRecordsCnt, int isQueryNeeded, int isIndexSchema) + : testCnt(testCnt), operRecordNum(operRecordNum), keyLength(keyLength), valueLength(valueLength), + isLocal(isLocal), isPresetRecords(isPresetRecords), presetRecordsCnt(presetRecordsCnt), + isQueryNeeded(isQueryNeeded), isIndexSchema(isIndexSchema) + { + } +}; + +// default kvStoreDelegateManager's config. +const DistributedDB::KvStoreConfig KV_CONFIG = { + .dataDir = DIRECTOR +}; + +class DistributedTestTools final { +public: + DistributedTestTools() {} + ~DistributedTestTools() {} + + // Delete the copy and assign constructors + DistributedTestTools(const DistributedTestTools &distributeDBTools) = delete; + DistributedTestTools& operator=(const DistributedTestTools &distributeDBTools) = delete; + DistributedTestTools(DistributedTestTools &&distributeDBTools) = delete; + DistributedTestTools& operator=(DistributedTestTools &&distributeDBTools) = delete; + + // this static method is to compare if the two Value has the same data. + static bool IsValueEquals(const DistributedDB::Value &v1, const DistributedDB::Value &v2); + static DistributedDB::KvStoreDelegate::Option TransferKvOptionType(const KvOption &optionParam); + static DistributedDB::KvStoreDelegate* GetDelegateSuccess(DistributedDB::KvStoreDelegateManager *&outManager, + const KvDBParameters ¶m, const KvOption &optionParam); + static DistributedDB::KvStoreDelegate* GetDelegateStatus(DistributedDB::KvStoreDelegateManager *&outManager, + DistributedDB::DBStatus &status, const KvDBParameters ¶m, const KvOption &optionParam); + + static DistributedDB::DBStatus GetDelegateNotGood( + DistributedDB::KvStoreDelegateManager *&outManager, DistributedDB::KvStoreDelegate *&outDelegate, + const std::string &storeId, const std::string &appId, const std::string &userId, const KvOption &optionParam); + + static DistributedDB::DBStatus Put(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const DistributedDB::Key &key, const DistributedDB::Value &value); + + static DistributedDB::DBStatus PutBatch(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const std::vector &entries); + + static DistributedDB::DBStatus Delete(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const DistributedDB::Key &key); + + static DistributedDB::DBStatus DeleteBatch(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const std::vector &keys); + + static DistributedDB::DBStatus Clear(DistributedDB::KvStoreDelegate &kvStoreDelegate); + + static DistributedDB::KvStoreSnapshotDelegate *GetKvStoreSnapshot(DistributedDB::KvStoreDelegate &kvStoreDelegate); + static DistributedDB::Value Get(DistributedDB::KvStoreDelegate &kvStoreDelegate, const DistributedDB::Key &key); + static DistributedDB::Value Get(DistributedDB::KvStoreSnapshotDelegate &kvStoreSnapshotDelegate, + const DistributedDB::Key &key); + + static std::vector GetEntries( + DistributedDB::KvStoreSnapshotDelegate &kvStoreSnapshotDelegate, const DistributedDB::Key &key); + static std::vector GetEntries(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const DistributedDB::Key &keyPrefix); + + static DistributedDB::KvStoreSnapshotDelegate *RegisterSnapObserver(DistributedDB::KvStoreDelegate *delegate, + DistributedDB::KvStoreObserver *observer); + static DistributedDB::DBStatus RegisterObserver(DistributedDB::KvStoreDelegate *delegate, + DistributedDB::KvStoreObserver *observer); + static DistributedDB::DBStatus UnRegisterObserver(DistributedDB::KvStoreDelegate *delegate, + DistributedDB::KvStoreObserver *observer); + static bool CalculateOpenPerformance(PerformanceData &performanceData); + static bool CalculateInsertPerformance(PerformanceData &performanceData); + static bool CalculateGetPutPerformance(PerformanceData &performanceData); + static bool CalculateUpdatePerformance(PerformanceData &performanceData); + static bool CalculateGetUpdatePerformance(PerformanceData &performanceData); + static bool CalculateUseClearPerformance(PerformanceData &performanceData); + static bool CalculateTransactionPerformance(PerformanceData &performanceData); + static bool CloseAndRelease(DistributedDB::KvStoreDelegateManager *&manager, + DistributedDB::KvStoreDelegate *&delegate); + static bool CloseAndRelease(DistributedDB::KvStoreDelegateManager *&manager, + DistributedDB::KvStoreNbDelegate *&delegate); + static bool VerifyDbRecordCnt(DistributedDB::KvStoreNbDelegate *&delegate, unsigned int recordCnt, + bool isLocal = false); + static bool VerifyRecordsInDb(DistributedDB::KvStoreNbDelegate *&delegate, + std::vector &entriesExpected, + const std::vector &keyPrefix = DistributedDBDataGenerator::KEY_EMPTY, bool isLocal = false); + static bool GetRecordCntByKey(const std::string &dbName, + const std::string &strSql, std::vector &sqlParam, KvOption &option, int &count); + static bool QuerySpecifiedData(const std::string &dbName, const std::string &strSql, + EncrypteAttribute &attribute, int &count); + static bool RepeatCheckAsyncResult(const std::function &inPred, int repeatLimit, + uint32_t repeatInterval); + static bool CompareKey(const DistributedDB::Entry &entry1, const DistributedDB::Entry &entry2); + static void CopyFile(const std::string &srcFile, const std::string &destFile); +}; + +std::string TransferStringToHashHexString(const std::string &origStr); + +int RemoveDatabaseDirectory(const std::string &directory); + +bool VerifyObserverResult(const KvStoreObserverImpl &pObserver, + int changedTimes, ListType type, const std::list &lst, + uint32_t timeout = DistributedDBDataGenerator::DistributedDBConstant::THIRTY_MINUTES); +bool VerifyObserverResult(const KvStoreObserverImpl &pObserver, + int changedTimes, ListType type, const std::vector &vec, + uint32_t timeout = DistributedDBDataGenerator::DistributedDBConstant::THIRTY_MINUTES); +bool VerifyObserverForSchema(const KvStoreObserverImpl &pObserver, + int changedTimes, ListType type, const std::vector &expectEntry, + uint32_t timeout = DistributedDBDataGenerator::DistributedDBConstant::THIRTY_MINUTES); +#endif // DISTRIBUTED_DB_MODULE_TEST_TOOLS_H diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_constant.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_constant.h new file mode 100644 index 0000000000000000000000000000000000000000..4f50a04dc4d9c93c91694e9bc87e96a682d5114a --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_constant.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2021 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 DISTRIBUTEDDB_CONSTANT_DEFINE_H +#define DISTRIBUTEDDB_CONSTANT_DEFINE_H + +#include +#include "store_types.h" + +namespace DistributedDBDataGenerator { +const int TEST_ID_1 = 1; +const int TEST_ID_2 = 2; +const int TEST_ID_3 = 3; +const int TEST_ID_4 = 4; +const int TEST_ID_5 = 5; +const int TEST_ID_6 = 6; +const int TEST_ID_7 = 7; +const int TEST_ID_8 = 8; +const int TEST_ID_9 = 9; +const int TEST_ID_10 = 10; +const int TEST_ID_11 = 11; +const int TEST_ID_12 = 12; +const int TEST_ID_13 = 13; +const int TEST_ID_14 = 14; +const int TEST_ID_15 = 15; +const int TEST_ID_16 = 16; +const int TEST_ID_17 = 17; +const int TEST_ID_18 = 18; +const int TEST_ID_19 = 19; +const int TEST_ID_20 = 20; +const int TEST_ID_21 = 21; +const int TEST_ID_22 = 22; +const int TEST_ID_23 = 23; +const int TEST_ID_24 = 24; +const int TEST_ID_25 = 25; +const int TEST_ID_26 = 26; +const int TEST_ID_27 = 27; +const int TEST_ID_28 = 28; +const int TEST_ID_29 = 29; +const int TEST_ID_30 = 30; +const int TEST_ID_31 = 31; +const int TEST_ID_32 = 32; +const int TEST_ID_33 = 33; +const int TEST_ID_34 = 34; +const int TEST_ID_35 = 35; +const int TEST_ID_36 = 36; +const int TEST_ID_37 = 37; +const int TEST_ID_38 = 38; +const int TEST_ID_39 = 39; +const int TEST_ID_40 = 40; +const int TEST_ID_41 = 41; +const int TEST_ID_42 = 42; +const int TEST_ID_43 = 43; +const int TEST_ID_44 = 44; +const int TEST_ID_45 = 45; +const int TEST_ID_46 = 46; +const int TEST_ID_47 = 47; +const int TEST_ID_48 = 48; +const int TEST_ID_49 = 49; +const int TEST_ID_50 = 50; +const int TEST_ID_51 = 51; +const int TEST_ID_52 = 52; + +class DistributedDBConstant { +public: + static const std::string NB_DIRECTOR; // default work dir. + static const std::string NB_DATABASE_NAME; + static const std::string NORMAL_COMMON_SCHEMA; + static const std::string COMPATIBLE_FOR_NORMAL_COMMON_SCHEMA; + static const std::string UNCOMPATIBLE_FOR_NORMAL_COMMON_SCHEMA; + // default kvStoreDelegateManager's config. + static const DistributedDB::KvStoreConfig CONFIG; + static const std::string DB_FILE_DOCUMENT; + static constexpr int UNLOCK_ACCESS = 0; + static constexpr int LOCKED_ACCESS = 1; + static constexpr uint32_t THIRTY_MINUTES = 1800; + static constexpr uint32_t WAIT_UNTIL_CALLBACK_COME = 0; + +// ************************ SYNC PACKET ************************************ + static constexpr int ZERO_PACKET = 0; + static constexpr int ONE_PACKET = 1; + static constexpr int TWO_PACKETS = 2; + static constexpr int THREE_PACKETS = 3; + static constexpr int FOUR_PACKETS = 4; + static constexpr int EIGHT_PACKETS = 8; + static constexpr int FIRST_PACKET = 1; + static constexpr int THIRD_PACKET = 3; + static constexpr int FIFTH_PACKET = 5; + static constexpr int EIGHTH_PACKET = 8; + static constexpr uint32_t THROW_PACKET_CNT_LEN = 168; // the length of data packet is greater than 168 + // the length of registering subscriber packet is greater than 111 + static constexpr uint32_t REGISTER_SUBSCRIBER_PACKET_LEN = 111; + +// ************************ MILLISECOND ************************************ + static const unsigned int THREE_S_TO_MS = 3000; + static const unsigned int FIVE_S_TO_MS = 5000; + static const unsigned int EIGHT_S_TO_MS = 8000; + static const unsigned int NINE_S_TO_MS = 9000; + static const unsigned int TEN_S_TO_MS = 10000; + static const unsigned int SIXTY_S_TO_MS = 60000; + +// ************************ compression ratio ************************** + static const unsigned int COMPRESSION_RATIO_ZERO = 0; + static const unsigned int COMPRESSION_RATIO_TEN = 10; + static const unsigned int COMPRESSION_RATIO_TWENTY = 20; + static const unsigned int COMPRESSION_RATIO_THIRTY = 30; + static const unsigned int COMPRESSION_RATIO_FORTY = 40; + static const unsigned int COMPRESSION_RATIO_FIFTY = 50; + static const unsigned int COMPRESSION_RATIO_SIXTY = 60; + static const unsigned int COMPRESSION_RATIO_SEVENTY = 70; + static const unsigned int COMPRESSION_RATIO_EIGHTY = 80; + static const unsigned int COMPRESSION_RATIO_NINETY = 90; + static const unsigned int COMPRESSION_RATIO_ONE_HUNDRED = 100; + static const unsigned int COMPRESSION_RATIO_ONE_HUNDRED_AND_ONE = 101; + +// ************************ record number ************************** + static const unsigned int THIRTY_THOUSAND_RECORDS = 30000; +}; +} // namespace DistributedDBDataGenerator + +#endif // DISTRIBUTEDDB_CONSTANT_DEFINE_H diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_data_generator.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_data_generator.h new file mode 100644 index 0000000000000000000000000000000000000000..e348cc4981c0476a4370a262587662422c36261a --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_data_generator.h @@ -0,0 +1,567 @@ +/* + * Copyright (c) 2021 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 DISTRIBUTED_DB_MODULE_TEST_TYPES_H +#define DISTRIBUTED_DB_MODULE_TEST_TYPES_H + +#include +#include +#include +#include "kv_store_delegate.h" +#include "kv_store_delegate_manager.h" +#include "distributed_test_sysinfo.h" +#include "distributeddb_log_print.h" +#include "distributeddb_constant.h" + +struct EntrySize { + unsigned int keySize = 0; + unsigned int valSize = 0; + void Set(unsigned int keySizeInput, unsigned int valSizeInput) + { + this->keySize = keySizeInput; + this->valSize = valSizeInput; + } +}; + +enum DBTypeInner { + UNENCRYPTED_DISK_DB = 0, + ENCRYPTED_DISK_DB, + MEMORY_DB +}; + +struct TimeSamp { + std::vector startTime; + std::vector endTime; + TimeSamp() + { + } +}; + +struct ImagePerSamp { + std::vector firstStep; + std::vector secondStep; + ImagePerSamp() + { + } +}; + +struct PerTimeLength { + std::vector entriesDuration; + std::vector cursorDuration; + std::vector moveNextDuration; + std::vector entryDurationForward; + std::vector movePreviousDuration; + std::vector entryDurationBackup; +}; + +struct Schema { + std::vector version; + std::vector mode; + std::vector define; + std::vector index; +}; +struct LongDefine { + int recordNum; + int recordSize; + char prefix; +}; + +struct NumberSize { + EntrySize entrySize; + int recordsNumber; + bool isRoundBack = false; + NumberSize() : recordsNumber(0) + { + } +}; + +enum class RandType { + ALPHA_NUM, + ALPHA_NUM_UNDERLINE, + SPECIAL, +}; + +// ************************ number class ********************************** +const unsigned int OBSERVER_NUM = 8; +const int BUFFER_COUNT = 5; +const unsigned int NB_OBSERVER_NUM = 4; +const unsigned int NB_OPERATION_NUM = 100; +const unsigned int NB_PREDATA_NUM = 50; +const unsigned int RECORDS_SMALL_CNT = 2; +const unsigned int NO_RECORD = 0; +const unsigned int THREE_RECORDS = 3; +const unsigned int THREE_PERF_DATA = 3; +const unsigned int BATCH_RECORDS = 128; +const static int ONE_RECORD = 1; +const static int TWO_RECORDS = 2; +const static int FOUR_RECORDS = 4; +const static int FIVE_RECORDS = 5; +const static int SIX_RECORDS = 6; +const static int EIGHT_RECORDS = 8; +const static int NINE_RECORDS = 9; +const static int TEN_RECORDS = 10; +const static int SIXTEEN_RECORDS = 16; +const static int TWENTY_RECORDS = 20; +const static int THIRTY_RECORDS = 30; +const static int THIRTYTWO_RECORDS = 32; +const static int FORTY_RECORDS = 40; +const static int FIFTY_RECORDS = 50; +const static int SIXTY_RECORDS = 60; +const static int EIGHTY_RECORDS = 80; +const static int ONE_HUNDRED_RECORDS = 100; +const static int TWO_HUNDREDS_RECORDS = 200; +const static int FIVE_HUNDREDS_RECORDS = 500; +const static int SIX_HUNDREDS_RECORDS = 600; +const static int ONE_THOUSAND_RECORDS = 1000; +const static int TWO_THOUSANDS_RECORDS = 2000; +const static int TWO_FIVE_ZERO_ZERO_RECORDS = 2500; +const static int TWO_FIVE_SIX_ZERO_RECORDS = 2560; +const static int FIVE_THOUSANDS_RECORDS = 5000; +const static int TEN_THOUSAND_RECORDS = 10000; +const static int FIFTEEN_THOUSAND_RECORDS = 15000; +const static int TWENTY_THOUSAND_RECORDS = 20000; +const static int THIRTY_THOUSAND_RECORDS = 30000; +const static int FIFTY_THOUSAND_RECORDS = 50000; +const static int HUNDRED_THOUSAND_RECORDS = 100000; +const static int FOUR_HUNDRED_THOUSAND_RECORDS = 400000; +const static int FIVE_HUNDRED_THOUSAND_RECORDS = 500000; +const static int TWO_FIVE_SIX_RECORDS = 256; +const static int FIRST_RECORD = 1; +const static int SECOND_RECORD = 2; +const static int DATAS_ACCOUNT = 300; +const static int DATA_LEN = 13; +const static int NINE_CNT = 9; +const static int TEN_CNT = 10; +const static unsigned int TWO_DEVICES = 2; +const static unsigned int FOUR_DEVICES = 4; +const static int THIRD_FUNC = 3; +const static int FOURTH_FUNC = 4; +const static int FIFTH_FUNC = 5; +const static int THREE_DBS = 3; +const static int EIGHT_DBS = 8; +const static int TEN_DBS = 10; +const static int ELEVEN_DBS = 11; +const static int TWELVE_DBS = 12; +const static int FIRST_DB = 1; +const static int FIFTH_DB = 5; +const static int TENTH_DB = 10; +const static int ELEVENTH_DB = 11; +const static int TWELFTH_DB = 12; + +// ************************ loop times class ************************** +const unsigned int MOD_NUM = 2; +const unsigned int BIG_MOD_NUM = 3; + +const unsigned int ID_CNT_START = 0; +const unsigned int ID_MIN_CNT = 2; +const unsigned int ID_MEDIUM_CNT = 3; +const unsigned int ID_MAX_CNT = 16; +const unsigned int STORE_CNT = 4; +const unsigned int DIR_CNT_START = 0; +const unsigned int DIR_MAX_CNT = 14; +const static int MANYTINES = 3; +const static int ONE_TIME = 1; +const static int TWO_TIMES = 2; +const static int FIVE_TIMES = 5; +const static int TEN_TIMES = 10; +const static int FIFTY_TIMES = 50; +const static int HUNDRED_TIMES = 100; + +// ************************ time class ************************** +const unsigned int UNIQUE_SECOND = 1; +const unsigned int TWO_SECONDS = 2; +const unsigned int THREE_SECONDS = 3; +const unsigned int FOUR_SECONDS = 4; +const unsigned int FIVE_SECONDS = 5; +const unsigned int SIX_SECONDS = 6; +const unsigned int TEN_SECONDS = 10; +const unsigned int FIFTEEN_SECONDS = 15; +const unsigned int TWENTY_SECONDS = 20; +const unsigned int THIRTY_SECONDS = 30; +const unsigned int FORTY_SECONDS = 40; +const unsigned int SIXTY_SECONDS = 60; +const unsigned int ONE_HUNDRED_SECONDS = 100; +const unsigned int TWO_HUNDREDS_SECONDS = 200; +const unsigned int THREE_HUNDREDS_SECONDS = 300; +const unsigned int FOUR_HUNDREDS_SECONDS = 400; +const unsigned int FIVE_HUNDREDS_SECONDS = 500; +const unsigned int SIX_HUNDREDS_SECONDS = 600; +const unsigned int SEVEN_HUNDREDS_SECONDS = 700; +const unsigned int EIGHT_HUNDREDS_SECONDS = 800; +const unsigned int TEN_HUNDREDS_SECONDS = 1000; +const unsigned int ONE_FIVE_ZERO_ZERO_SECONDS = 1500; +const unsigned int SIXTEEN_HUNDREDS_SECONDS = 1600; +const unsigned int EIGHTEEN_HUNDREDS_SECONDS = 1800; +const unsigned int TWENTY_HUNDREDS_SECONDS = 2000; +const unsigned int THREE_THOUSANDS_SECONDS = 3000; +const unsigned int THREE_SIX_ZERO_ZERO_SECONDS = 3600; +const unsigned int EIGHT_THOUSANDS_SECONDS = 8000; +const unsigned int TEN_THOUSANDS_SECONDS = 10000; +const unsigned int WAIT_FOR_LONG_TIME = 15000; +const unsigned int WAIT_FOR_FIFTY_MS = 50000; +const unsigned int WAIT_FOR_LAST_SYNC = 500000; +const unsigned int WAIT_FOR_TWO_HUNDREDS_MS = 200000; +const int FIFTY_MILI_SECONDS = 50; +const int HUNDRED_MILLI_SECONDS = 100; +const static int MILLSECONDS_PER_SECOND = 1000; + +// ************************ length of key class ************************** +const static int KEY_SIX_BYTE = 6; +const static int KEY_EIGHT_BYTE = 8; +const static int KEY_THIRTYTWO_BYTE = 32; +const static int KEY_SIXTYFOUR_BYTE = 64; +const static int KEY_TWO_FIVE_SIX_BYTE = 256; +const static int KEY_ONE_K_BYTE = 1024; +const static int KEY_ONE_HUNDRED_BYTE = 100; + +// ************************ length of value class ************************** +const unsigned int SMALL_VALUE_SIZE = 2; +const unsigned int ONE_K_LONG_STRING = 1024; // 1K +const unsigned int TWO_K_LONG_STRING = 2048; // 2K +const unsigned int TWO_POINT_FOUR_LONG = 2400; // 2.4K +const unsigned int THREE_K_LONG_STRING = 3072; // 3K +const unsigned int FOUR_K_LONG_STRING = 4096; // 4K +const unsigned int ONE_M_LONG_STRING = 1048576; // 1M +const unsigned int TWO_M_LONG_STRING = 2097152; // 2M +const unsigned int FOUR_M_LONG_STRING = 4194304; // 4M +const unsigned int TEN_M_LONG_STRING = 10485760; // 10M +const static int VALUE_SIX_BYTE = 6; +const static int VALUE_ONE_HUNDRED_BYTE = 100; +const static int VALUE_FIVE_HUNDRED_BYTE = 500; +const static int VALUE_ONE_K_BYTE = 1024; +const static int VALUE_HUNDRED_K_BYTE = 102400; +const static int VALUE_TWENTY_K_BYTE = 20480; +const static int VALUE_TWO_POINT_FOUR_K_BYTE = 2458; +const static int PASSWD_BYTE = 129; + +// ************************ bool class ************************************* +const bool IS_LOCAL_ONLY = true; +const bool IS_NOT_LOCAL_ONLY = false; +const bool IS_NEED_CREATE = true; +const bool IS_NOT_NEED_CREATE = false; + +// ************************ range verify class ***************************** +const static int CHANGED_ZERO_TIME = 0; +const static int CHANGED_ONE_TIME = 1; +const static int CHANGED_TWO_TIMES = 2; +const static int CHANGED_THREE_TIMES = 3; +const static int CHANGED_ONE_HUNDRED_TIMES = 100; +const static int CHANGED_TWO_HUNDRED_TIMES = 200; +const static int CHANGED_TWO_FIVE_SIX_TIMES = 256; +const static int CHANGED_ONE_THOUSAND_TIMES = 1000; +const static int CHANGED_TEN_THOUSAND_TIMES = 10000; +const unsigned int RECORDS_NUM_START = 1; +const unsigned int RECORDS_NUM_END = 128; +const unsigned int DEFAULT_START = 1; +const unsigned int DEFAULT_ANOTHER_START = 11; +const unsigned int OBSERVER_CNT_START = 0; +const unsigned int OBSERVER_CNT_END = 8; +const unsigned int NB_OBSERVER_CNT_START = 0; +const unsigned int NB_OBSERVER_CNT_END = 4; +const unsigned int NB_OPERATION_CNT_START = 0; +const unsigned int NB_OPERATION_CNT_END = 5; + +const int LOCAL_OPER_CNT = 2; +const int NATIVE_OPER_CNT = 6; +const static int OPER_CNT_START = 0; +const static int OPER_CNT_END = 10; +const static int MODE_RAND_MIN = 0; +const static int MODE_RAND_MAX = 2; + +// ************************ USED FOR THREAD ******************************** +const unsigned int SINGLE_THREAD_NUM = 2; +const unsigned int CHAR_SPAN_MIN = 0; +const unsigned int CHAR_SPAN_MAX = 255; + +// ************************ USED FOR INDEX ********************************* +const int INDEX_ZEROTH = 0; +const int INDEX_FIRST = 1; +const int INDEX_SECOND = 2; +const int INDEX_THIRD = 3; +const int INDEX_FORTH = 4; +const int INDEX_FIFTH = 5; +const int INDEX_SIXTH = 6; +const int INDEX_SEVENTH = 7; +const int INDEX_EIGHTTH = 8; +const int INDEX_NINTH = 9; +const int INDEX_TENTH = 10; +const int INDEX_NINE_NINE_NINTH = 999; +const int INDEX_FIVE_THOUSANDS = 5000; +const int INDEX_TEN_THOUSANDS = 10000; +const int INDEX_FIFTEEN_THOUSANDS = 15000; + +// ************************ OTHER CLASS ************************************ +const int TABLE_MAX = 60; + +const static int ENCRYPT_COUNT = 100; + +const static int EVEN_NUMBER = 2; + +const int VALUE_FIVE_HUNDRED = 500; +const int VALUE_SUM = VALUE_FIVE_HUNDRED + VALUE_FIVE_HUNDRED; +const int VALUE_CHANGE1_FIRST = 400; +const int VALUE_CHANGE1_SECOND = VALUE_SUM - VALUE_CHANGE1_FIRST; +const int VALUE_CHANGE2_FIRST = 700; +const int VALUE_CHANGE2_SECOND = VALUE_SUM - VALUE_CHANGE2_FIRST; + +const static std::string MULTIDB = "/multi_ver/value_storage.db"; +const static std::string KVMULTIDB = "/multi_ver/multi_ver_data.db"; +const static std::string SYNC_MULTI_VER_QUERY_SQL = "select count(*) from version_data;"; +const static std::string DATABASE_INFOR_FILE = "/single_ver/main/gen_natural_store.db"; +const static std::string SYNC_VALUE_SLICE_QUERY_SQL = "select count(*) from data;"; +const static std::string QUERY_SQL = "select count(*) from version_data where key = ?;"; +const static std::string MULTI_KEY_QUERY_SQL = "select count(*) from version_data where key = ? or key = ?;"; + +typedef std::chrono::time_point microClock_type; + +// place some const values for testcases in namespace. +namespace DistributedDBDataGenerator { +const std::string STORE_ID = ""; +const std::string STORE_ID_1 = "STORE_ID_1"; +const std::string STORE_ID_2 = "STORE_ID_2"; +const std::string STORE_ID_3 = "STORE_ID_3"; +const std::string STORE_ID_4 = "STORE_ID_4"; +const std::string STORE_ID_5 = "STORE_ID_5"; +const std::string STORE_ID_6 = "STORE_ID_6"; +const std::string STORE_ID_7 = "STORE_ID_7"; +const std::string STORE_ID_8 = "STORE_ID_8"; +const std::string STORE_ID_9 = "STORE_ID_9"; +const std::string STORE_ID_10 = "STORE_ID_10"; +const std::string JSON_SCHEMA_STORE_ID_11 = "JSON_SCHEMA_STORE_ID_11"; +const std::string STORE_ID_PERFORM = "STORE_ID_PERFORM"; +const static std::string STORE_ID_SYNC_1 = "SYNC1"; +const static std::string STORE_ID_SYNC_2 = "SYNC2"; +const static std::string STORE_ID_SYNC_3 = "SYNC3"; +const static std::string STORE_ID_SYNC_4 = "SYNC4"; +const static std::string STORE_ID_SYNC_5 = "SYNC5"; +const static std::string STORE_ID_SYNC_6 = "SYNC6"; +const static std::string STORE_ID_SYNC_7 = "SYNC7"; +const static std::string STORE_ID_SYNC_8 = "SYNC8"; +const static std::string STORE_ID_SYNC_9 = "SYNC9"; +const static std::string STORE_ID_SYNC_10 = "SYNC10"; + +const std::string APP_ID = "APP_ID"; +const std::string APP_ID_1 = "APP_ID_1"; +const std::string APP_ID_2 = "APP_ID_2"; +const std::string APP_ID_3 = "APP_ID_3"; +const std::string APP_ID_4 = "APP_ID_4"; +const std::string APP_ID_5 = "APP_ID_5"; +const std::string APP_ID_6 = "APP_ID_6"; +const std::string APP_ID_PERFORM = "APP_ID_PERFORM"; +const std::string APP_ID_NB_1 = "APP_ID_NB_1"; +const std::string APP_ID_NB_2 = "APP_ID_NB_2"; +const std::string APP_ID_LOCAL_1 = "APP_ID_LOCAL_1"; + +const std::string USER_ID = "USER_ID"; +const std::string USER_ID_1 = "USER_ID_1"; +const std::string USER_ID_2 = "USER_ID_2"; +const std::string USER_ID_3 = "USER_ID_3"; +const std::string USER_ID_4 = "USER_ID_4"; +const std::string USER_ID_5 = "USER_ID_5"; +const std::string USER_ID_6 = "USER_ID_6"; +const std::string USER_ID_PERFORM = "USER_ID_PERFORM"; + +const std::vector K1_HASH_KEY = { 0xA2, 0xAB, 0x19, 0x59, 0xC1, 0xC3, 0xBF, 0xA2, 0x95, 0xB0, 0xFC, 0x90, + 0x19, 0x93, 0x78, 0x27, 0x2D, 0xB7, 0x6B, 0x45}; +const std::vector K2_HASH_KEY = { 0xBF, 0xEB, 0x73, 0x4D, 0x2E, 0xB5, 0xD0, 0x91, 0x51, 0x45, 0xC1, 0x86, + 0x12, 0x48, 0x75, 0x7D, 0x4F, 0xD3, 0x2B, 0xC2 }; +const std::vector K3_HASH_KEY = { 0xB5, 0x32, 0xA5, 0x44, 0x0D, 0xD8, 0x42, 0x2D, 0x9D, 0x5F, 0x8D, 0x99, + 0x9B, 0x31, 0x06, 0x87, 0xD4, 0xA2, 0xFE, 0xD9 }; +const std::vector K4_HASH_KEY = { 0x5E, 0xF8, 0x76, 0x6D, 0xE9, 0x35, 0x32, 0x44, 0x24, 0xB5, 0x63, 0xAA, + 0x3E, 0xB0, 0xC7, 0x46, 0x6B, 0x29, 0x3C, 0x94 }; +const std::vector NULL_HASH_KEY = {}; +const DistributedDB::Key KEY_1 = { 'k', '1' }; +const DistributedDB::Key KEY_2 = { 'k', '2' }; +const DistributedDB::Key KEY_3 = { 'k', '3' }; +const DistributedDB::Key KEY_4 = { 'k', '4' }; +const DistributedDB::Key KEY_5 = { 'k', '5' }; +const DistributedDB::Key KEY_6 = { 'k', '6' }; +const DistributedDB::Key KEY_7 = { 'k', '7' }; +const DistributedDB::Key KEY_8 = { 'k', '8' }; +const DistributedDB::Key KEY_9 = { 'k', '9' }; +const DistributedDB::Key KEY_10 = { 'k', '1', '0' }; +const DistributedDB::Key KEY_6_BYTE = { 'k', 'k', 'k', 'k', 'k', '1' }; +const DistributedDB::Key KEY_A_1 = { 'a', 'b', 'c' }; +const DistributedDB::Key KEY_A_2 = { 'a', 'b', 'c', 'd', 'a', 's', 'd' }; +const DistributedDB::Key KEY_A_3 = { 'a', 'b', 'c', 'd', 's' }; +const DistributedDB::Key KEY_BIG_1 = { 'b', 'i', 'g', '1' }; + +const std::vector NULL_K1 = {}; +const DistributedDB::Key KEY_EMPTY = { }; +const DistributedDB::Key KEY_K = { 'k' }; +const DistributedDB::Key KEY_A = { 'a' }; +const DistributedDB::Key KEY_E = { 'k', 'e' }; +const DistributedDB::Key OK_KEY_1 = { 'o', 'k' }; + +const DistributedDB::Value VALUE_1 = { 'v', '1' }; +const DistributedDB::Value VALUE_2 = { 'v', '2' }; +const DistributedDB::Value VALUE_3 = { 'v', '3' }; +const DistributedDB::Value VALUE_4 = { 'v', '4' }; +const DistributedDB::Value VALUE_5 = { 'v', '5' }; +const DistributedDB::Value VALUE_6 = { 'v', '6' }; +const DistributedDB::Value VALUE_7 = { 'v', '7' }; +const DistributedDB::Value VALUE_8 = { 'v', '8' }; +const DistributedDB::Value VALUE_9 = { 'v', '9' }; +const DistributedDB::Value VALUE_10 = { 'v', '1', '0' }; +const DistributedDB::Value VALUE_A_1 = { 'a', '1' }; +const DistributedDB::Value VALUE_A_2 = { 'a', '2' }; +const DistributedDB::Value VALUE_A_3 = { 'a', '3' }; +const DistributedDB::Value VALUE_EMPTY = { }; +const DistributedDB::Value OK_VALUE_1 = { 'o', 'k' }; + +const std::vector IMAGE_KEY_PRE = {'a', 'l', 'b', 'u', 'm', '_'}; +const std::vector IMAGE_FILE_KEY_PRE = {'f', 'i', 'l', 'e', '_'}; +const std::string IMAGE_VALUE_PRE = {"\"_id\":23,\"local_media_id\":0," \ + "\"_data\":\"/storage/emulated/0/Pictures/.Gallery2/recycle/GF6DA7BR\"," \ + "\"_size\":427460,\"date_added\":1518606965,\"date_modified\":1519460678," \ + "\"mime_type\":\"image/jpeg\",\"title\":\"MagazinePic-05-2.3.001-bigpicture_05_4\"," \ + "\"description\":\"\",\"_display_name\":\"MagazinePic-05-2.3.001-bigpicture_05_4.jpg\"," \ + "\"orientation\":0,\"latitude\":0,\"longitude\":0,\"datetaken\":1514792938000," \ + "\"bucket_id\":771419238,\"bucket_display_name\":\"MagazineUnlock\",\"duration\":0," \ + "\"resolution\":\"1440x2560\",\"media_type\":1,\"storage_id\":65537,\"width\":1440," \ + "\"height\":2560,\"is_hdr\":0,\"is_hw_privacy\":0,\"hw_voice_offset\":0,\"is_hw_favorite\":0," \ + "\"hw_image_refocus\":0,\"is_hw_burst\":0,\"hw_rectify_offset\":0,\"contenturi\":\"\"," \ + "\"hash\":\"e46cf1bb4773421fbded2e2583fe7130\",\"special_file_list\":0,\"special_file_type\":0," \ + "\"special_file_offset\":0,\"relative_bucket_id\":1793967153,\"albumId\":\"default-album-3\",\"fileType\":1," \ + "\"fileId\":0,\"videoThumbId\":0,\"thumbId\":0,\"lcdThumbId\":0,\"thumbType\":3,\"localThumbPath\":\"\"," \ + "\"localBigThumbPath\":\"\",\"expand\":\"\",\"showDateToken\":1514792938000,\"visit_time\":0," \ + "\"last_update_time\":1519461225861,\"source\":\"\",\"geo_code\":0,\"location_key\":104473884060," \ + "\"story_id\":0,\"story_cluster_state\":\"todo\",\"search_data_status\":0,\"category_id\":-2," \ + "\"portrait_id\":0,\"portrait_cluster_state\":\"todo\",\"dirty\":0,\"recycleFlag\":2," \ + "\"recycledTime\":1519550100614,\"sourcePath\":\"/storage/emulated/0/MagazineUnlock/MagazinePic\"," \ + "\"sourceFileName\":\"MagazinePic-05-2.3.001-bigpict\",\"garbage\":0,\"uniqueId\":0,\"localKey\":\"\"," \ + "\"picture_score\":99,\"cam_perception\":\"\",\"cam_exif_flag\":1,\"sync_status\":0," \ + "\"album_name\":\".MagazineUnlock\",\"ocr_status\":0"}; + +const DistributedDB::Key KEY_SEARCH_0 = KEY_A; +const DistributedDB::Key KEY_SEARCH = { 'a', 'b' }; +const DistributedDB::Key KEY_SEARCH_2 = { 'a', 'b', 'c', 'd', 'e' }; +const std::vector K_SEARCH_3 = { 'b', 'i', 'g'}; +const DistributedDB::Key KEY_SEARCH_3 = { 'b', 'i', 'g'}; +const DistributedDB::Key KEY_SEARCH_4 = { 'k' }; +const std::vector K_SEARCH_5 = { 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k' }; +const DistributedDB::Key KEY_SEARCH_6 = { 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', '6' }; +const DistributedDB::Key PERFORMANCEKEY = { 'p', 'e', 'r' }; +const DistributedDB::Key KEY_CONS_1 = { 'c', 'o', 'n', 's', '1' }; +const DistributedDB::Key KEY_CONS_2 = { 'c', 'o', 'n', 's', '2' }; +const DistributedDB::Key KEY_BATCH_CONS_1 = { 'r', 'e', 's', 'u', 'l', 't', '1' }; +const DistributedDB::Key KEY_BATCH_CONS_2 = { 'r', 'e', 's', 'u', 'l', 't', '2' }; +const DistributedDB::Key KEY_BATCH_CONS_3 = { 'r', 'e', 's', 'u', 'l', 't', '3' }; +const std::vector KEYS_1 = { KEY_1, KEY_2 }; +const DistributedDB::Entry ENTRY_1 = { .key = KEY_1, .value = VALUE_1 }; +const DistributedDB::Entry ENTRY_2 = { .key = KEY_2, .value = VALUE_2 }; +const DistributedDB::Entry ENTRY_3 = { .key = KEY_3, .value = VALUE_3 }; +const DistributedDB::Entry ENTRY_4 = { .key = KEY_4, .value = VALUE_4 }; +const DistributedDB::Entry ENTRY_5 = { .key = KEY_5, .value = VALUE_5 }; +const DistributedDB::Entry ENTRY_6 = { .key = KEY_6, .value = VALUE_6 }; +const DistributedDB::Entry ENTRY_7 = { .key = KEY_7, .value = VALUE_7 }; +const DistributedDB::Entry ENTRY_8 = { .key = KEY_8, .value = VALUE_8 }; +const DistributedDB::Entry ENTRY_9 = { .key = KEY_9, .value = VALUE_9 }; +const DistributedDB::Entry ENTRY_10 = { .key = KEY_10, .value = VALUE_10 }; +const DistributedDB::Entry ENTRY_1_2 = { .key = KEY_1, .value = VALUE_2 }; +const DistributedDB::Entry ENTRY_2_3 = { .key = KEY_2, .value = VALUE_3 }; +const DistributedDB::Entry ENTRY_3_1 = { .key = KEY_3, .value = VALUE_1 }; +const DistributedDB::Entry ENTRY_4_5 = { .key = KEY_4, .value = VALUE_5 }; +const DistributedDB::Entry ENTRY_5_6 = { .key = KEY_5, .value = VALUE_6 }; +const DistributedDB::Entry ENTRY_2_1 = { .key = KEY_2, .value = VALUE_1 }; +const DistributedDB::Entry ENTRY_1_3 = { .key = KEY_1, .value = VALUE_3 }; +const DistributedDB::Entry ENTRY_2_4 = { .key = KEY_2, .value = VALUE_4 }; +const DistributedDB::Entry ENTRY_1_4 = { .key = KEY_1, .value = VALUE_4 }; +const DistributedDB::Entry ENTRY_3_4 = { .key = KEY_3, .value = VALUE_4 }; +const DistributedDB::Entry ENTRY_1_NULL = { .key = KEY_1, .value = VALUE_EMPTY }; +const DistributedDB::Entry ENTRY_2_NULL = { .key = KEY_2, .value = VALUE_EMPTY }; +const DistributedDB::Entry ENTRY_3_NULL = { .key = KEY_3, .value = VALUE_EMPTY }; +const DistributedDB::Entry ENTRY_NULL_1 = { .key = KEY_EMPTY, .value = VALUE_2 }; +const DistributedDB::Entry ENTRY_NULL_2 = { .key = KEY_EMPTY, .value = VALUE_3 }; +const DistributedDB::Entry ENTRY_NULL_3 = { .key = KEY_EMPTY, .value = VALUE_1 }; +const DistributedDB::Entry ENTRY_NULL = { .key = KEY_EMPTY, .value = VALUE_EMPTY }; +const DistributedDB::Entry ENTRY_A_1 = { .key = KEY_A_1, .value = VALUE_A_1 }; +const DistributedDB::Entry ENTRY_A_2 = { .key = KEY_A_2, .value = VALUE_A_2 }; +const DistributedDB::Entry ENTRY_A_3 = { .key = KEY_A_3, .value = VALUE_A_3 }; +const DistributedDB::Entry ENTRY_A_1_2 = { .key = KEY_A_1, .value = VALUE_A_2 }; +const DistributedDB::Entry ENTRY_A_2_3 = { .key = KEY_A_2, .value = VALUE_A_3 }; +const DistributedDB::Entry ENTRY_A_3_1 = { .key = KEY_A_3, .value = VALUE_A_1 }; + +const DistributedDB::CipherPassword NULL_PASSWD; +const std::vector NULL_PASSWD_VECTOR = {}; +const std::vector PASSWD_VECTOR_1 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'd', '@', '1', '2', '3'}; +const std::vector PASSWD_VECTOR_2 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'd', '@', 'c', 'o', 'm'}; +const std::vector FILE_PASSWD_VECTOR_1 = {'F', 'i', 'l', 'e', 'p', 'a', 's', 's', 'w', 'd', '1'}; +const std::vector FILE_PASSWD_VECTOR_2 = {'F', 'i', 'l', 'e', 'p', 'a', 's', 's', 'w', 'd', '2'}; + +void GenerateRecord(unsigned int keyNo, DistributedDB::Entry &entry, std::vector keyPrifix = { 'k' }); + +void GenerateCharSet(std::vector &charSet); + +void GenerateAlphaNumUnderlineCharSet(std::vector &charSet); + +void GenerateSpecialCharSet(std::vector &charSet); + +void GenerateFixedLenRandString(unsigned int neededLen, RandType randType, std::string &genString); + +void GenerateRandRecord(DistributedDB::Entry &entry, EntrySize &entrySize, unsigned int keyNo); + +void GenerateRecords(unsigned int recordNum, unsigned int start, + std::vector &allKeys, std::vector &entriesBatch, + std::vector keyPrifix = { 'k' }); +void GenerateMaxBigRecord(unsigned int keyNo, DistributedDB::Entry &entry, + const std::vector &keyPrefix, unsigned int num); +bool GenerateMaxBigRecords(unsigned int recordNum, unsigned int start, + std::vector &allKeys, std::vector &entriesBatch); + +void GenerateTenThousandRecords(unsigned int recordNum, unsigned int start, + std::vector &allKeys, std::vector &entriesBatch); + +void GenerateNormalAsciiRecords(DistributedDB::Entry &entry); + +void GenerateFullAsciiRecords(DistributedDB::Entry &entry); + +void GenerateBiggistKeyRecords(DistributedDB::Entry &entry); + +DistributedDB::Entry GenerateFixedLenKVRecord(unsigned int serialNo, + unsigned int keyLen, uint8_t keyFilledChr, unsigned int valueLen, uint8_t valueFilledChr); + +void GenerateFixedRecords(std::vector &entries, std::vector &allKeys, + int recordNum, unsigned int keySize, unsigned int valSize); + +void GenerateOneRecordForImage(int entryNo, const EntrySize &entrySize, + const std::vector &keyPrefix, const std::vector &val, DistributedDB::Entry &entry); +void GenerateRecordsForImage(std::vector &entries, EntrySize &entrySize, + int num, std::vector keyPrefix = {'k'}, std::vector val = {'v'}); + +void GenerateAppointPrefixAndSizeRecord(int recordNo, const EntrySize &entrySize, + const std::vector &keyPrefix, const std::vector &valPrefix, DistributedDB::Entry &entry); +void GenerateAppointPrefixAndSizeRecords(std::vector &entries, const EntrySize &entrySize, + int num, const std::vector &keyPrefix = {'k'}, const std::vector &valPrefix = {'v'}); +void GenerateAppointPrefixAndSizeRecords(std::vector &entries, int startpoint, + const NumberSize param, const std::vector &keyPrefix = {'k'}, + const std::vector &valPrefix = {'v'}); + +int GetRandInt(const int randMin, const int randMax); + +void GenerateFixedLenRandRecords(std::vector &entries, std::vector &allKeys, + int recordNum, unsigned int keySize, unsigned int valSize); +std::vector GenerateFixedLenRandRecords(std::vector &allKeys, + int recordNum, const EntrySize &entrySize, const std::vector &keyPrefix = {'k'}, + const std::vector &valPrefix = {'v'}); + +const std::string GetDbType(const int type); +void GenerateRandomRecords(std::vector &entries, EntrySize &entrySize, int num); +void GetLongSchemaDefine(LongDefine ¶m, std::string &longDefine); +const std::string SpliceToSchema(const std::string &version, const std::string &mode, + const std::string &define, const std::string &index = "", const std::string &skipSize = ""); +std::vector GetValidSchema(Schema &validSchema, bool hasIndex); +std::map> GetInvalidSchema(Schema &invalidSchema, Schema &validSchema, bool hasIndex); +} // DistributedDBDataGenerator +#endif // DISTRIBUTED_DB_MODULE_TEST_TYPES_H diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_log_print.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_log_print.h new file mode 100644 index 0000000000000000000000000000000000000000..7f8a56d2a25090ca91fc86257d7440f79c373f80 --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_log_print.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021-2022 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 DISTRIBUTED_DB_LOG_PRINT_H +#define DISTRIBUTED_DB_LOG_PRINT_H + +#if defined _WIN32 + #ifndef RUNNING_ON_WIN + #define RUNNING_ON_WIN + #endif +#else + #ifndef RUNNING_ON_LINUX + #define RUNNING_ON_LINUX + #endif +#endif + +#include "hilog/log.h" + +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, 0xD001630, "DistributedDB[TEST]" }; +#define MST_LOG(fmt, ...) \ + OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%s: " fmt, __FUNCTION__, ##__VA_ARGS__) +#endif diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h new file mode 100644 index 0000000000000000000000000000000000000000..fdc8b858a60e52de5bedaa3eb327e35b97b9dc04 --- /dev/null +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2021 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 DISTRIBUTEDDB_NB_TEST_TOOLS_H +#define DISTRIBUTEDDB_NB_TEST_TOOLS_H + +#include "kv_store_delegate.h" +#include "kv_store_delegate_manager.h" +#include "kv_store_nb_delegate.h" +#include "kv_store_observer.h" +#ifdef RELEASE_MODE_V2 +#include "query.h" +#endif +#include "distributeddb_data_generator.h" +#include "distributed_test_tools.h" + +struct DBParameters { + std::string storeId; + std::string appId; + std::string userId; + DBParameters(std::string storeIdStr, std::string appIdStr, std::string userIdStr) + : storeId(storeIdStr), appId(appIdStr), userId(userIdStr) + { + } +}; + +struct Option { + bool createIfNecessary = true; + bool isMemoryDb = false; // true represents using a memory database + bool isEncryptedDb = false; // whether need encrypt + DistributedDB::CipherType cipher = DistributedDB::CipherType::DEFAULT; // cipher type + std::vector passwd; // cipher password +#ifdef RELEASE_MODE_V2 + std::string schema; + bool createDirByStoreIdOnly = false; +#endif // endif of RELEASE_MODE_V2 +#ifdef RELEASE_MODE_V3 + DistributedDB::SecurityOption secOption; + DistributedDB::KvStoreObserver *observer = nullptr; + DistributedDB::Key key; + unsigned int mode = 0; + int conflictType = 0; + DistributedDB::KvStoreNbConflictNotifier notifier = nullptr; + int conflictResolvePolicy = DistributedDB::LAST_WIN; + bool isNeedIntegrityCheck = false; + bool isNeedRmCorruptedDb = false; + bool isNeedCompressOnSync = false; + uint8_t compressionRate = 100; // default compression rate 100%, that means not compressing +#endif // end of RELEASE_MODE_V3 + Option(bool createIfNecessary, bool isMemoryDb, bool isEncryptedDb, DistributedDB::CipherType cipher, + std::vector passwd) + : createIfNecessary(createIfNecessary), isMemoryDb(isMemoryDb), isEncryptedDb(isEncryptedDb), + cipher(cipher), passwd(passwd) + { + } +#ifdef RELEASE_MODE_V3 + Option(bool createIfNecessary, bool isMemoryDb, bool isEncryptedDb, const DistributedDB::CipherType &cipher, + const std::vector &passwd, const DistributedDB::SecurityOption &secOption, + DistributedDB::KvStoreObserver *observer, const DistributedDB::KvStoreNbConflictNotifier ¬ifier) + : createIfNecessary(createIfNecessary), isMemoryDb(isMemoryDb), isEncryptedDb(isEncryptedDb), + cipher(cipher), passwd(passwd), secOption(secOption), observer(observer), notifier(notifier) + { + } +#endif // endif of RELEASE_MODE_V3 + Option() + {} +}; + +struct ConflictData { + DistributedDB::KvStoreNbConflictType type; + DistributedDB::Key key; + DistributedDB::Value oldValue; + DistributedDB::Value newValue; + bool oldIsDeleted = false; + bool newIsDeleted = false; + bool oldIsNative = false; + bool newIsNative = false; +}; + +enum EntryType { + INSERT_LOCAL = 0, + INSERT_NATIVE = 1, + DELETE_LOCAL = 2, + DELETE_NATIVE = 3, + UPDATE_LOCAL = 4, + UPDATE_NATIVE = 5 +}; + +enum class ReadOrWriteTag { + READ = 0, + WRITE = 1, + DELETE = 2, + REGISTER = 3 +}; + +const static DBParameters g_dbParameter1(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters g_dbParameter2(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_2); +const static DBParameters g_dbParameter3(DistributedDBDataGenerator::STORE_ID_3, + DistributedDBDataGenerator::APP_ID_3, DistributedDBDataGenerator::USER_ID_3); +const static DBParameters g_dbParameter4(DistributedDBDataGenerator::STORE_ID_4, + DistributedDBDataGenerator::APP_ID_4, DistributedDBDataGenerator::USER_ID_4); +const static DBParameters g_dbParameter5(DistributedDBDataGenerator::STORE_ID_5, + DistributedDBDataGenerator::APP_ID_5, DistributedDBDataGenerator::USER_ID_5); +const static DBParameters g_dbParameter6(DistributedDBDataGenerator::STORE_ID_6, + DistributedDBDataGenerator::APP_ID_6, DistributedDBDataGenerator::USER_ID_6); +const static DBParameters g_dbParameter2_1(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters DB_PARAMETER_0_1(DistributedDBDataGenerator::STORE_ID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters g_dbParameter1_2_1(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters g_dbParameter2_1_2(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_2); +const static DBParameters g_dbParameter3_2_1(DistributedDBDataGenerator::STORE_ID_3, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters g_dbParameter4_2_2(DistributedDBDataGenerator::STORE_ID_4, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_2); +const static Option g_createDiskUnencrypted(true, false, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +const static Option g_createDiskEncrypted(true, false, true, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::PASSWD_VECTOR_1); +const static Option g_ncreateDiskUnencrypted(false, false, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +const static Option g_ncreateDiskEncrypted(false, false, true, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::PASSWD_VECTOR_1); +const static Option g_createMemUnencrypted(true, true, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +static Option g_option = g_createDiskUnencrypted; +const std::vector