diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..e69de29b
diff --git a/BUILD.gn b/BUILD.gn
new file mode 100755
index 00000000..f85a0891
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,24 @@
+# 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")
+
+group("build_native_test") {
+ testonly = true
+ deps = [
+ "frameworks/innerkitsimpl/distributeddatafwk/test:unittest",
+ "services/distributeddataservice/adapter/test:unittest",
+ "services/distributeddataservice/app/test:unittest",
+ "services/distributeddataservice/libs/distributeddb/test:unittest",
+ "services/distributeddataservice/test:moduletest",
+ ]
+}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..4947287f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/README.en.md b/README.en.md
deleted file mode 100644
index 5b16104b..00000000
--- a/README.en.md
+++ /dev/null
@@ -1,36 +0,0 @@
-# distributeddatamgr_datamgr
-
-#### Description
-Distributed data manager that provides the capability to store data in the databases of different devices | 分布式数据管理服务模块,提供多设备数据分布式存储能力
-
-#### Software Architecture
-Software architecture description
-
-#### Installation
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Instructions
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Contribution
-
-1. Fork the repository
-2. Create Feat_xxx branch
-3. Commit your code
-4. Create Pull Request
-
-
-#### Gitee Feature
-
-1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
-2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
-3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
-4. The most valuable open source project [GVP](https://gitee.com/gvp)
-5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
-6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README.md b/README.md
index 0d934e52..2d8851fc 100644
--- a/README.md
+++ b/README.md
@@ -1,37 +1,127 @@
-# distributeddatamgr_datamgr
+# distributeddatamgr\_distributeddatamgr
-#### 介绍
-Distributed data manager that provides the capability to store data in the databases of different devices | 分布式数据管理服务模块,提供多设备数据分布式存储能力
+- [Introduction](#section11660541593)
+- [Directory Structure](#section161941989596)
+- [Constraints](#section119744591305)
+- [Description](#section1312121216216)
+- [Repositories Involved](#section1371113476307)
-#### 软件架构
-软件架构说明
+## Introduction
+
+Distributed Data Service \(DDS\) provides the capability to store data in the databases of different devices. DDS isolates data based on a triplet of the account, app, and database. DDS synchronizes data between trusted devices to provide users with consistent data access experience on different devices.
+
+DDS manages data of OpenHarmony in a distributed manner. It consists of the following parts:
+
+- **Service interfaces**
+
+ DDS provides APIs for other modules to create databases, access data, and subscribe to data. Supporting the KV data model and common data types, the APIs are highly compatible and easy to use, and can be released.
+
+- **Service component**
+
+ The service component manages metadata, permissions, backup and restoration, and multiple users. It also initializes the storage and synchronization components and communication adaptation layer of the distributed database.
+
+- **Storage component**
+
+ The storage component provides data access, data reduction, transactions, snapshots, data combination, and conflict resolution.
+
+- **Synchronization component**
+
+ The synchronization component connects the storage and communication components. It maintains data consistency between online devices by synchronizing data generated on the local device to other devices and merging data received from other devices into the local device.
+
+- **Communication adaptation layer**
+
+ The communication adaptation layer invokes interfaces of the public communication layer to create and connect to communication channels, receive device online and offline messages, maintain metadata of the connected and disconnected devices, send device online and offline messages to the synchronization component, synchronize the list of devices connected to and maintained by components, and invoke interfaces to encapsulate and send data to the connected devices.
-#### 安装教程
+You call APIs of DDS to create, access, and subscribe to distributed databases. The service interfaces store data to the storage component based on the capabilities provided by the service component. The storage component invokes the synchronization component to synchronize data. The synchronization component uses the communication adaptation layer to synchronize data to remote devices, which update the data in the storage component.
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### 使用说明
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### 参与贡献
-
-1. Fork 本仓库
-2. 新建 Feat_xxx 分支
-3. 提交代码
-4. 新建 Pull Request
+**Figure 1** How DDS works
-#### 特技
+
+
+## Directory Structure
+
+```
+/foundation/distributeddatamgr/distributeddatamgr
+├── interfaces # APIs
+│ └── innerkits # Native APIs
+├── services # Service code
+│ └── distributeddataservice # DDS implementation
+└── test # Test case resources
+```
+
+## Constraints
+
+- To use all functions of DDS, you need to obtain the **ohos.permission.DISTRIBUTED\_DATASYNC** permission.
+- DDS supports the KV data model, but not foreign keys or triggers of the relational database.
+- DDS supports the following KV data model specifications:
+ - For the device KV store, the maximum size of a key is 896 bytes, and that of a value is 4 MB.
+ - For the single KV store, the maximum size of a key is 1 KB, and that of a value is 4 MB.
+ - Each app can open a maximum of 16 databases simultaneously.
+
+- DDS cannot completely replace the database in the service sandbox for storing data, because the storage types supported by them are not completely the same. You need to determine the data to be synchronized in distributed mode and store the data in DDS.
+- Currently, DDS does not allow customization of conflict resolution policies.
+- DDS supports a maximum of 1000 **KvStore** API calls per second, and 10,000 per minute. It supports a maximum of 50 **KvManager** API calls per second, and 500 per minute.
+
+## Description
+
+Some basic concepts related to the DDS are as follows:
+
+- **KV data model**
+
+ KV is short for key-value. The KV database is a type of NoSQL database. Data in this type of database is organized, indexed, and stored in the form of key-value pairs.
+
+ The KV data model is suitable for storing service data that does not involve too many data or service relationships. It provides better read and write performance than the SQL database. The KV data model is widely used in distributed scenarios because it handles conflict more easily in database version compatibility and data synchronization. The distributed database is based on the KV data model and provides KV-based access interfaces.
+
+- **Distributed database transactions**
+
+ Distributed database transactions include local transactions \(same as the transactions of traditional databases\) and synchronization transactions. Synchronization transactions refer to data synchronization between devices in the unit of local transaction. Synchronization of a local transaction modification either succeeds or fails on multiple devices.
+
+- **Distributed database consistency**
+
+ In a distributed scenario where multiple devices are used in the same network, distributed database consistency means that data is consistent on these devices. This consistency can be classified into strong, weak, and eventual consistency.
+
+ - **Strong consistency**: After data is inserted, deleted, or updated on a device, other devices in the same network will obtain the updated data.
+ - **Weak consistency**: After data is inserted, deleted, or updated on a device, other devices in the same network may or may not obtain the updated data. The time when all devices have the same data is uncertain.
+ - **Eventual consistency**: After data is inserted, deleted, or updated on a device, other devices in the same network may not obtain the updated data immediately. However, data on all the devices will become consistent after some time.
+
+ Strong consistency has high requirements on distributed data management and may be used in distributed server scenarios. DDS supports only ultimate consistency because mobile devices are not always online and there is no center.
+
+- **Distributed database synchronization**
+
+ After discovering and authenticating a device, the bottom-layer communication component notifies the DDS that the device goes online. After receiving the notification, DDS establishes an encrypted transmission channel to synchronize data between the two devices.
+
+ DDS provides both manual and automatic synchronization. In manual synchronization, you can specify the list of target devices and the synchronization mode \(PULL, PUSH, or PULL\_PUSH\). In automatic synchronization, the distributed database synchronizes data \(when devices go online or data is modified\), and you are unaware of the synchronization.
+
+- **Single KV store**
+
+ Data is saved locally in the unit of a single KV entry. Only one entry is saved for each key. When users modify data locally, the corresponding KV entry is modified, regardless of whether the data has been synchronized. As for synchronization, the latest modification is synchronized to remote devices.
+
+- **Device KV store**
+
+ The device KV store is based on the single KV store and adds device IDs before the keys of key-value pairs. This ensures that the data generated by each device is isolated from each other and is centrally managed by the system. With the device KV store, you can query data of a specified device, but cannot modify the data synchronized from remote devices.
+
+- **Conflict resolution policy for the distributed database**
+
+ A data conflict occurs when multiple devices modify the same data and commit the modification to the database. In this case, the default conflict resolution policy is used, that is, the data modification committed later takes effect. Currently, the conflict resolution policy cannot be customized.
+
+- **Schema-based database management and data query based on predicates**
+
+ When creating or opening a single KV store, you can specify a schema. The database detects the value format of key-value pairs based on the schema and checks the value structure. In addition, the database provides index creation and predicate-based query functions based on the fields in the values.
+
+- **Distributed database backup capability**
+
+ DDS provides the database backup capability. By setting **backup** to **true**, you can trigger daily database backup. If a distributed database is damaged, DDS deletes the database and restores the most recent data from the backup database. If no backup database is available, DDS creates one. DDS can also back up encrypted databases.
+
+
+## Repositories Involved
+
+Distributed Data Management subsystem
+
+distributeddatamgr\_distributeddatamgr
+
+third\_party\_sqlite
+
+third\_party\_flatbuffers
-1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
-2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
-3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
-4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
-5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
-6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README_zh.md b/README_zh.md
new file mode 100644
index 00000000..48aabe1d
--- /dev/null
+++ b/README_zh.md
@@ -0,0 +1,127 @@
+# 分布式数据服务组件
+
+- [简介](#section11660541593)
+- [目录](#section161941989596)
+- [约束](#section119744591305)
+- [说明](#section1312121216216)
+- [相关仓](#section1371113476307)
+
+## 简介
+
+分布式数据服务(Distributed Data Service,DDS) 提供不同设备间数据库数据分布式的能力。通过结合帐号、应用和数据库三元组,分布式数据服务对数据进行隔离。在通过可信认证的设备间,分布式数据服务支持数据相互同步,为用户提供在多种终端设备上一致的数据访问体验。
+
+分布式数据服务支撑OpenHarmony系统上分布式管理数据,包含五部分:
+
+- **服务接口**
+
+ 分布式数据服务提供专门的数据库创建、数据访问、数据订阅等接口给内部其他部件调用,接口支持KV数据模型,支持常用的数据类型,同时确保接口的兼容性、易用性和可发布性。
+
+- **服务组件**
+
+ 服务组件负责服务内元数据管理、权限管理、备份和恢复管理以及多用户管理等、同时负责初始化底层分布式DB的存储组件、同步组件和通信适配层。
+
+- **存储组件**
+
+ 存储组件负责数据的访问、数据的缩减、事务、快照,以及数据合并和冲突解决等特性。
+
+- **同步组件**
+
+ 同步组件连结了存储组件与通信组件,其目标是保持在线设备间的数据库数据一致性,包括将本地产生的未同步数据同步给其他设备,接收来自其他设备发送过来的数据,并合并到本地设备中。
+
+- **通信适配层**
+
+ 通信适配层负责调用底层公共通信层的接口完成通信管道的创建、连接,接收设备上下线消息,维护已连接和断开设备列表的元数据,同时将设备上下线信息发送给上层同步组件,同步组件维护连接的设备列表,同步数据时根据该列表,调用通信适配层的接口将数据封装并发送给连接的设备。
+
+
+通过调用分布式数据服务接口实现分布式数据库创建、访问、订阅功能,服务接口通过操作服务组件提供的能力,将数据存储至存储组件,存储组件调用同步组件实现将数据同步,同步组件使用通信适配层将数据同步至远端设备,远端设备通过同步组件接收数据,并更新至本端存储组件。
+
+**图 1** 数据分布式运作示意图
+
+
+
+
+## 目录
+
+```
+/foundation/distributeddatamgr/distributeddatamgr
+├── interfaces # 接口层代码
+│ └── innerkits # Native接口
+├── services # 服务层代码
+│ └── distributeddataservice # 分布式数据服务实现
+└── test # 测试用例资源
+```
+
+## 约束
+
+- 如需使用分布式数据服务完整功能,需要申请ohos.permission.DISTRIBUTED\_DATASYNC权限。
+- 分布式数据服务的数据模型仅支持KV数据模型,不支持外键、触发器等关系型数据库中的技术点。
+- 分布式数据服务支持的KV数据模型规格:
+ - 设备协同数据库,Key最大支持896Byte,Value最大支持4MB。
+ - 单版本数据库,Key最大支持1KB,Value最大支持4MB。
+ - 每个程序最多支持同时打开16个DB。
+
+- 由于支持的存储类型不完全相同等原因,分布式数据服务无法完全代替业务沙箱内数据库数据的存储功能,开发人员需要确定要做分布式同步的数据,把这些数据保存到分布式数据服务中。
+- 分布式数据服务当前不支持自定义冲突解决策略。
+- 分布式数据服务当前流控机制针对KvStore的接口1秒最大访问1000次,1分钟最大访问10000次。KvManager的接口1秒最大访问50次,1分钟最大访问500次。
+
+## 说明
+
+分布式数据服务几个基本概念:
+
+- **KV数据模型**
+
+ “KV数据模型”是“Key-Value数据模型”的简称,“Key-Value”即“键-值”。它是一种NoSQL类型数据库,其数据以键值对的形式进行组织、索引和存储。
+
+ KV数据模型适合不涉及过多数据关系和业务关系的业务数据存储,比SQL数据库存储拥有更好的读写性能,同时因在分布式场景中降低了数据库版本兼容和数据同步过程中冲突解决的复杂度而被广泛使用。分布式数据库也是基于KV数据模型,对外提供KV类型的访问接口。
+
+- **分布式数据库事务性**
+
+ 分布式数据库事务支持本地事务(和传统数据库的事务概念一致)和同步事务,同步事务是指在设备之间同步数据时,是以本地事务为单位进行同步,一次本地事务的修改要么都同步成功,要么都同步失败。
+
+- **分布式数据库一致性**
+
+ 在分布式场景中一般会涉及多个设备,组网内设备之间看到的数据是否一致称为分布式数据库的一致性。分布式数据库一致性可以分为**强一致性**、**弱一致性**和**最终一致性**。
+
+ - **强一致性**:是指某一设备成功增、删、改数据后,组网内设备对该数据的读取操作都将得到更新后的值。
+ - **弱一致性**:是指某一设备成功增、删、改数据后,组网内设备可能能读取到本次更新数据,也可能读取不到,不能保证在多长时间后每个设备的数据一定是一致的。
+ - **最终一致性**:是指某一设备成功增、删、改数据后,组网内设备可能读取不到本次更新数据,但在某个时间窗口之后组网内设备的数据能够达到一致状态。
+
+ 强一致性对分布式数据的管理要求非常高,在服务器的分布式场景可能会遇到。因为移动终端设备的不常在线、以及无中心的特性,分布式数据服务不支持强一致,只支持最终一致性。
+
+- **分布式数据库同步**
+
+ 底层通信组件完成设备发现和认证,会通知分布式数据服务设备上线。收到设备上线的消息后分布式数据服务可以在两个设备之间建立加密的数据传输通道,利用该通道在两个设备之间进行数据同步。
+
+ 分布式数据服务提供了两种同步模式:**手动同步**和**自动同步模式**。**手动同步模式**支持指定同步的设备列表和同步模式(PULL、PUSH和PULL\_PUSH三种同步模式)。**自动同步模式**由分布式数据库来完成数据同步(同步时机包括设备上线、修改数据等),业务不感知同步操作。
+
+- **单版本分布式数据库**
+
+ 单版本是指数据在本地保存是以单个KV条目为单位的方式保存,对每个Key最多只保存一个条目项,当数据在本地被用户修改时,不管它是否已经被同步出去,均直接在这个条目上进行修改。同步也以此为基础,按照它在本地被写入或更改的顺序将当前最新一次修改逐条同步至远端设备。
+
+- **设备协同分布式数据库**
+
+ 设备协同分布式数据库建立在单版本分布式数据库之上,对于存入的KV数据中的Key前面拼接了本设备的DeviceID标识符,这样能保证每个设备产生的数据严格隔离,底层按照设备的维度管理这些数据,设备协同分布式数据库支持以设备的维度查询分布式数据,但是不支持修改远端设备同步过来的数据。
+
+- **分布式数据库冲突解决策略**
+
+ 分布式数据库多设备提交冲突场景,在给提交冲突做合并的过程中,如果多个设备同时修改了同一数据,则称这种场景为数据冲突。数据冲突采用默认冲突解决策略,基于提交时间戳,取时间戳较大的提交数据,当前不支持定制冲突解决策略。
+
+- **数据库Schema化管理与谓词查询**
+
+ 单版本数据库支持在创建和打开数据库时指定Schema,数据库根据Schema定义感知KV记录的Value格式,以实现对Value值结构的检查,并基于Value中的字段实现索引建立和支持谓词查询。
+
+- **分布式数据库备份能力**
+
+ 提供分布式数据库备份能力,业务通过设置backup属性为true,可以触发分布式数据服务每日备份。当分布式数据库发生损坏,分布式数据服务会删除损坏数据库,并且从备份数据库中恢复上次备份的数据。如果不存在备份数据库,则创建一个新的数据库。同时支持加密数据库的备份能力。
+
+
+## 相关仓
+
+分布式数据管理子系统
+
+distributeddatamgr\_distributeddatamgr
+
+third\_party\_sqlite
+
+third\_party\_flatbuffers
+
diff --git a/figures/en-us_image_0000001162536643.png b/figures/en-us_image_0000001162536643.png
new file mode 100644
index 00000000..05c1fe6f
Binary files /dev/null and b/figures/en-us_image_0000001162536643.png differ
diff --git a/figures/zh-cn_image_0000001162536643.png b/figures/zh-cn_image_0000001162536643.png
new file mode 100644
index 00000000..7f809adc
Binary files /dev/null and b/figures/zh-cn_image_0000001162536643.png differ
diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/idevice_status_change_listener.h b/frameworks/innerkitsimpl/distributeddatafwk/include/idevice_status_change_listener.h
new file mode 100644
index 00000000..fe0df554
--- /dev/null
+++ b/frameworks/innerkitsimpl/distributeddatafwk/include/idevice_status_change_listener.h
@@ -0,0 +1,48 @@
+/*
+ * 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 DEV_IDEVICE_STATUS_CHANGE_LISTENER_H
+#define DEV_IDEVICE_STATUS_CHANGE_LISTENER_H
+#include "iremote_broker.h"
+#include "iremote_proxy.h"
+#include "iremote_stub.h"
+#include "types.h"
+
+namespace OHOS {
+namespace DistributedKv {
+class IDeviceStatusChangeListener : public IRemoteBroker {
+public:
+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.IDeviceStatusChangeListener");
+ virtual void OnChange(const DeviceInfo &results, const DeviceChangeType &type) = 0;
+};
+
+class DeviceStatusChangeListenerStub : public IRemoteStub {
+public:
+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
+ MessageParcel &reply, MessageOption &option) override;
+};
+
+class DeviceStatusChangeListenerProxy : public IRemoteProxy {
+public:
+ explicit DeviceStatusChangeListenerProxy(const sptr &impl);
+ ~DeviceStatusChangeListenerProxy() = default;
+ void OnChange(const DeviceInfo &results, const DeviceChangeType &type) override;
+private:
+ static inline BrokerDelegator delegator_;
+};
+} // namespace DistributedKv
+} // namespace OHOS
+
+#endif // DEV_IDEVICE_STATUS_CHANGE_LISTENER_H
\ No newline at end of file
diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore.h
new file mode 100644
index 00000000..2821dee8
--- /dev/null
+++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore.h
@@ -0,0 +1,100 @@
+/*
+ * 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 I_KVSTORE_H
+#define I_KVSTORE_H
+
+#include "message_parcel.h"
+#include "iremote_broker.h"
+#include "ikvstore_observer.h"
+#include "ikvstore_snapshot.h"
+#include "iremote_proxy.h"
+#include "iremote_stub.h"
+#include "types.h"
+
+namespace OHOS {
+namespace DistributedKv {
+
+class IKvStoreImpl : public IRemoteBroker {
+public:
+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.IKvStoreImpl")
+
+ virtual void GetKvStoreSnapshot(sptr observer,
+ std::function)> callback) = 0;
+
+ virtual Status ReleaseKvStoreSnapshot(sptr iKvStoreSnapshot) = 0;
+
+ virtual Status Put(const Key &key, const Value &value) = 0;
+
+ virtual Status PutBatch(const std::vector &entries) = 0;
+
+ virtual Status Delete(const Key &key) = 0;
+
+ virtual Status DeleteBatch(const std::vector &keys) = 0;
+
+ virtual Status Clear() = 0;
+
+ virtual Status StartTransaction() = 0;
+
+ virtual Status Commit() = 0;
+
+ virtual Status Rollback() = 0;
+
+ virtual Status SubscribeKvStore(const SubscribeType subscribeType, sptr observer) = 0;
+
+ virtual Status UnSubscribeKvStore(const SubscribeType subscribeType, sptr observer) = 0;
+};
+
+class KvStoreImplStub : public IRemoteStub {
+public:
+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
+ MessageParcel &reply, MessageOption &option) override;
+
+private:
+ int32_t GetKvStoreSnapshotOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t ReleaseKvStoreSnapshotOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t PutOnRemoteRequest(MessageParcel &data, MessageParcel &reply);
+ int32_t PutBatchOnRemoteRequest(MessageParcel &data, MessageParcel &reply);
+ int32_t DeleteOnRemoteRequest(MessageParcel &data, MessageParcel &reply);
+ int32_t DeleteBatchOnRemoteRequest(MessageParcel &data, MessageParcel &reply);
+ int32_t SubscribeKvStoreOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t UnSubscribeKvStoreOnRemote(MessageParcel &data, MessageParcel &reply);
+};
+
+class KvStoreImplProxy : public IRemoteProxy {
+public:
+ explicit KvStoreImplProxy(const sptr &impl);
+ ~KvStoreImplProxy() = default;
+ virtual void GetKvStoreSnapshot(sptr observer,
+ std::function)> callback);
+ virtual Status ReleaseKvStoreSnapshot(sptr iKvStoreSnapshot);
+ virtual Status Put(const Key &key, const Value &value);
+ virtual Status PutBatch(const std::vector &entries);
+ virtual Status Delete(const Key &key);
+ virtual Status DeleteBatch(const std::vector &keys);
+ virtual Status Clear();
+ virtual Status StartTransaction();
+ virtual Status Commit();
+ virtual Status Rollback();
+ virtual Status SubscribeKvStore(const SubscribeType subscribeType, sptr observer);
+ virtual Status UnSubscribeKvStore(const SubscribeType subscribeType, sptr observer);
+private:
+ static inline BrokerDelegator delegator_;
+};
+
+} // namespace DistributedKv
+} // namespace OHOS
+
+#endif // I_KVSTORE_H
diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h
new file mode 100644
index 00000000..15a83f10
--- /dev/null
+++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h
@@ -0,0 +1,48 @@
+/*
+ * 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 I_KVSTORE_CLIENT_DEATH_OBSERVER_H
+#define I_KVSTORE_CLIENT_DEATH_OBSERVER_H
+
+#include "iremote_broker.h"
+#include "iremote_proxy.h"
+#include "iremote_stub.h"
+
+namespace OHOS {
+namespace DistributedKv {
+
+class IKvStoreClientDeathObserver : public IRemoteBroker {
+public:
+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.IKvStoreClientDeathObserver");
+};
+
+class KvStoreClientDeathObserverStub : public IRemoteStub {
+public:
+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
+ MessageParcel &reply, MessageOption &option) override;
+};
+
+class KvStoreClientDeathObserverProxy : public IRemoteProxy {
+public:
+ explicit KvStoreClientDeathObserverProxy(const sptr &impl);
+ ~KvStoreClientDeathObserverProxy() = default;
+private:
+ static inline BrokerDelegator delegator_;
+};
+
+} // namespace DistributedKv
+} // namespace OHOS
+
+#endif // I_KVSTORE_CLIENT_DEATH_OBSERVER_H
diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h
new file mode 100755
index 00000000..3755e1f0
--- /dev/null
+++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h
@@ -0,0 +1,176 @@
+/*
+ * 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 I_KV_STORE_DATA_SERVICE_H
+#define I_KV_STORE_DATA_SERVICE_H
+
+#include "iremote_broker.h"
+#include "ikvstore.h"
+#include "ikvstore_client_death_observer.h"
+#include "ikvstore_observer.h"
+#include "ikvstore_single.h"
+#include "iremote_proxy.h"
+#include "iremote_stub.h"
+#include "message_parcel.h"
+#include "types.h"
+#include "idevice_status_change_listener.h"
+
+namespace OHOS {
+namespace DistributedKv {
+/*
+ * IPC-friendly Options struct without std::string schema field.
+ * Passing a struct with an std::string field is a potential security exploit.
+ *
+ */
+struct OptionsIpc {
+ bool createIfMissing;
+ bool encrypt;
+ bool persistant;
+ bool backup;
+ bool autoSync;
+ int securityLevel;
+ SyncPolicy syncPolicy;
+ KvStoreType kvStoreType;
+ bool syncable; // let bms delete first
+ bool dataOwnership; // true indicates the ownership of distributed data is DEVICE, otherwise, ACCOUNT
+};
+
+class IKvStoreDataService : public IRemoteBroker {
+public:
+ enum {
+ GETKVSTORE,
+ GETALLKVSTOREID,
+ CLOSEKVSTORE,
+ CLOSEALLKVSTORE,
+ DELETEKVSTORE,
+ DELETEALLKVSTORE,
+ REGISTERCLIENTDEATHOBSERVER,
+ GETSINGLEKVSTORE,
+ GETLOCALDEVICE,
+ GETDEVICELIST,
+ STARTWATCHDEVICECHANGE,
+ STOPWATCHDEVICECHANGE,
+ SERVICE_CMD_LAST,
+ DATAUSAGESTART = 20,
+ DATAUSAGEEND = 40,
+ };
+
+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.IKvStoreDataService");
+ /* create and open kv store instance. */
+ virtual Status GetKvStore(const Options &options, const AppId &appId, const StoreId &storeId,
+ std::function)> callback) = 0;
+
+ virtual Status GetSingleKvStore(const Options &options, const AppId &appId, const StoreId &storeId,
+ std::function)> callback) = 0;
+
+ /* get all kv store names */
+ virtual void GetAllKvStoreId(const AppId &appId, std::function &)> callback) = 0;
+
+ /* open kv store instance will not receive subscribe any more. */
+ virtual Status CloseKvStore(const AppId &appId, const StoreId &id) = 0;
+
+ /* close all kvstore. */
+ virtual Status CloseAllKvStore(const AppId &appId) = 0;
+
+ /* delete kv store */
+ virtual Status DeleteKvStore(const AppId &appId, const StoreId &id) = 0;
+
+ /* delete kv store */
+ virtual Status DeleteAllKvStore(const AppId &appId) = 0;
+
+ virtual Status RegisterClientDeathObserver(const AppId &appId, sptr observer) = 0;
+
+ virtual Status GetLocalDevice(DeviceInfo &device) = 0;
+ virtual Status GetDeviceList(std::vector &deviceInfoList, DeviceFilterStrategy strategy) = 0;
+ virtual Status StartWatchDeviceChange(sptr observer,
+ DeviceFilterStrategy strategy) = 0;
+ virtual Status StopWatchDeviceChange(sptr observer) = 0;
+};
+
+class KvStoreDataServiceStub : public IRemoteStub {
+public:
+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
+ MessageParcel &reply, MessageOption &option) override;
+private:
+ int32_t GetKvStoreOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t GetAllKvStoreIdOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t CloseKvStoreOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t CloseAllKvStoreOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t DeleteKvStoreOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t DeleteAllKvStoreOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t RegisterClientDeathObserverOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t GetLocalDeviceOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t GetDeviceListOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t StartWatchDeviceChangeOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t StopWatchDeviceChangeOnRemote(MessageParcel &data, MessageParcel &reply);
+ int32_t GetSingleKvStoreOnRemote(MessageParcel &data, MessageParcel &reply);
+
+ using RequestHandler = int32_t(KvStoreDataServiceStub::*)(MessageParcel&, MessageParcel&);
+ static constexpr RequestHandler HANDLERS[SERVICE_CMD_LAST] = {
+ [GETKVSTORE] = &KvStoreDataServiceStub::GetKvStoreOnRemote,
+ [GETALLKVSTOREID] = &KvStoreDataServiceStub::GetAllKvStoreIdOnRemote,
+ [CLOSEKVSTORE] = &KvStoreDataServiceStub::CloseKvStoreOnRemote,
+ [CLOSEALLKVSTORE] = &KvStoreDataServiceStub::CloseAllKvStoreOnRemote,
+ [DELETEKVSTORE] = &KvStoreDataServiceStub::DeleteKvStoreOnRemote,
+ [DELETEALLKVSTORE] = &KvStoreDataServiceStub::DeleteAllKvStoreOnRemote,
+ [REGISTERCLIENTDEATHOBSERVER] = &KvStoreDataServiceStub::RegisterClientDeathObserverOnRemote,
+ [GETSINGLEKVSTORE] = &KvStoreDataServiceStub::GetSingleKvStoreOnRemote,
+ [GETLOCALDEVICE] = &KvStoreDataServiceStub::GetLocalDeviceOnRemote,
+ [GETDEVICELIST] = &KvStoreDataServiceStub::GetDeviceListOnRemote,
+ [STARTWATCHDEVICECHANGE] = &KvStoreDataServiceStub::StartWatchDeviceChangeOnRemote,
+ [STOPWATCHDEVICECHANGE] = &KvStoreDataServiceStub::StopWatchDeviceChangeOnRemote,
+ };
+};
+
+class KvStoreDataServiceProxy : public IRemoteProxy {
+public:
+ explicit KvStoreDataServiceProxy(const sptr &impl);
+ ~KvStoreDataServiceProxy() = default;
+
+ /* create and open kv store instance. */
+ virtual Status GetKvStore(const Options &options, const AppId &appId, const StoreId &storeId,
+ std::function)> callback);
+
+ virtual Status GetSingleKvStore(const Options &options, const AppId &appId, const StoreId &storeId,
+ std::function)> callback);
+
+ /* get all kv store names */
+ virtual void GetAllKvStoreId(const AppId &appId, std::function &)> callback);
+
+ /* open kv store instance will not receive subscribe any more. */
+ virtual Status CloseKvStore(const AppId &appId, const StoreId &storeId);
+
+ /* close all kvstore. */
+ virtual Status CloseAllKvStore(const AppId &appId);
+
+ /* delete kv store */
+ virtual Status DeleteKvStore(const AppId &appId, const StoreId &id);
+
+ /* delete kv store */
+ virtual Status DeleteAllKvStore(const AppId &appId);
+
+ virtual Status RegisterClientDeathObserver(const AppId &appId, sptr observer);
+
+ virtual Status GetLocalDevice(DeviceInfo &device);
+ virtual Status GetDeviceList(std::vector &deviceInfoList, DeviceFilterStrategy strategy);
+ virtual Status StartWatchDeviceChange(sptr observer, DeviceFilterStrategy strategy);
+ virtual Status StopWatchDeviceChange(sptr observer);
+private:
+ static inline BrokerDelegator delegator_;
+};
+} // namespace DistributedKv
+} // namespace OHOS
+
+#endif // I_KV_STORE_DATA_SERVICE_H
diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h
new file mode 100644
index 00000000..b04d53ce
--- /dev/null
+++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.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 I_KVSTORE_OBSERVER_H
+#define I_KVSTORE_OBSERVER_H
+
+#include "change_notification.h"
+#include "iremote_broker.h"
+#include "ikvstore_observer.h"
+#include "ikvstore_snapshot.h"
+#include "iremote_proxy.h"
+#include "iremote_stub.h"
+
+namespace OHOS {
+namespace DistributedKv {
+
+class IKvStoreObserver : public IRemoteBroker {
+public:
+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.IKvStoreObserver");
+ virtual void OnChange(const ChangeNotification &changeNotification, sptr snapshot) = 0;
+};
+
+class KvStoreObserverStub : public IRemoteStub {
+public:
+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
+ MessageParcel &reply, MessageOption &option) override;
+};
+
+class KvStoreObserverProxy : public IRemoteProxy {
+public:
+ explicit KvStoreObserverProxy(const sptr &impl);
+ ~KvStoreObserverProxy() = default;
+ void OnChange(const ChangeNotification &changeNotification, sptr snapshot) override;
+private:
+ static inline BrokerDelegator delegator_;
+};
+
+} // namespace DistributedKv
+} // namespace OHOS
+
+#endif // I_KVSTORE_OBSERVER_H
diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_resultset.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_resultset.h
new file mode 100644
index 00000000..ed707c30
--- /dev/null
+++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_resultset.h
@@ -0,0 +1,101 @@
+/*
+ * 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 I_KVSTORE_RESULTSET_H
+#define I_KVSTORE_RESULTSET_H
+
+#include "message_parcel.h"
+#include "iremote_broker.h"
+#include "ikvstore_observer.h"
+#include "iremote_proxy.h"
+#include "iremote_stub.h"
+#include "types.h"
+
+namespace OHOS::DistributedKv {
+class IKvStoreResultSet : public IRemoteBroker {
+public:
+ DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.IKvStoreResultSet")
+ virtual int GetCount() = 0;
+
+ virtual int GetPosition() = 0;
+
+ virtual bool MoveToFirst() = 0;
+
+ virtual bool MoveToLast() = 0;
+
+ virtual bool MoveToNext() = 0;
+
+ virtual bool MoveToPrevious() = 0;
+
+ virtual bool Move(int offset) = 0;
+
+ virtual bool MoveToPosition(int position) = 0;
+
+ virtual bool IsFirst() = 0;
+
+ virtual bool IsLast() = 0;
+
+ virtual bool IsBeforeFirst() = 0;
+
+ virtual bool IsAfterLast() = 0;
+
+ virtual Status GetEntry(Entry &entry) = 0;
+};
+
+class KvStoreResultSetStub : public IRemoteStub {
+public:
+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
+ MessageParcel &reply, MessageOption &option) override;
+
+private:
+ int GetEntryOnRemote(MessageParcel &reply);
+};
+
+class KvStoreResultSetProxy : public IRemoteProxy {
+public:
+ explicit KvStoreResultSetProxy(const sptr &impl);
+ ~KvStoreResultSetProxy() = default;
+ virtual int GetCount();
+
+ virtual int GetPosition();
+
+ virtual bool MoveToFirst();
+
+ virtual bool MoveToLast();
+
+ virtual bool MoveToNext();
+
+ virtual bool MoveToPrevious();
+
+ virtual bool Move(int offset);
+
+ virtual bool MoveToPosition(int position);
+
+ virtual bool IsFirst();
+
+ virtual bool IsLast();
+
+ virtual bool IsBeforeFirst();
+
+ virtual bool IsAfterLast();
+
+ virtual Status GetEntry(Entry &entry);
+private:
+ virtual int SendRequest(uint32_t code);
+ virtual bool SendRequestRetBool(uint32_t code);
+ static inline BrokerDelegator delegator_;
+};
+} // namespace OHOS::DistributedKv
+#endif // I_KVSTORE_RESULTSET_H
diff --git a/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_single.h b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_single.h
new file mode 100755
index 00000000..20a1c15b
--- /dev/null
+++ b/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_single.h
@@ -0,0 +1,191 @@
+/*
+ * 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 I_SINGLE_KVSTORE_H
+#define I_SINGLE_KVSTORE_H
+
+#include