• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 CLOUD_DB_TYPES_H
17 #define CLOUD_DB_TYPES_H
18 
19 #include "cloud/cloud_store_types.h"
20 #include <string>
21 
22 namespace DistributedDB {
23 enum class CloudWaterType {
24     INSERT,
25     UPDATE,
26     DELETE,
27     BUTT // invalid cloud water type
28 };
29 
30 struct CloudSyncBatch {
31     std::vector<VBucket> record;
32     std::vector<VBucket> extend;
33     std::vector<int64_t> rowid;
34     std::vector<int64_t> timestamp;
35     std::vector<VBucket> assets;
36     std::vector<Bytes> hashKey;
37 };
38 
39 struct ReviseModTimeInfo {
40     Bytes hashKey;
41     int64_t curTime;
42     int64_t invalidTime;
43 };
44 
45 struct CloudSyncData {
46     std::string tableName;
47     CloudSyncBatch insData;
48     CloudSyncBatch updData;
49     CloudSyncBatch delData;
50     CloudSyncBatch lockData;
51     std::vector<ReviseModTimeInfo> revisedData;
52     bool isCloudForcePushStrategy = false;
53     bool isCompensatedTask = false;
54     bool isShared = false;
55     int ignoredCount = 0;
56     bool isCloudVersionRecord = false;
57     CloudWaterType mode;
58     CloudSyncData() = default;
CloudSyncDataCloudSyncData59     CloudSyncData(const std::string &_tableName) : tableName(_tableName) {};
CloudSyncDataCloudSyncData60     CloudSyncData(const std::string &_tableName, CloudWaterType _mode) : tableName(_tableName), mode(_mode) {};
61 };
62 
63 struct CloudTaskConfig {
64     bool allowLogicDelete = false;
65 };
66 
67 template<typename Tp, typename... Types>
68 struct index_of : std::integral_constant<size_t, 0> {};
69 
70 template<typename Tp, typename... Types>
71 inline static constexpr size_t index_of_v = index_of<Tp, Types...>::value;
72 
73 template<typename Tp, typename First, typename... Rest>
74 struct index_of<Tp, First, Rest...>
75     : std::integral_constant<size_t, std::is_same_v<Tp, First> ? 0 : index_of_v<Tp, Rest...> + 1> {};
76 
77 template<typename... Types>
78 struct variant_size_of {
79     static constexpr size_t value = sizeof...(Types);
80 };
81 
82 template<typename T, typename... Types>
83 struct variant_index_of {
84     static constexpr size_t value = index_of_v<T, Types...>;
85 };
86 
87 template<typename... Types>
88 static variant_size_of<Types...> variant_size_test(const std::variant<Types...> &);
89 
90 template<typename T, typename... Types>
91 static variant_index_of<T, Types...> variant_index_test(const T &, const std::variant<Types...> &);
92 
93 template<typename T>
94 inline constexpr static int32_t TYPE_INDEX =
95     decltype(variant_index_test(std::declval<T>(), std::declval<Type>()))::value;
96 
97 inline constexpr static int32_t TYPE_MAX = decltype(variant_size_test(std::declval<Type>()))::value;
98 
99 } // namespace DistributedDB
100 #endif // CLOUD_DB_TYPES_H
101