From 1a3e03132779513382619bb02ce602fcdfee1303 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Tue, 13 Jun 2023 15:14:30 +0800 Subject: [PATCH 1/7] remove the config and unused code Signed-off-by: Sven Wang --- bundle.json | 4 +- conf/BUILD.gn | 4 +- datamgr_service.gni | 2 + .../adapter/autils/BUILD.gn | 43 ---- .../adapter/autils/src/constant.cpp | 124 ------------ .../adapter/autils/src/directory_utils.cpp | 164 ---------------- .../autils/src/thread_pool/kv_store_task.cpp | 40 ---- .../src/thread_pool/kv_store_thread.cpp | 60 ------ .../autils/src/thread_pool/kv_store_thread.h | 40 ---- .../src/thread_pool/kv_store_thread_pool.cpp | 38 ---- .../thread_pool/kv_store_thread_pool_impl.cpp | 111 ----------- .../thread_pool/kv_store_thread_pool_impl.h | 53 ----- .../adapter/autils/test/BUILD.gn | 48 ----- .../unittest/kv_store_thread_pool_test.cpp | 130 ------------- .../communicator/src/softbus_adapter.h | 1 - .../adapter/include/autils/constant.h | 184 ------------------ .../adapter/include/autils/directory_utils.h | 50 ----- .../adapter/include/autils/kv_store_task.h | 39 ---- .../include/autils/kv_store_thread_pool.h | 46 ----- .../include/autils/platform_specific.h | 25 --- .../adapter/include/autils/time_utils.h | 38 ---- .../app/src/kvstore_data_service.cpp | 48 +---- .../app/src/kvstore_data_service.h | 36 ---- .../app/src/kvstore_meta_manager.cpp | 3 +- .../app/src/security/security.cpp | 3 +- .../distributeddataservice/service/BUILD.gn | 1 - .../service/kvdb/executor_factory.cpp | 46 ----- .../service/kvdb/executor_factory.h | 36 ---- 28 files changed, 11 insertions(+), 1406 deletions(-) delete mode 100755 services/distributeddataservice/adapter/autils/BUILD.gn delete mode 100644 services/distributeddataservice/adapter/autils/src/constant.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/directory_utils.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_task.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.h delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.h delete mode 100755 services/distributeddataservice/adapter/autils/test/BUILD.gn delete mode 100644 services/distributeddataservice/adapter/autils/test/unittest/kv_store_thread_pool_test.cpp delete mode 100644 services/distributeddataservice/adapter/include/autils/constant.h delete mode 100644 services/distributeddataservice/adapter/include/autils/directory_utils.h delete mode 100644 services/distributeddataservice/adapter/include/autils/kv_store_task.h delete mode 100644 services/distributeddataservice/adapter/include/autils/kv_store_thread_pool.h delete mode 100644 services/distributeddataservice/adapter/include/autils/platform_specific.h delete mode 100644 services/distributeddataservice/adapter/include/autils/time_utils.h delete mode 100644 services/distributeddataservice/service/kvdb/executor_factory.cpp delete mode 100644 services/distributeddataservice/service/kvdb/executor_factory.h diff --git a/bundle.json b/bundle.json index 586e02e19..c8b8c56e3 100644 --- a/bundle.json +++ b/bundle.json @@ -38,7 +38,9 @@ "name": "datamgr_service", "subsystem": "distributeddatamgr", "syscap": [], - "features": [], + "features": [ + "datamgr_service_config" + ], "adapted_system_type": [ "standard" ], diff --git a/conf/BUILD.gn b/conf/BUILD.gn index 0e9037c6c..14f7ca2ca 100644 --- a/conf/BUILD.gn +++ b/conf/BUILD.gn @@ -15,7 +15,9 @@ import("//build/ohos_var.gni") #/system/etc/distributeddata/conf group("build_module") { - deps = [ ":default_conf" ] + if (datamgr_service_config) { + deps = [ ":default_conf" ] + } } ohos_prebuilt_etc("default_conf") { source = "config.json" diff --git a/datamgr_service.gni b/datamgr_service.gni index 2537c5685..7ef3974eb 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -45,4 +45,6 @@ declare_args() { } else { os_account_part_is_enabled = false } + + datamgr_service_config = true; } diff --git a/services/distributeddataservice/adapter/autils/BUILD.gn b/services/distributeddataservice/adapter/autils/BUILD.gn deleted file mode 100755 index 48efe8f54..000000000 --- a/services/distributeddataservice/adapter/autils/BUILD.gn +++ /dev/null @@ -1,43 +0,0 @@ -# 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/ohos.gni") -import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") - -ohos_static_library("distributeddata_autils_static") { - sources = [ - "src/constant.cpp", - "src/directory_utils.cpp", - "src/thread_pool/kv_store_task.cpp", - "src/thread_pool/kv_store_thread.cpp", - "src/thread_pool/kv_store_thread_pool.cpp", - "src/thread_pool/kv_store_thread_pool_impl.cpp", - ] - - include_dirs = [ - "../include/autils", - "../include/log", - "../include/dfx", - "${kv_store_common_path}", - ] - - cflags_cc = [ "-fvisibility=hidden" ] - - external_deps = [ - "c_utils:utils", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", - ] - subsystem_name = "distributeddatamgr" - part_name = "datamgr_service" - defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] -} diff --git a/services/distributeddataservice/adapter/autils/src/constant.cpp b/services/distributeddataservice/adapter/autils/src/constant.cpp deleted file mode 100644 index f393d354c..000000000 --- a/services/distributeddataservice/adapter/autils/src/constant.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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. - */ - -#include "constant.h" -#include -#include -#include - -namespace OHOS { -namespace DistributedKv { -// the Key Prefix for Meta data of KvStore. -const std::string KvStoreMetaRow::KEY_PREFIX = "KvStoreMetaData"; - -const std::string SecretMetaRow::KEY_PREFIX = "SecretKey"; - -/* version for distributed kv data service. */ -const std::string Constant::VERSION = "1"; - -/* meta name for distributed kv data service. */ -const std::string Constant::META_DIR_NAME = "Meta"; - -/* name for distributed kv data service. */ -const std::string Constant::SERVICE_NAME = "mdds"; - -/* root path for distributed kv data service. */ -const std::string Constant::ROOT_PATH = "/data/misc_de/0"; - -/* root path for distributeddata service and system services. */ -const std::string Constant::ROOT_PATH_DE = "/data/misc_de/0"; - -/* root path for self-developed and non-self-developed app. */ -const std::string Constant::ROOT_PATH_CE = "/data/misc_ce/0"; - -// the max length for key is 1024. -const size_t Constant::MAX_KEY_LENGTH = 1024; - -// the max length for StoreId is 128. -const size_t Constant::MAX_STORE_ID_LENGTH = 128; - -// the max length for value is 4M. -const size_t Constant::MAX_VALUE_LENGTH = 4 * 1024 * 1024; - -// the max batch for putBatch is 128. -const size_t Constant::MAX_BATCH_SIZE = 128; - -// the max capacity for ipc is 800K. -const size_t Constant::MAX_IPC_CAPACITY = 800 * 1024; - -// the default mode is 0755, stands for r/w/x for user, r/x for group, r/x for others. -const mode_t Constant::DEFAULT_MODE = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - -// the mode for dir is 0755, r/w/x for user, r/-/x for group, r/-/x for others. -const mode_t Constant::DEFAULT_MODE_DIR = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - -// the mode for file is 0600, r/w/- for user, -/-/- for group, -/-/- for others. -const mode_t Constant::DEFAULT_MODE_FILE = S_IRUSR | S_IWUSR; - -// Size threshold of switching to large data is a little smaller than MAX_IPC_CAPACITY. -const int Constant::SWITCH_RAW_DATA_SIZE = 700 * 1024; - -const int Constant::MAX_OPEN_KVSTORES = 16; - -// default group id for synchronization. -const std::string Constant::DEFAULT_GROUP_ID = "default"; - -// true indicates the ownership of distributed data is DEVICE, otherwise, ACCOUNT -const bool Constant::STOREID_ONLY_FLAG = true; - -// service meta db name. -const std::string Constant::SERVICE_META_DB_NAME = "service_meta"; - -const std::string Constant::KEY_SEPARATOR = "###"; - -const std::string Constant::ROOT_KEY_GENERATED = "RootKeyGenerated"; - -std::vector KvStoreMetaRow::GetKeyFor(const std::string &key) -{ - std::string str = Constant::Concatenate({KvStoreMetaRow::KEY_PREFIX, Constant::KEY_SEPARATOR, key }); - return std::vector(str.begin(), str.end()); -} - -std::vector SecretMetaRow::GetKeyFor(const std::string &key) -{ - std::string str = Constant::Concatenate({SecretMetaRow::KEY_PREFIX, Constant::KEY_SEPARATOR, key }); - return std::vector(str.begin(), str.end()); -} - -std::string Constant::Concatenate(std::initializer_list stringList) -{ - std::string result; - size_t result_size = 0; - for (const std::string &str : stringList) { - result_size += str.size(); - } - result.reserve(result_size); - for (const std::string &str : stringList) { - result.append(str.data(), str.size()); - } - return result; -} - -std::string Constant::GetDefaultDeviceAccountId() -{ - return "0"; -} - -std::string Constant::GetDefaultHarmonyAccountName() -{ - return "default"; -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/directory_utils.cpp b/services/distributeddataservice/adapter/autils/src/directory_utils.cpp deleted file mode 100644 index b12626106..000000000 --- a/services/distributeddataservice/adapter/autils/src/directory_utils.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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. - */ - -#define LOG_TAG "DirectoryUtils" - -#include "directory_utils.h" -#include -#include -#include "log_print.h" -#include "unistd.h" - -namespace OHOS { -namespace DistributedKv { -// change the mode of all files in the specified directory recursively. -bool DirectoryUtils::ChangeModeFileOnly(const std::string &path, const mode_t &mode) -{ - ZLOGI("begin."); - std::string subPath; - bool ret = true; - DIR *dir = opendir(path.c_str()); - if (dir == nullptr) { - return false; - } - - while (true) { - struct dirent *ptr = readdir(dir); - if (ptr == nullptr) { - break; - } - - // skip current directory and parent directory. - if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) { - continue; - } - - subPath = IncludeDelimiterAtPathTail(path) + std::string(ptr->d_name); - if (ptr->d_type == DT_DIR) { - ret = ChangeModeFileOnly(subPath, mode); - continue; - } - - // change the mode of file only. - if ((access(subPath.c_str(), F_OK) == 0) && (ptr->d_type == DT_REG)) { - ZLOGD("[Von-Debug]change the file[%s] to mode[%d].", subPath.c_str(), mode); - if (!ChangeMode(subPath, mode)) { - closedir(dir); - ZLOGD("[Von-Debug]change the file[%s] to mode[%d] failed.", subPath.c_str(), mode); - return false; - } - } - } - closedir(dir); - return ret; -} - -// change the mode of all subdirectories in the specified directory recursively. -bool DirectoryUtils::ChangeModeDirOnly(const std::string &path, const mode_t &mode) -{ - ZLOGI("begin."); - std::string subPath; - bool ret = true; - DIR *dir = opendir(path.c_str()); - if (dir == nullptr) { - return false; - } - - while (true) { - struct dirent *ptr = readdir(dir); - if (ptr == nullptr) { - break; - } - - // skip current directory and parent directory. - if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) { - continue; - } - - subPath = IncludeDelimiterAtPathTail(path) + std::string(ptr->d_name); - if (ptr->d_type == DT_DIR) { - ret = ChangeModeDirOnly(subPath, mode); - continue; - } - - // change the mode of directory only. - if ((access(subPath.c_str(), F_OK) == 0) && (ptr->d_type == DT_DIR)) { - ZLOGD("[Von-Debug]change the dir[%s] to mode[%d].", subPath.c_str(), mode); - if (!ChangeMode(subPath, mode)) { - closedir(dir); - ZLOGD("[Von-Debug]change the dir[%s] to mode[%d] failed.", subPath.c_str(), mode); - return false; - } - } - } - closedir(dir); - - std::string currentPath = ExcludeDelimiterAtPathTail(path); - if (access(currentPath.c_str(), F_OK) == 0) { - if (!ChangeMode(currentPath, mode)) { - return false; - } - } - return ret; -} - -// create all subdirectories in the specified directory recursively. -bool DirectoryUtils::CreateDirectory(const std::string &path) -{ - std::string::size_type index = 0; - do { - std::string subPath; - index = path.find('/', index + 1); - if (index == std::string::npos) { - subPath = path; - } else { - subPath = path.substr(0, index); - } - - if (access(subPath.c_str(), F_OK) != 0) { - if (mkdir(subPath.c_str(), (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != 0) { - return false; - } - } - } while (index != std::string::npos); - - return access(path.c_str(), F_OK) == 0; -} - -// exclude separators '/' at the end of the path. -std::string DirectoryUtils::ExcludeDelimiterAtPathTail(const std::string &path) -{ - if (path.rfind('/') != path.size() - 1) { - return path; - } - - if (!path.empty()) { - return path.substr(0, static_cast(path.size()) - 1); - } - - return path; -} - -// include separators '/' at the end of the path. -std::string DirectoryUtils::IncludeDelimiterAtPathTail(const std::string &path) -{ - if (path.rfind('/') != path.size() - 1) { - return path + "/"; - } - - return path; -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_task.cpp b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_task.cpp deleted file mode 100644 index b6de8ace9..000000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_task.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -#define LOG_TAG "KvStoreTask" - -#include "kv_store_task.h" -#include "log_print.h" - -namespace OHOS { -namespace DistributedKv { -KvStoreTask::KvStoreTask(std::function lambda) -{ - task_ = std::move(lambda); - name_ = std::string(); -} - -KvStoreTask::KvStoreTask(std::function lambda, const std::string &taskName) -{ - task_ = std::move(lambda); - name_ = taskName; -} - -void KvStoreTask::operator()() -{ - task_(); -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.cpp b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.cpp deleted file mode 100644 index 52efe42d0..000000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -#define LOG_TAG "KvStoreThread" - -#include "kv_store_thread_pool_impl.h" -#include "log_print.h" -#include "pthread.h" - -namespace OHOS { -namespace DistributedKv { -KvStoreThread::KvStoreThread(KvStoreThreadPool *threadPool, const std::string &name) -{ - realThread_ = std::thread([this, threadPool, name]() { - // this makes me unconfortable: this lambda capture 'this' by reference, and right after this call this object - // is move-constructed, so when we call this in Run(), we are actually refer to the old object. we can still - // use all its non-virtual function, but all arguments and virtual-function are not available. - int32_t ret = pthread_setname_np(pthread_self(), name.c_str()); - if (ret != 0) { - ZLOGE("Failed to set thread name:%{public}s, ret:%{public}d.", name.c_str(), ret); - } - Run(threadPool); - }); -} - -void KvStoreThread::Run(KvStoreThreadPool *pool) -{ - if (pool == nullptr) { - ZLOGW("input param is null."); - return; - } - - auto impl = reinterpret_cast(pool); - while (impl->IsRunning()) { - impl->ScheduleTask()(); - } - ZLOGW("stop"); -} - -void KvStoreThread::Join() -{ - realThread_.join(); -} - -KvStoreThread::~KvStoreThread() -{} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.h b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.h deleted file mode 100644 index c0c745bde..000000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 KV_STORE_THREAD_H -#define KV_STORE_THREAD_H - -#include -#include "kv_store_thread_pool.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreThread { -public: - explicit KvStoreThread(KvStoreThreadPool *threadPool, const std::string &name); - KvStoreThread(KvStoreThread &&thread) = delete; - KvStoreThread(const KvStoreThread &) = delete; - KvStoreThread &operator=(KvStoreThread &&) = delete; - KvStoreThread &operator=(const KvStoreThread &) = delete; - void Run(KvStoreThreadPool *threadPool); - void Join(); - ~KvStoreThread(); -private: - std::thread realThread_; -}; -} // namespace DistributedKv -} // namespace OHOS - -#endif // KV_STORE_THREAD_H diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool.cpp b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool.cpp deleted file mode 100644 index d8ccdc62a..000000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ - -#define LOG_TAG "KvStoreThreadPool" - -#include "kv_store_thread_pool_impl.h" -#include "log_print.h" - -namespace OHOS { -namespace DistributedKv { -std::shared_ptr KvStoreThreadPool::GetPool(int poolSize, std::string poolName, bool startImmediately) -{ - std::shared_ptr poolImpl = - std::make_shared(poolSize, std::move(poolName), startImmediately); - if (poolImpl == nullptr) { - return nullptr; - } - return std::shared_ptr(std::dynamic_pointer_cast(poolImpl)); -} - -std::string KvStoreThreadPool::GetPoolName() -{ - return poolName_; -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.cpp b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.cpp deleted file mode 100644 index 7a8ad6b83..000000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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. - */ - -#define LOG_TAG "KvStoreThreadPoolImpl" -#include "kv_store_thread_pool_impl.h" - -#include -#include -#include - -#include "kv_store_thread.h" -#include "log_print.h" - -namespace OHOS { -namespace DistributedKv { -KvStoreThreadPoolImpl::~KvStoreThreadPoolImpl() -{ - Stop(); -} - -void KvStoreThreadPoolImpl::Start() -{ - ZLOGI("start"); - running = true; - for (int i = 0; i < threadNum; i++) { - threadList.emplace_back(this, poolName_.substr(0, MAX_THREAD_NAME_SIZE) + "_" + std::to_string(i)); - } -} - -void KvStoreThreadPoolImpl::Stop() -{ - ZLOGW("stop"); - if (!running) { - return; - } - { - std::unique_lock lock(taskListMutex); - running = false; - for (auto task = taskList.begin(); task != taskList.end(); task++) { - ZLOGI("running task in stop()"); - (*task)(); - ZLOGI("running task finish"); - } - taskList.clear(); - } - has_task.notify_all(); - for (auto thread = threadList.begin(); thread != threadList.end(); thread++) { - thread->Join(); - } -} - -bool KvStoreThreadPoolImpl::IsRunning() const -{ - return running; -} - -KvStoreThreadPoolImpl::KvStoreThreadPoolImpl(int threadNum, std::string poolName, bool startImmediately) - : taskList(), threadList(), threadNum(threadNum) -{ - this->poolName_ = poolName; - if (threadNum <= 0 || threadNum > MAX_POOL_SIZE) { - this->threadNum = DEFAULT_POOL_SIZE; - } - if (startImmediately) { - Start(); - } -} - -bool KvStoreThreadPoolImpl::AddTask(KvStoreTask &&task) -{ - ZLOGD("start"); - if (threadList.empty()) { - Start(); - } - std::unique_lock lock(taskListMutex); - if (!running) { - return false; - } - taskList.push_back(std::move(task)); - has_task.notify_one(); - return true; -} - -KvStoreTask KvStoreThreadPoolImpl::ScheduleTask() -{ - std::unique_lock lock(taskListMutex); - if (taskList.empty() && running) { - has_task.wait(lock, [&]() {return !running || !taskList.empty(); }); - } - if (taskList.empty()) { - ZLOGW("taskList empty. schedule empty task(pool stopping?)"); - return KvStoreTask([]() {;}); - } - KvStoreTask ret = std::move(taskList.front()); - taskList.pop_front(); - return ret; -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.h b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.h deleted file mode 100644 index 10051ff1f..000000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 KV_STORE_THREAD_POOL_IMPL_H -#define KV_STORE_THREAD_POOL_IMPL_H - -#include -#include -#include -#include "kv_store_thread_pool.h" -#include "kv_store_thread.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreThreadPoolImpl : public KvStoreThreadPool { -public: - KvStoreThreadPoolImpl(int threadNum, std::string poolName, bool startImmediately); - KvStoreThreadPoolImpl() = delete; - KvStoreThreadPoolImpl(const KvStoreThreadPoolImpl &) = delete; - KvStoreThreadPoolImpl(KvStoreThreadPoolImpl &&) = delete; - KvStoreThreadPoolImpl& operator=(const KvStoreThreadPoolImpl &) = delete; - KvStoreThreadPoolImpl& operator=(KvStoreThreadPoolImpl &&) = delete; - bool AddTask(KvStoreTask &&task) override; - void Stop() final; - KvStoreTask ScheduleTask(); - bool IsRunning() const; - virtual ~KvStoreThreadPoolImpl(); -private: - std::mutex taskListMutex{}; - std::list taskList{}; - std::condition_variable has_task{}; - std::list threadList{}; - int threadNum; - void Start(); - bool running = false; - static constexpr int MAX_THREAD_NAME_SIZE = 11; -}; -} // namespace DistributedKv -} // namespace OHOS - -#endif // KV_STORE_THREAD_POOL_IMPL_H diff --git a/services/distributeddataservice/adapter/autils/test/BUILD.gn b/services/distributeddataservice/adapter/autils/test/BUILD.gn deleted file mode 100755 index afd7c605f..000000000 --- a/services/distributeddataservice/adapter/autils/test/BUILD.gn +++ /dev/null @@ -1,48 +0,0 @@ -# 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 = "datamgr_service/distributeddatafwk" - -############################################################################### -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "../../include/autils/", - "//foundation/distributeddatamgr/kv_store/frameworks/common", - ] - defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] -} - -ohos_unittest("KvStoreThreadPoolTest") { - module_out_path = module_output_path - - sources = [ "unittest/kv_store_thread_pool_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ - "../../autils:distributeddata_autils_static", - "//third_party/googletest:gtest_main", - ] -} - -group("unittest") { - testonly = true - - deps = [] - - deps += [ ":KvStoreThreadPoolTest" ] -} -############################################################################### diff --git a/services/distributeddataservice/adapter/autils/test/unittest/kv_store_thread_pool_test.cpp b/services/distributeddataservice/adapter/autils/test/unittest/kv_store_thread_pool_test.cpp deleted file mode 100644 index f95274403..000000000 --- a/services/distributeddataservice/adapter/autils/test/unittest/kv_store_thread_pool_test.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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. - */ - -#include -#include -#include -#include -#include "kv_store_thread_pool.h" - -using namespace testing::ext; -using namespace OHOS::DistributedKv; - -class KvStoreThreadPoolTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void KvStoreThreadPoolTest::SetUpTestCase(void) -{} - -void KvStoreThreadPoolTest::TearDownTestCase(void) -{} - -void KvStoreThreadPoolTest::SetUp(void) -{} - -void KvStoreThreadPoolTest::TearDown(void) -{} - -/** - * @tc.name: TestApplyTask001 - * @tc.desc: test if task can be done asynchronous. - * @tc.type: FUNC - * @tc.require: AR000CQS31 - * @tc.author: liqiao - */ -HWTEST_F(KvStoreThreadPoolTest, TestApplyTask001, TestSize.Level1) -{ - auto pool = KvStoreThreadPool::GetPool(8, "Task001", true); - int var = 0; - auto start = std::chrono::system_clock::now(); - pool->AddTask(KvStoreTask([&var](){ - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - var++; - })); - auto end = std::chrono::system_clock::now(); - std::chrono::duration returnTime = end - start; - EXPECT_LT(returnTime.count(), 0.05); - EXPECT_EQ(var, 0); - std::this_thread::sleep_for(std::chrono::milliseconds(150)); - EXPECT_EQ(var, 1); -} - -/** - * @tc.name: TestApplyTask002 - * @tc.desc: test if task can be done in different thread. - * @tc.type: FUNC - * @tc.require: AR000CQS31 - * @tc.author: liqiao - */ -HWTEST_F(KvStoreThreadPoolTest, TestApplyTask002, TestSize.Level2) -{ - auto pool = KvStoreThreadPool::GetPool(2, "Task002", false); - int var = 0; - std::mutex varMutex; - auto start = std::chrono::system_clock::now(); - KvStoreTask task([&](){ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::lock_guard lock(varMutex); - var++; - }); - for (int i = 0; i < 8; i++) { - pool->AddTask(KvStoreTask(task)); - } - auto end = std::chrono::system_clock::now(); - std::chrono::duration returnTime = end - start; - EXPECT_LT(returnTime.count(), 0.1); - EXPECT_EQ(var, 0); - std::this_thread::sleep_for(std::chrono::milliseconds(700)); - EXPECT_EQ(var, 2); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - EXPECT_EQ(var, 4); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - EXPECT_EQ(var, 6); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - EXPECT_EQ(var, 8); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - EXPECT_EQ(var, 8); - pool->Stop(); -} - -/** - * @tc.name: TestApplyTask003 - * @tc.desc: test whether task can be done if they are not scheduled when calling Stop(). - * @tc.type: FUNC - * @tc.require: AR000CQS31 - * @tc.author: liqiao - */ -HWTEST_F(KvStoreThreadPoolTest, TestApplyTask003, TestSize.Level1) -{ - auto pool = KvStoreThreadPool::GetPool(2, "Task003", false); - int var = 0; - std::mutex varMutex; - KvStoreTask task([&](){ - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - std::lock_guard lock(varMutex); - var++; - }); - for (int i = 0; i < 8; i++) { - pool->AddTask(KvStoreTask(task)); - } - EXPECT_EQ(var, 0); - pool->Stop(); - EXPECT_EQ(var, 8); -} diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h b/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h index 277d2d73d..868d5ed12 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h +++ b/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h @@ -28,7 +28,6 @@ #include "app_data_change_listener.h" #include "app_device_change_listener.h" #include "block_data.h" -#include "platform_specific.h" #include "session.h" #include "softbus_bus_center.h" #include "softbus_client.h" diff --git a/services/distributeddataservice/adapter/include/autils/constant.h b/services/distributeddataservice/adapter/include/autils/constant.h deleted file mode 100644 index 1d9748940..000000000 --- a/services/distributeddataservice/adapter/include/autils/constant.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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 KV_DATASERVICE_CONSTANT_H -#define KV_DATASERVICE_CONSTANT_H - -#include -#include -#include -#include -#include -#include -#include -#include "visibility.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreMetaRow { -public: - KVSTORE_API static const std::string KEY_PREFIX; - - KVSTORE_API static std::vector GetKeyFor(const std::string &key); -}; - -class SecretMetaRow { -public: - KVSTORE_API static const std::string KEY_PREFIX; - - KVSTORE_API static std::vector GetKeyFor(const std::string &key); -}; - -class Constant { -public: - // concatenate strings and return a composition string. - KVSTORE_API static std::string Concatenate(std::initializer_list stringList); - - // delete left bland in s by reference. - template - static void LeftTrim(T &s); - - // delete right bland in s by reference. - template - static void RightTrim(T &s); - - // delete both left and right bland in s by reference. - template - static void Trim(T &s); - - // delete left bland in s by reference, not change raw string. - template - static T LeftTrimCopy(T s); - - // delete right bland in s by reference, not change raw string. - template - static T RightTrimCopy(T s); - - // delete both left and right bland in s by reference, not change raw string. - template - static T TrimCopy(T s); - - // get default device account id. - KVSTORE_API static std::string GetDefaultDeviceAccountId(); - - // get default harmony account name. - KVSTORE_API static std::string GetDefaultHarmonyAccountName(); - - // default group id for synchronization based on harmony account. - KVSTORE_API static const std::string DEFAULT_GROUP_ID; - - // Indicates whether only storeid are used as hash materials for the DistributedDB path generated. - KVSTORE_API static const bool STOREID_ONLY_FLAG; - - // version for distributed kv data service. - KVSTORE_API static const std::string VERSION; - - // meta name for distributed kv data service. - KVSTORE_API static const std::string META_DIR_NAME; - - // name for distributed kv data service. - KVSTORE_API static const std::string SERVICE_NAME; - - // root path for distributed kv data service. - KVSTORE_API static const std::string ROOT_PATH; - - // root path for distributeddata service and system services. - KVSTORE_API static const std::string ROOT_PATH_DE; - - // root path for self-developed and non-self-developed app. - KVSTORE_API static const std::string ROOT_PATH_CE; - - // the max length for key is 256. - KVSTORE_API static const size_t MAX_KEY_LENGTH; - - // the max length for value is 1M. - KVSTORE_API static const size_t MAX_VALUE_LENGTH; - - // the max length for StoreId is 64. - KVSTORE_API static const size_t MAX_STORE_ID_LENGTH; - - // the max batch for putBatch is 128. - KVSTORE_API static const size_t MAX_BATCH_SIZE; - - // the max capacity for ipc is 800KB. - KVSTORE_API static const size_t MAX_IPC_CAPACITY; - - // service meta db name. - KVSTORE_API static const std::string SERVICE_META_DB_NAME; - - KVSTORE_API static const std::string KEY_SEPARATOR; - - KVSTORE_API static const mode_t DEFAULT_MODE; - - KVSTORE_API static const mode_t DEFAULT_MODE_DIR; - - KVSTORE_API static const mode_t DEFAULT_MODE_FILE; - - KVSTORE_API static const int SWITCH_RAW_DATA_SIZE; - - KVSTORE_API static const int MAX_OPEN_KVSTORES; - - // name for process label (bus name for communication). compatible with HwDDMP - KVSTORE_API static const std::string ROOT_KEY_GENERATED; -}; - -// trim from start (in place) -template -void Constant::LeftTrim(T &s) -{ - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); })); -} - -// trim from end (in place) -template -void Constant::RightTrim(T &s) -{ - s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end()); -} - -// trim from both ends (in place) -template -void Constant::Trim(T &s) -{ - LeftTrim(s); - RightTrim(s); -} - -// trim from start (copying) -template -T Constant::LeftTrimCopy(T s) -{ - LeftTrim(s); - return s; -} - -// trim from end (copying) -template -T Constant::RightTrimCopy(T s) -{ - RightTrim(s); - return s; -} - -// trim from both ends (copying) -template -T Constant::TrimCopy(T s) -{ - Trim(s); - return s; -} -} // namespace DistributedKv -} // namespace OHOS -#endif // KV_DATASERVICE_CONSTANT_H diff --git a/services/distributeddataservice/adapter/include/autils/directory_utils.h b/services/distributeddataservice/adapter/include/autils/directory_utils.h deleted file mode 100644 index 67ba84dda..000000000 --- a/services/distributeddataservice/adapter/include/autils/directory_utils.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 DIRECTORY_UTILS_H -#define DIRECTORY_UTILS_H - -#include -#include -#include "visibility.h" - -namespace OHOS { -namespace DistributedKv { -class DirectoryUtils { -public: - KVSTORE_API static bool ChangeModeFileOnly(const std::string &path, const mode_t &mode); - - KVSTORE_API static bool ChangeModeDirOnly(const std::string &path, const mode_t &mode); - - KVSTORE_API static bool CreateDirectory(const std::string &path); - -private: - DirectoryUtils() = default; - - ~DirectoryUtils() = default; - - static std::string ExcludeDelimiterAtPathTail(const std::string &path); - - static std::string IncludeDelimiterAtPathTail(const std::string &path); - - // change the mode of the specified file or directory. - static inline bool ChangeMode(const std::string &name, const mode_t &mode) - { - return (chmod(name.c_str(), mode) == 0); - } -}; -} // namespace DistributedKv -} // namespace OHOS -#endif // DIRECTORY_UTILS_H diff --git a/services/distributeddataservice/adapter/include/autils/kv_store_task.h b/services/distributeddataservice/adapter/include/autils/kv_store_task.h deleted file mode 100644 index 30891bb0d..000000000 --- a/services/distributeddataservice/adapter/include/autils/kv_store_task.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 KV_STORE_TASK_H -#define KV_STORE_TASK_H - -#include -#include -#include "visibility.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreTask { -public: - KVSTORE_API ~KvStoreTask() {} - KVSTORE_API KvStoreTask(std::function lambda); - KVSTORE_API KvStoreTask(std::function lambda, const std::string &taskName); - KVSTORE_API void operator()(); - -private: - std::function task_; - std::string name_; -}; -} // namespace DistributedKv -} // namespace OHOS - -#endif // TASK_H diff --git a/services/distributeddataservice/adapter/include/autils/kv_store_thread_pool.h b/services/distributeddataservice/adapter/include/autils/kv_store_thread_pool.h deleted file mode 100644 index 6b908a68b..000000000 --- a/services/distributeddataservice/adapter/include/autils/kv_store_thread_pool.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 KV_STORE_THREAD_POOL_H -#define KV_STORE_THREAD_POOL_H - -#include -#include "kv_store_task.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreThreadPool { -public: - KvStoreThreadPool(KvStoreThreadPool &&) = delete; - KvStoreThreadPool(const KvStoreThreadPool &) = delete; - KvStoreThreadPool &operator=(KvStoreThreadPool &&) = delete; - KvStoreThreadPool &operator=(const KvStoreThreadPool &) = delete; - KVSTORE_API virtual ~KvStoreThreadPool() {} - - KVSTORE_API static std::shared_ptr GetPool( - int poolSize, std::string poolName, bool startImmediately = false); - KVSTORE_API virtual void Stop() = 0; - KVSTORE_API virtual bool AddTask(KvStoreTask &&task) = 0; - KVSTORE_API static constexpr int MAX_POOL_SIZE = 64; // the max thread pool size - KVSTORE_API static constexpr int DEFAULT_POOL_SIZE = 8; // the default thread pool size - std::string GetPoolName(); -protected: - KvStoreThreadPool() = default; - std::string poolName_ = ""; -}; -} // namespace DistributedKv -} // namespace OHOS - -#endif // KV_STORE_THREAD_POOL_H diff --git a/services/distributeddataservice/adapter/include/autils/platform_specific.h b/services/distributeddataservice/adapter/include/autils/platform_specific.h deleted file mode 100644 index 6634dbf40..000000000 --- a/services/distributeddataservice/adapter/include/autils/platform_specific.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 PLATFORM_SPECIFIC_H -#define PLATFORM_SPECIFIC_H - -#if defined _WIN32 - #define OS_WINDOWS -#else - #define OS_OHOS -#endif - -#endif // PLATFORM_SPECIFIC_H diff --git a/services/distributeddataservice/adapter/include/autils/time_utils.h b/services/distributeddataservice/adapter/include/autils/time_utils.h deleted file mode 100644 index a67f12f7c..000000000 --- a/services/distributeddataservice/adapter/include/autils/time_utils.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 TIME_UTILS_H -#define TIME_UTILS_H - -#include -#include - -namespace OHOS { -namespace DistributedKv { -constexpr int64_t SEC_TO_MICROSEC = 1000000; - -class TimeUtils final { -public: - // micro seconds since 1970 - static inline uint64_t CurrentTimeMicros() - { - struct timeval tv = { 0, 0 }; - gettimeofday(&tv, nullptr); - return (tv.tv_sec * SEC_TO_MICROSEC + tv.tv_usec); - } -}; -} // namespace DistributedKv -} // namespace OHOS -#endif diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 98e780749..5c3173622 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -25,7 +25,6 @@ #include "checker/checker_manager.h" #include "communication_provider.h" #include "config_factory.h" -#include "constant.h" #include "crypto_manager.h" #include "device_manager_adapter.h" #include "device_matrix.h" @@ -312,7 +311,7 @@ void KvStoreDataService::StartService() DumpHelper::GetInstance().AddErrorInfo("StartService: Service publish failed."); } // Initialize meta db delegate manager. - KvStoreMetaManager::GetInstance().SubscribeMeta(KvStoreMetaRow::KEY_PREFIX, + KvStoreMetaManager::GetInstance().SubscribeMeta(StoreMetaData::GetKey({}), [this](const std::vector &key, const std::vector &value, CHANGE_FLAG flag) { OnStoreMetaChanged(key, value, flag); }); @@ -671,51 +670,6 @@ void KvStoreDataService::OnDeviceOnReady(const AppDistributedKv::DeviceInfo &inf }); } -bool DbMetaCallbackDelegateMgr::GetKvStoreDiskSize(const std::string &storeId, uint64_t &size) -{ - if (IsDestruct()) { - return false; - } - DistributedDB::DBStatus ret = delegate_->GetKvStoreDiskSize(storeId, size); - return (ret == DistributedDB::DBStatus::OK); -} - -void DbMetaCallbackDelegateMgr::GetKvStoreKeys(std::vector &dbStats) -{ - if (IsDestruct()) { - return; - } - DistributedDB::DBStatus dbStatusTmp; - Option option {.createIfNecessary = true, .isMemoryDb = false, .isEncryptedDb = false}; - DistributedDB::KvStoreNbDelegate *nbDelegate = nullptr; - delegate_->GetKvStore(Bootstrap::GetInstance().GetMetaDBName(), option, - [&nbDelegate, &dbStatusTmp](DistributedDB::DBStatus dbStatus, DistributedDB::KvStoreNbDelegate *delegate) { - nbDelegate = delegate; - dbStatusTmp = dbStatus; - }); - - if (dbStatusTmp != DistributedDB::DBStatus::OK) { - return; - } - DistributedDB::Key dbKey = KvStoreMetaRow::GetKeyFor(""); - std::vector entries; - nbDelegate->GetEntries(dbKey, entries); - if (entries.empty()) { - delegate_->CloseKvStore(nbDelegate); - return; - } - for (auto const &entry : entries) { - std::string key = std::string(entry.key.begin(), entry.key.end()); - std::vector out; - Split(key, Constant::KEY_SEPARATOR, out); - if (out.size() >= VECTOR_SIZE) { - StoreInfo storeInfo = {out[USER_ID], out[APP_ID], out[STORE_ID]}; - dbStats.push_back(std::move(storeInfo)); - } - } - delegate_->CloseKvStore(nbDelegate); -} - int32_t KvStoreDataService::OnUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) { features_.ForEachCopies( diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index cbb4ae016..4a16d21cf 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -21,7 +21,6 @@ #include #include "account_delegate.h" -#include "constant.h" #include "dump_helper.h" #include "feature_stub_impl.h" #include "ikvstore_data_service.h" @@ -137,40 +136,5 @@ private: std::shared_ptr deviceInnerListener_; std::shared_ptr executors_; }; - -class DbMetaCallbackDelegateMgr : public DbMetaCallbackDelegate { -public: - using Option = DistributedDB::KvStoreNbDelegate::Option; - virtual ~DbMetaCallbackDelegateMgr() {} - - explicit DbMetaCallbackDelegateMgr(DistributedDB::KvStoreDelegateManager *delegate) - : delegate_(delegate) {} - bool GetKvStoreDiskSize(const std::string &storeId, uint64_t &size) override; - void GetKvStoreKeys(std::vector &dbStats) override; - bool IsDestruct() - { - return delegate_ == nullptr; - } - -private: - void Split(const std::string &str, const std::string &delimiter, std::vector &out) - { - size_t start; - size_t end = 0; - while ((start = str.find_first_not_of(delimiter, end)) != std::string::npos) { - end = str.find(delimiter, start); - if (end == std::string::npos) { - end = str.size(); - } - out.push_back(str.substr(start, end - start)); - } - } - - DistributedDB::KvStoreDelegateManager *delegate_ {}; - static const inline int USER_ID = 0; - static const inline int APP_ID = 1; - static const inline int STORE_ID = 2; - static const inline int VECTOR_SIZE = 2; -}; } #endif // KVSTORE_DATASERVICE_H diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp index c281c7a20..960dcad31 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp @@ -24,7 +24,6 @@ #include "bootstrap.h" #include "communication_provider.h" #include "communication_strategy.h" -#include "constant.h" #include "crypto_manager.h" #include "device_manager_adapter.h" #include "device_matrix.h" @@ -156,7 +155,7 @@ void KvStoreMetaManager::InitMetaData() data.isEncrypt = false; data.storeType = KvStoreType::SINGLE_VERSION; data.schema = ""; - data.storeId = Constant::SERVICE_META_DB_NAME; + data.storeId = Bootstrap::GetInstance().GetMetaDBName(); data.account = accountId; data.uid = static_cast(uid); data.version = META_STORE_VERSION; diff --git a/services/distributeddataservice/app/src/security/security.cpp b/services/distributeddataservice/app/src/security/security.cpp index 0ff95061f..881217ef0 100644 --- a/services/distributeddataservice/app/src/security/security.cpp +++ b/services/distributeddataservice/app/src/security/security.cpp @@ -14,11 +14,10 @@ */ #include "security.h" -#include #include +#include #include #include -#include "constant.h" #include "dev_slinfo_mgr.h" #include "device_manager_adapter.h" #include "log_print.h" diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index aaab31bc3..d55ad5863 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -69,7 +69,6 @@ ohos_shared_library("distributeddatasvc") { "config/src/model/protocol_config.cpp", "crypto/src/crypto_manager.cpp", "kvdb/auth_delegate.cpp", - "kvdb/executor_factory.cpp", "kvdb/kvdb_exporter.cpp", "kvdb/kvdb_service_impl.cpp", "kvdb/kvdb_service_stub.cpp", diff --git a/services/distributeddataservice/service/kvdb/executor_factory.cpp b/services/distributeddataservice/service/kvdb/executor_factory.cpp deleted file mode 100644 index 4d4385625..000000000 --- a/services/distributeddataservice/service/kvdb/executor_factory.cpp +++ /dev/null @@ -1,46 +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 "executor_factory.h" - -namespace OHOS::DistributedData { -using namespace OHOS::DistributedKv; -ExecutorFactory &ExecutorFactory::GetInstance() -{ - static ExecutorFactory instance; - return instance; -} - -bool ExecutorFactory::Execute(KvStoreTask &&task) -{ - if (threadPool_ == nullptr) { - return false; - } - threadPool_->AddTask(std::move(task)); - return true; -} - -ExecutorFactory::ExecutorFactory() -{ - threadPool_ = KvStoreThreadPool::GetPool(POOL_SIZE, "Executor", true); -} - -ExecutorFactory::~ExecutorFactory() -{ - if (threadPool_ != nullptr) { - threadPool_->Stop(); - threadPool_ = nullptr; - } -} -} // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/service/kvdb/executor_factory.h b/services/distributeddataservice/service/kvdb/executor_factory.h deleted file mode 100644 index 42d05757d..000000000 --- a/services/distributeddataservice/service/kvdb/executor_factory.h +++ /dev/null @@ -1,36 +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 DISTRIBUTEDDATAMGR_DATAMGR_EXECUTOR_FACTORY_H -#define DISTRIBUTEDDATAMGR_DATAMGR_EXECUTOR_FACTORY_H - -#include "kv_store_thread_pool.h" -namespace OHOS::DistributedData { -using OHOS::DistributedKv::KvStoreTask; -using OHOS::DistributedKv::KvStoreThreadPool; -class ExecutorFactory { -public: - API_EXPORT static ExecutorFactory &GetInstance(); - API_EXPORT bool Execute(KvStoreTask &&task); - -private: - ExecutorFactory(); - ~ExecutorFactory(); - - static constexpr int POOL_SIZE = 4; - - std::shared_ptr threadPool_; -}; -} // namespace OHOS::DistributedData -#endif // DISTRIBUTEDDATAMGR_DATAMGR_EXECUTOR_FACTORY_H -- Gitee From 0b4ccc291b5d0e93d9489903b618550e21211c0d Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Tue, 13 Jun 2023 15:18:18 +0800 Subject: [PATCH 2/7] remove the a utils Signed-off-by: Sven Wang --- services/distributeddataservice/adapter/BUILD.gn | 1 - services/distributeddataservice/adapter/dfx/BUILD.gn | 1 - services/distributeddataservice/adapter/dfx/test/BUILD.gn | 2 -- 3 files changed, 4 deletions(-) diff --git a/services/distributeddataservice/adapter/BUILD.gn b/services/distributeddataservice/adapter/BUILD.gn index caf337463..515866a6a 100644 --- a/services/distributeddataservice/adapter/BUILD.gn +++ b/services/distributeddataservice/adapter/BUILD.gn @@ -45,7 +45,6 @@ ohos_shared_library("distributeddata_adapter") { configs = [ ":distributeddata_adapter_private_config" ] deps = [ "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/account:distributeddata_account_static", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/autils:distributeddata_autils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/communicator:distributeddata_communicator_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/dfx:distributeddata_dfx_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/permission:distributeddata_permission_static", diff --git a/services/distributeddataservice/adapter/dfx/BUILD.gn b/services/distributeddataservice/adapter/dfx/BUILD.gn index c137b61fe..c6938ff3f 100644 --- a/services/distributeddataservice/adapter/dfx/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/BUILD.gn @@ -42,7 +42,6 @@ ohos_static_library("distributeddata_dfx_static") { cflags_cc = [ "-fvisibility=hidden" ] deps = [ - "../autils:distributeddata_autils_static", "//third_party/openssl:libcrypto_shared", ] external_deps = [ diff --git a/services/distributeddataservice/adapter/dfx/test/BUILD.gn b/services/distributeddataservice/adapter/dfx/test/BUILD.gn index 0c2a6050e..4b4df71f6 100755 --- a/services/distributeddataservice/adapter/dfx/test/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/test/BUILD.gn @@ -47,7 +47,6 @@ ohos_unittest("DistributeddataDfxMSTTest") { ] ldflags = [ "-Wl,--exclude-libs,ALL" ] deps = [ - "../../autils:distributeddata_autils_static", "../../dfx:distributeddata_dfx_static", "//third_party/googletest:gtest_main", "//third_party/openssl:libcrypto_shared", @@ -106,7 +105,6 @@ ohos_unittest("DistributeddataDfxUTTest") { ] ldflags = [ "-Wl,--exclude-libs,ALL" ] deps = [ - "../../autils:distributeddata_autils_static", "//third_party/googletest:gtest_main", "//third_party/openssl:libcrypto_shared", ] -- Gitee From f9350fdcb860c297de00ee8d7f78bbdb230d9d38 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Tue, 13 Jun 2023 19:37:23 +0800 Subject: [PATCH 3/7] update Signed-off-by: Sven Wang --- datamgr_service.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamgr_service.gni b/datamgr_service.gni index 7ef3974eb..3a7b7e96b 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -46,5 +46,5 @@ declare_args() { os_account_part_is_enabled = false } - datamgr_service_config = true; + datamgr_service_config = true } -- Gitee From a6d6d831f1d1fcedac93722a73a58f49ec9ddc7f Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Tue, 13 Jun 2023 21:37:31 +0800 Subject: [PATCH 4/7] fixed the bugs Signed-off-by: Sven Wang --- conf/BUILD.gn | 1 + .../adapter/account/src/account_delegate_impl.cpp | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/conf/BUILD.gn b/conf/BUILD.gn index 14f7ca2ca..330b9f2e5 100644 --- a/conf/BUILD.gn +++ b/conf/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") import("//build/ohos_var.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") #/system/etc/distributeddata/conf group("build_module") { diff --git a/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp b/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp index 7284cca5d..875a2ca3d 100644 --- a/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp +++ b/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp @@ -16,11 +16,8 @@ #define LOG_TAG "EVENT_HANDLER" #include "account_delegate_impl.h" -#include #include #include -#include -#include "constant.h" namespace OHOS { namespace DistributedKv { -- Gitee From 03d383cc92467fb3a1ff68153f72a9451b7e84f8 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Wed, 14 Jun 2023 09:30:02 +0800 Subject: [PATCH 5/7] remove a utils test Signed-off-by: Sven Wang --- services/distributeddataservice/adapter/test/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/adapter/test/BUILD.gn b/services/distributeddataservice/adapter/test/BUILD.gn index b716360d7..206f581e3 100755 --- a/services/distributeddataservice/adapter/test/BUILD.gn +++ b/services/distributeddataservice/adapter/test/BUILD.gn @@ -19,7 +19,6 @@ group("unittest") { deps += [ "../account/test:unittest", - "../autils/test:unittest", "../communicator/test:unittest", "../dfx/test:unittest", "../permission/test:unittest", -- Gitee From 8d5d7e514b42e802f124f417d0480c248f7f2efe Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Wed, 14 Jun 2023 10:10:28 +0800 Subject: [PATCH 6/7] fixed format bugs Signed-off-by: Sven Wang --- services/distributeddataservice/adapter/dfx/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/distributeddataservice/adapter/dfx/BUILD.gn b/services/distributeddataservice/adapter/dfx/BUILD.gn index c6938ff3f..2818cae48 100644 --- a/services/distributeddataservice/adapter/dfx/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/BUILD.gn @@ -41,9 +41,7 @@ ohos_static_library("distributeddata_dfx_static") { cflags_cc = [ "-fvisibility=hidden" ] - deps = [ - "//third_party/openssl:libcrypto_shared", - ] + deps = [ "//third_party/openssl:libcrypto_shared" ] external_deps = [ "c_utils:utils", "hisysevent_native:libhisysevent", -- Gitee From 78ad7f98a8788b6a196c19ff0f22fd0f101d0255 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Wed, 14 Jun 2023 16:04:05 +0800 Subject: [PATCH 7/7] remove time utils Signed-off-by: Sven Wang --- .../app/test/unittest/kvstore_flowctrl_manager_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/app/test/unittest/kvstore_flowctrl_manager_test.cpp b/services/distributeddataservice/app/test/unittest/kvstore_flowctrl_manager_test.cpp index e2e662be9..506f32c1a 100644 --- a/services/distributeddataservice/app/test/unittest/kvstore_flowctrl_manager_test.cpp +++ b/services/distributeddataservice/app/test/unittest/kvstore_flowctrl_manager_test.cpp @@ -18,11 +18,11 @@ #include "flowctrl_manager/kvstore_flowctrl_manager.h" #include #include -#include "time_utils.h" - +#include using namespace testing::ext; using namespace OHOS::DistributedKv; using namespace OHOS; +using namespace std::chrono; class KvStoreFlowCtrlManagerTest : public testing::Test { public: @@ -152,11 +152,11 @@ HWTEST_F(KvStoreFlowCtrlManagerTest, KvStoreFlowCtrlManagerTest006, TestSize.Lev auto ptr = std::make_shared(OPERATION_BURST_CAPACITY, OPERATION_SUSTAINED_CAPACITY); int arr[2] = {0, 0}; uint64_t curTime = 0; - uint64_t lastTime = TimeUtils::CurrentTimeMicros(); + uint64_t lastTime = duration_cast(steady_clock::now().time_since_epoch()).count(); for (int i = 0; i < 10001; i++) { arr[ptr->IsTokenEnough()]++; while (true) { - curTime = TimeUtils::CurrentTimeMicros(); + curTime = duration_cast(steady_clock::now().time_since_epoch()).count(); if ((curTime - lastTime) > 1000) { lastTime = curTime; break; -- Gitee