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_DEF_H
17 #define MULTI_VER_DEF_H
18 
19 #include <list>
20 #include <string>
21 #include <vector>
22 
23 #include "db_types.h"
24 
25 namespace DistributedDB {
26 using CommitID = std::vector<uint8_t>;
27 using Version = uint64_t;
28 static const size_t MULTI_VER_TAG_SIZE = 8;
29 
30 struct MultiVerCommitNode {
31     static const uint64_t LOCAL_FLAG = 1;
32     static const uint64_t NON_LOCAL_FLAG = 0;
33     std::vector<uint8_t> commitId;
34     std::vector<uint8_t> leftParent;
35     std::vector<uint8_t> rightParent;
36     uint64_t timestamp = 0;
37     uint64_t version = 0; // version for storage
38     uint64_t isLocal = 0; // merge node or native node
39     std::string deviceInfo; // device name
40 };
41 
42 struct MultiVerEntryAuxData {
43     uint64_t operFlag = 0;
44     uint64_t timestamp = 0;
45     uint64_t oriTimestamp = 0;
46 };
47 
48 struct MultiVerEntryData {
49     Key key;
50     Value value;
51     MultiVerEntryAuxData auxData; // auxiliaries
52 };
53 
54 struct MultiVerTrimedVersionData {
55     Key key; // hash key
56     uint64_t operFlag = 0;
57     uint64_t version = 0;
58 };
59 
60 struct MultiVerDiffData {
61     std::list<Entry> inserted;
62     std::list<Entry> updated;
63     std::list<Entry> deleted;
64     bool isCleared = false;
ResetMultiVerDiffData65     void Reset()
66     {
67         inserted.clear();
68         updated.clear();
69         deleted.clear();
70         isCleared = false;
71     }
72 };
73 
74 enum class MultiVerDataType {
75     NATIVE_TYPE,
76     ALL_TYPE,
77 };
78 }
79 
80 #endif // MULTI_VER_DEF_H
81