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 CloudSyncData {
40     std::string tableName;
41     CloudSyncBatch insData;
42     CloudSyncBatch updData;
43     CloudSyncBatch delData;
44     CloudSyncBatch lockData;
45     bool isCloudForcePushStrategy = false;
46     bool isCompensatedTask = false;
47     bool isShared = false;
48     int ignoredCount = 0;
49     bool isCloudVersionRecord = false;
50     CloudWaterType mode;
51     CloudSyncData() = default;
CloudSyncDataCloudSyncData52     CloudSyncData(const std::string &_tableName) : tableName(_tableName) {};
CloudSyncDataCloudSyncData53     CloudSyncData(const std::string &_tableName, CloudWaterType _mode) : tableName(_tableName), mode(_mode) {};
54 };
55 
56 struct CloudTaskConfig {
57     bool allowLogicDelete = false;
58 };
59 
60 template<typename Tp, typename... Types>
61 struct index_of : std::integral_constant<size_t, 0> {};
62 
63 template<typename Tp, typename... Types>
64 inline static constexpr size_t index_of_v = index_of<Tp, Types...>::value;
65 
66 template<typename Tp, typename First, typename... Rest>
67 struct index_of<Tp, First, Rest...>
68     : std::integral_constant<size_t, std::is_same_v<Tp, First> ? 0 : index_of_v<Tp, Rest...> + 1> {};
69 
70 template<typename... Types>
71 struct variant_size_of {
72     static constexpr size_t value = sizeof...(Types);
73 };
74 
75 template<typename T, typename... Types>
76 struct variant_index_of {
77     static constexpr size_t value = index_of_v<T, Types...>;
78 };
79 
80 template<typename... Types>
81 static variant_size_of<Types...> variant_size_test(const std::variant<Types...> &);
82 
83 template<typename T, typename... Types>
84 static variant_index_of<T, Types...> variant_index_test(const T &, const std::variant<Types...> &);
85 
86 template<typename T>
87 inline constexpr static int32_t TYPE_INDEX =
88     decltype(variant_index_test(std::declval<T>(), std::declval<Type>()))::value;
89 
90 inline constexpr static int32_t TYPE_MAX = decltype(variant_size_test(std::declval<Type>()))::value;
91 
92 } // namespace DistributedDB
93 #endif // CLOUD_DB_TYPES_H
94