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_SYNC_TASK_CONTEXT_H 17 #define MULTI_VER_SYNC_TASK_CONTEXT_H 18 19 #ifndef OMIT_MULTI_VER 20 #include "multi_ver_kvdb_sync_interface.h" 21 #include "sync_task_context.h" 22 23 namespace DistributedDB { 24 class MultiVerSyncTaskContext final : public SyncTaskContext { 25 public: MultiVerSyncTaskContext()26 MultiVerSyncTaskContext() {}; 27 28 DISABLE_COPY_ASSIGN_MOVE(MultiVerSyncTaskContext); 29 30 // Init the MultiVerSyncTaskContext 31 int Initialize(const std::string &deviceId, ISyncInterface *syncInterface, 32 const std::shared_ptr<Metadata> &metadata, ICommunicator *communicator) override; 33 34 // Add a sync task target with the operation to the queue 35 int AddSyncOperation(SyncOperation *operation) override; 36 37 int GetCommitIndex() const; 38 39 void SetCommitIndex(int index); 40 41 int GetEntriesIndex() const; 42 43 void SetEntriesIndex(int index); 44 45 int GetValueSlicesIndex() const; 46 47 void SetValueSlicesIndex(int index); 48 49 void GetCommits(std::vector<MultiVerCommitNode> &commits); 50 51 void SetCommits(const std::vector<MultiVerCommitNode> &commits); 52 53 void GetCommit(int index, MultiVerCommitNode &commit) const; 54 55 void SetCommit(int index, const MultiVerCommitNode &commit); 56 57 void SetEntries(const std::vector<MultiVerKvEntry *> &entries); 58 59 void ReleaseEntries(void); 60 61 void GetEntries(std::vector<MultiVerKvEntry *> &entries) const; 62 63 void GetEntry(int index, MultiVerKvEntry *&entry); 64 65 void SetCommitsSize(int commitsSize); 66 67 int GetCommitsSize() const; 68 69 void SetEntriesSize(int entriesSize); 70 71 int GetEntriesSize() const; 72 73 void SetValueSlicesSize(int valueSlicesSize); 74 75 int GetValueSlicesSize() const; 76 77 void GetValueSliceHashNode(int index, ValueSliceHash &hashNode) const; 78 79 void SetValueSliceHashNodes(const std::vector<ValueSliceHash> &valueSliceHashNodes); 80 81 void GetValueSliceHashNodes(std::vector<ValueSliceHash> &valueSliceHashNodes) const; 82 83 void Clear() override; 84 85 protected: 86 ~MultiVerSyncTaskContext() override; 87 88 void CopyTargetData(const ISyncTarget *target, const TaskParam &taskParam) override; 89 90 private: 91 DECLARE_OBJECT_TAG(MultiVerSyncTaskContext); 92 93 std::vector<MultiVerCommitNode> commits_; 94 std::vector<MultiVerKvEntry *> entries_; 95 std::vector<ValueSliceHash> valueSliceHashNodes_; 96 int commitsIndex_ = 0; 97 int commitsSize_ = 0; 98 int entriesIndex_ = 0; 99 int entriesSize_ = 0; 100 int valueSlicesIndex_ = 0; 101 int valueSlicesSize_ = 0; 102 }; 103 } // namespace DistributedDB 104 105 #endif // MULTI_VER_SYNC_TASK_CONTEXT_H 106 #endif