1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MULTI_VER_KVDB_SYNC_INTERFACE_H 17 #define MULTI_VER_KVDB_SYNC_INTERFACE_H 18 19 #include <map> 20 #include <vector> 21 22 #include "multi_ver_def.h" 23 #include "multi_ver_kv_entry.h" 24 #include "ikvdb_sync_interface.h" 25 26 namespace DistributedDB { 27 class MultiVerKvDBSyncInterface : public IKvDBSyncInterface { 28 public: 29 // Judge whether the commit existed. 30 virtual bool IsCommitExisted(const MultiVerCommitNode &commit) const = 0; 31 32 // Get the latest commits of all devices in the current device. 33 virtual int GetDeviceLatestCommit(std::map<std::string, MultiVerCommitNode> &commitMap) const = 0; 34 35 // Get the commit tree and exclude the existed commits from the remote device. 36 virtual int GetCommitTree(const std::map<std::string, MultiVerCommitNode> &commitMap, 37 std::vector<MultiVerCommitNode> &commits) const = 0; 38 39 // Get all the data from one commit. 40 virtual int GetCommitData(const MultiVerCommitNode &commit, std::vector<MultiVerKvEntry *> &entries) const = 0; 41 42 // Create one kv entry from the serialized data from remote device. 43 virtual MultiVerKvEntry *CreateKvEntry(const std::vector<uint8_t> &data) = 0; 44 45 // Release the kv entry created from the interface of CreateKvEntry. 46 virtual void ReleaseKvEntry(const MultiVerKvEntry *entry) = 0; 47 48 // Judge whether the slice hash-value existed. 49 virtual bool IsValueSliceExisted(const ValueSliceHash &value) const = 0; 50 51 // Get the value according the slice hash value, and push the value to the remote. 52 virtual int GetValueSlice(const ValueSliceHash &hashValue, ValueSlice &sliceValue) const = 0; 53 54 // Put the value when put the remote data into the local database. 55 virtual int PutValueSlice(const ValueSliceHash &hashValue, const ValueSlice &sliceValue) const = 0; 56 57 // Put all the kv entries of one commit received from the remote. 58 virtual int PutCommitData(const MultiVerCommitNode &commit, const std::vector<MultiVerKvEntry *> &entries, 59 const std::string &deviceName) = 0; 60 61 // Merge the remote commit into the local tree. 62 virtual int MergeSyncCommit(const MultiVerCommitNode &commit, const std::vector<MultiVerCommitNode> &commits) = 0; 63 64 virtual void NotifyStartSyncOperation() = 0; 65 66 virtual void NotifyFinishSyncOperation() = 0; 67 68 virtual int TransferSyncCommitDevInfo(MultiVerCommitNode &commit, const std::string &devId, 69 bool isSyncedIn) const = 0; 70 }; 71 } 72 73 #endif // MULTI_VER_KVDB_SYNC_INTERFACE_H 74