• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SYNC_TYPES_H
17 #define SYNC_TYPES_H
18 
19 #include <cstdint>
20 #include "query_sync_object.h"
21 #include "sync_config.h"
22 
23 namespace DistributedDB {
24 enum MessageId {
25     TIME_SYNC_MESSAGE = 1,
26     DATA_SYNC_MESSAGE,
27     COMMIT_HISTORY_SYNC_MESSAGE,
28     MULTI_VER_DATA_SYNC_MESSAGE,
29     VALUE_SLICE_SYNC_MESSAGE,
30     LOCAL_DATA_CHANGED,
31     ABILITY_SYNC_MESSAGE,
32     QUERY_SYNC_MESSAGE,
33     CONTROL_SYNC_MESSAGE,
34     UNKNOW_MESSAGE,
35 };
36 
37 enum SyncModeType {
38     PUSH,
39     PULL,
40     PUSH_AND_PULL,
41     AUTO_PUSH,
42     AUTO_PULL,
43     RESPONSE_PULL,
44     QUERY_PUSH,
45     QUERY_PULL,
46     QUERY_PUSH_PULL,
47     SUBSCRIBE_QUERY,
48     UNSUBSCRIBE_QUERY,
49     AUTO_SUBSCRIBE_QUERY,
50     INVALID_MODE
51 };
52 
53 enum class SyncType {
54     MANUAL_FULL_SYNC_TYPE = 1,
55     AUTO_SYNC_TYPE,
56     QUERY_SYNC_TYPE,
57     INVALID_SYNC_TYPE,
58 };
59 
60 enum ControlCmdType {
61     SUBSCRIBE_QUERY_CMD,
62     UNSUBSCRIBE_QUERY_CMD,
63     INVALID_CONTROL_CMD,
64 };
65 
66 struct UpdateWaterMark {
67     bool normalUpdateMark = false;
68     bool deleteUpdateMark = false;
69 };
70 
71 struct InternalSyncParma {
72     std::vector<std::string> devices;
73     int mode = 0;
74     bool isQuerySync = false;
75     QuerySyncObject syncQuery;
76 };
77 
78 constexpr int NOT_SURPPORT_SEC_CLASSIFICATION = 0xff;
79 constexpr uint8_t QUERY_SYNC_MODE_BASE = SyncModeType::QUERY_PUSH;
80 constexpr int AUTO_RETRY_TIMES = 3;
81 constexpr int MANUAL_RETRY_TIMES = 1;
82 constexpr int TIME_SYNC_WAIT_TIME = 5000; // 5s
83 constexpr uint64_t MAX_PACKETID = 10000000000; // max packetId
84 constexpr int NOTIFY_MIN_MTU_SIZE = 30 * 1024; // 30k
85 
86 constexpr int MAX_SUBSCRIBE_NUM_PER_DEV = 4;
87 constexpr int MAX_SUBSCRIBE_NUM_PER_DB = 8;
88 constexpr size_t MAX_DEVICES_NUM = 32;
89 
90 // index 0 for packetId in data request
91 // if ack reserve size is 1, reserve is {localWaterMark}
92 // if ack reserve size is above 2, reserve is {localWaterMark, packetId, deletedWaterMark...}
93 constexpr uint32_t REQUEST_PACKET_RESERVED_INDEX_PACKETID = 0;
94 constexpr uint32_t ACK_PACKET_RESERVED_INDEX_PACKETID = 1; // index 1 for packetId
95 constexpr uint32_t ACK_PACKET_RESERVED_INDEX_LOCAL_WATER_MARK = 0; // index 0 for localWaterMark
96 constexpr uint32_t ACK_PACKET_RESERVED_INDEX_DELETE_WATER_MARK = 2; // index 2 for deleteDataWaterMark
97 constexpr uint64_t MAX_TIMESTAMP = INT64_MAX;
98 constexpr uint8_t REMOVE_DEVICE_DATA_MARK = 1;
99 constexpr uint8_t SUPPORT_MARK = 1; // used for set is support one ability
100 }
101 #endif