• 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 DISTRIBUTEDDB_CONSTANT_H
17 #define DISTRIBUTEDDB_CONSTANT_H
18 
19 #include <string>
20 
21 namespace DistributedDB {
22 class DBConstant {
23 public:
24     static constexpr const size_t MAX_KEY_SIZE = 1024;
25     static constexpr const size_t MAX_VALUE_SIZE = 4 * 1024 * 1024; // 4M
26     static constexpr const size_t MAX_SET_VALUE_SIZE =  64 * 1024 * 1024; // 64M
27     static constexpr const size_t MAX_FIELD_NUM = 2000;
28     static constexpr const size_t MAX_BATCH_SIZE = 128;
29     static constexpr const size_t MAX_DEV_LENGTH = 128;
30     static constexpr const size_t MAX_TRANSACTION_KEY_VALUE_LENS = 512 * 1024 * 1024; // 512M
31 
32     static constexpr const size_t MAX_DATA_DIR_LENGTH = 512;
33 
34     static constexpr const size_t MAX_INKEYS_SIZE = 128;
35     static constexpr const size_t MAX_SQL_ARGS_COUNT = 100;
36     static constexpr const size_t MAX_IN_COUNT = 100;
37 
38     static constexpr const int DB_TYPE_LOCAL = 1;
39     static constexpr const int DB_TYPE_MULTI_VER = 2;
40     static constexpr const int DB_TYPE_SINGLE_VER = 3;
41 
42     static constexpr const int QUEUED_SYNC_LIMIT_DEFAULT = 32;
43     static constexpr const int QUEUED_SYNC_LIMIT_MIN = 1;
44     static constexpr const int QUEUED_SYNC_LIMIT_MAX = 4096;
45 
46     static constexpr const int MAX_DEVICES_SIZE = 100;
47     static constexpr const int MAX_COMMIT_SIZE = 1000000;
48     static constexpr const int MAX_ENTRIES_SIZE = 1000000;
49 
50     static constexpr const uint32_t MAX_COLUMN  = 32767;
51 
52     static constexpr const int MAX_REMOTEDATA_SIZE = 4 * 1024 * 1024;  // 4M.
53 
54     static constexpr const int DEFAULT_ITER_TIMES = 5000;
55 
56     // In querySync, when getting query data finished,
57     // if the block size reach the half of max block size, will get deleted data next;
58     // if the block size not reach the half of max block size, will not get deleted data.
59     static constexpr const float QUERY_SYNC_THRESHOLD = 0.50;
60 
61     static constexpr const uint64_t MAX_USER_ID_LENGTH = 128;
62     static constexpr const uint64_t MAX_APP_ID_LENGTH = 128;
63     static constexpr const uint64_t MAX_STORE_ID_LENGTH = 128;
64     static constexpr const uint64_t MAX_SUB_USER_LENGTH = 128;
65 
66     static constexpr const char *MULTI_SUB_DIR = "multi_ver";
67     static constexpr const char *SINGLE_SUB_DIR = "single_ver";
68     static constexpr const char *LOCAL_SUB_DIR = "local";
69 
70     static constexpr const char *MAINDB_DIR = "main";
71     static constexpr const char *METADB_DIR = "meta";
72     static constexpr const char *CACHEDB_DIR = "cache";
73 
74     static constexpr const char *LOCAL_DATABASE_NAME = "local";
75     static constexpr const char *MULTI_VER_DATA_STORE = "multi_ver_data";
76     static constexpr const char *MULTI_VER_COMMIT_STORE = "commit_logs";
77     static constexpr const char *MULTI_VER_VALUE_STORE = "value_storage";
78     static constexpr const char *MULTI_VER_META_STORE = "meta_storage";
79     static constexpr const char *SINGLE_VER_DATA_STORE = "gen_natural_store";
80     static constexpr const char *SINGLE_VER_META_STORE = "meta";
81     static constexpr const char *SINGLE_VER_CACHE_STORE = "cache";
82 
83     static constexpr const char *SQLITE_URL_PRE = "file:";
84     static constexpr const char *DB_EXTENSION = ".db";
85     static constexpr const char *SQLITE_MEMDB_IDENTIFY = "?mode=memory&cache=shared";
86 
87     static constexpr const char *SCHEMA_KEY = "schemaKey";
88     static constexpr const char *RELATIONAL_SCHEMA_KEY = "relational_schema";
89     static constexpr const char *RELATIONAL_TRACKER_SCHEMA_KEY = "relational_tracker_schema";
90     static constexpr const char *RDB_KNOWLEDGE_SCHEMA_KEY = "rdbKnowledgeSchemaKey";
91 
92     static constexpr const char *RD_KV_COLLECTION_MODE = "{\"mode\" : \"kv\"}";
93     static constexpr const char *RD_KV_HASH_COLLECTION_MODE = "{\"mode\" : \"kv\",\"indextype\" : \"hash\"}";
94 
95     static constexpr const char *PATH_POSTFIX_UNPACKED = "_unpacked";
96     static constexpr const char *PATH_POSTFIX_IMPORT_BACKUP = "_import_bak";
97     static constexpr const char *PATH_POSTFIX_IMPORT_ORIGIN = "_import_ori";
98     static constexpr const char *PATH_POSTFIX_IMPORT_DUP = "_import_dup";
99     static constexpr const char *PATH_POSTFIX_EXPORT_BACKUP = "_export_bak";
100     // use for make sure create datebase and set label complete
101     static constexpr const char *PATH_POSTFIX_DB_INCOMPLETE = "_db_incomplete.lock";
102 
103     static constexpr const char *REKEY_FILENAME_POSTFIX_PRE = "_ctrl_pre";
104     static constexpr const char *REKEY_FILENAME_POSTFIX_OK = "_ctrl_ok";
105     static constexpr const char *UPGRADE_POSTFIX = "_upgrade.lock";
106     // used for make sure meta split upgrade atomically
107     static constexpr const char *SET_SECOPT_POSTFIX = "_secopt.lock";
108     static constexpr const char *PATH_BACKUP_POSTFIX = "_bak";
109 
110     static constexpr const char *ID_CONNECTOR = "-";
111 
112     static constexpr const char *DELETE_KVSTORE_REMOVING = "_removing";
113     static constexpr const char *DB_LOCK_POSTFIX = ".lock";
114 
115     static constexpr const char *SUBSCRIBE_QUERY_PREFIX = "subscribe_query_";
116 
117     static constexpr const char *TRIGGER_REFERENCES_NEW = "NEW.";
118     static constexpr const char *TRIGGER_REFERENCES_OLD = "OLD.";
119 
120     static constexpr const char *UPDATE_META_FUNC = "update_meta_within_trigger";
121 
122     // Prefix Key in meta db
123     static constexpr const char *DEVICEID_PREFIX_KEY = "deviceId";
124     static constexpr const char *USERID_PREFIX_KEY = "userId";
125     static constexpr const char *QUERY_SYNC_PREFIX_KEY = "querySync";
126     static constexpr const char *DELETE_SYNC_PREFIX_KEY = "deleteSync";
127 
128     static constexpr const size_t MAX_NORMAL_PACK_ITEM_SIZE = 4000;
129     // slide window mode to reduce last ack transfer time
130     static constexpr const size_t MAX_HPMODE_PACK_ITEM_SIZE = 2000;
131 
132     static constexpr const uint32_t MIN_MTU_SIZE = 1024; // 1KB
133     static constexpr const uint32_t MAX_MTU_SIZE = 5242880; // 5MB
134 
135     static constexpr const uint32_t MIN_TIMEOUT = 5000; // 5s
136     static constexpr const uint32_t MAX_TIMEOUT = 60000; // 60s
137     static constexpr const uint32_t MAX_SYNC_TIMEOUT = 300000; // 300s
138     static constexpr const int INFINITE_WAIT = -1; // -1 is infinite waiting
139 
140     static constexpr const uint8_t DEFAULT_COMPTRESS_RATE = 100;
141 
142     static constexpr const size_t MAX_SYNC_BLOCK_SIZE = 31457280; // 30MB
143 
144     static constexpr const int DOUBLE_PRECISION = 15;
145     static constexpr const int MAX_DISTRIBUTED_TABLE_COUNT = 32;
146 
147     static constexpr const uint64_t MAX_LOG_SIZE_HIGH = 0x400000000ULL; // 16GB
148     static constexpr const uint64_t MAX_LOG_SIZE_LOW = 0x400000ULL; // 4MB
149     static constexpr const uint64_t MAX_LOG_SIZE_DEFAULT = 0x40000000ULL; // 1GB
150 
151     static constexpr const int DEF_LIFE_CYCLE_TIME = 60000; // 60S
152 
153     static constexpr const int RELATIONAL_LOG_TABLE_FIELD_NUM = 7; // field num is relational distributed log table
154 
155     static constexpr const uint64_t IGNORE_CONNECTION_ID = 0;
156     // Soft limit of a connection observer count.
157     static constexpr const int MAX_OBSERVER_COUNT = 8;
158 
159     // For relational
160     static constexpr const char *SYSTEM_TABLE_PREFIX = "naturalbase_rdb_";
161     static constexpr const char *RELATIONAL_PREFIX = "naturalbase_rdb_aux_";
162     static constexpr size_t RELATIONAL_PREFIX_SIZE = 20;
163     static constexpr const char *TIMESTAMP_ALIAS = "naturalbase_rdb_aux_timestamp";
164     static constexpr const char *LOG_POSTFIX = "_log";
165     static constexpr const char *META_TABLE_POSTFIX = "metadata";
166     static constexpr const char *KNOWLEDGE_TABLE_TYPE = "knowledge";
167 
168     static constexpr const char *LOG_TABLE_VERSION_3 = "3.0";
169     static constexpr const char *LOG_TABLE_VERSION_5_1 = "5.01";
170     static constexpr const char *LOG_TABLE_VERSION_5_3 = "5.03"; // add sharing_resource field
171     static constexpr const char *LOG_TABLE_VERSION_5_5 = "5.05"; // add status field
172     static constexpr const char *LOG_TABLE_VERSION_5_8 = "5.08"; // migrate cursor to meta table
173     static constexpr const char *LOG_TABLE_VERSION_5_9 = "5.09"; // insert retains the old version
174     static constexpr const char *LOG_TABLE_VERSION_5_10 = "5.10"; // retain downloading asset in update trigger
175     static constexpr const char *LOG_TABLE_VERSION_CURRENT = LOG_TABLE_VERSION_5_10;
176 
177     static constexpr const char *LOG_TABLE_VERSION_KEY = "log_table_version";
178 
179     static constexpr const char *REMOTE_DEVICE_SCHEMA_KEY_PREFIX = "remote_device_schema_";
180 
181     static constexpr const uint32_t MAX_CONDITION_KEY_LEN = 128;
182     static constexpr const uint32_t MAX_CONDITION_VALUE_LEN = 128;
183     static constexpr const uint32_t MAX_CONDITION_COUNT = 32;
184 
185     static constexpr const uint32_t REMOTE_QUERY_MAX_SQL_LEN = 1000000U;
186 
187     static constexpr const int HASH_KEY_SIZE = 32; // size of SHA256_DIGEST_LENGTH
188 
189     static constexpr const char *TABLE_IS_DROPPED = "table_is_dropped_";
190 
191     static constexpr const char *SQLITE_INNER_ROWID = "_rowid_";
192     static constexpr const int32_t DEFAULT_ROW_ID = -1;
193     static constexpr const int STR_TO_LL_BY_DEVALUE = 10;
194     // key in meta_data
195     static constexpr const char *LOCALTIME_OFFSET_KEY = "localTimeOffset";
196 
197     static constexpr const uint64_t OBSERVER_CHANGES_MASK = 0XF00;
198 
199     static constexpr const char *STORAGE_TYPE_LONG = "long";
200 
201     static constexpr const uint64_t INVALID_CURSOR = UINT64_MAX;
202 
203     static constexpr const char *KV_SYNC_TABLE_NAME = "sync_data";
204     static constexpr const char *KV_LOCAL_TABLE_NAME = "local_data";
205 
206     static constexpr const char *ROWID = "rowid";
207 
208     static constexpr const char *DEFAULT_USER = "default_user";
209 
210     static constexpr const char *DISTRIBUTED_DEFAULT_APP_ID = "distributeddata";
211 };
212 } // namespace DistributedDB
213 #endif // DISTRIBUTEDDB_CONSTANT_H
214