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 size_t MAX_KEY_SIZE = 1024; 25 static constexpr size_t MAX_VALUE_SIZE = 4194304; 26 static constexpr size_t MAX_BATCH_SIZE = 128; 27 static constexpr size_t MAX_DEV_LENGTH = 128; 28 static constexpr size_t MAX_TRANSACTION_ENTRY_SIZE = 128; 29 30 static constexpr size_t MAX_DATA_DIR_LENGTH = 512; 31 32 static constexpr size_t MAX_INKEYS_SIZE = 128; 33 static constexpr size_t MAX_SQL_ARGS_COUNT = 100; 34 35 static constexpr int DB_TYPE_LOCAL = 1; 36 static constexpr int DB_TYPE_MULTI_VER = 2; 37 static constexpr int DB_TYPE_SINGLE_VER = 3; 38 39 static constexpr int QUEUED_SYNC_LIMIT_DEFAULT = 32; 40 static constexpr int QUEUED_SYNC_LIMIT_MIN = 1; 41 static constexpr int QUEUED_SYNC_LIMIT_MAX = 4096; 42 43 static constexpr int MAX_DEVICES_SIZE = 100; 44 static constexpr int MAX_COMMIT_SIZE = 1000000; 45 static constexpr int MAX_ENTRIES_SIZE = 1000000; 46 47 static constexpr uint32_t MAX_COLUMN = 32767; 48 49 static constexpr int MAX_REMOTEDATA_SIZE = 4194304; // 4M. 50 51 static constexpr int DEFAULT_ITER_TIMES = 5000; 52 53 // In querySync, when getting query data finished, 54 // if the block size reach the half of max block size, will get deleted data next; 55 // if the block size not reach the half of max block size, will not get deleted data. 56 static constexpr float QUERY_SYNC_THRESHOLD = 0.50; 57 58 static constexpr uint64_t MAX_USER_ID_LENGTH = 128; 59 static constexpr uint64_t MAX_APP_ID_LENGTH = 128; 60 static constexpr uint64_t MAX_STORE_ID_LENGTH = 128; 61 62 static const std::string MULTI_SUB_DIR; 63 static const std::string SINGLE_SUB_DIR; 64 static const std::string LOCAL_SUB_DIR; 65 66 static const std::string MAINDB_DIR; 67 static const std::string METADB_DIR; 68 static const std::string CACHEDB_DIR; 69 70 static const std::string LOCAL_DATABASE_NAME; 71 static const std::string MULTI_VER_DATA_STORE; 72 static const std::string MULTI_VER_COMMIT_STORE; 73 static const std::string MULTI_VER_VALUE_STORE; 74 static const std::string MULTI_VER_META_STORE; 75 static const std::string SINGLE_VER_DATA_STORE; 76 static const std::string SINGLE_VER_META_STORE; 77 static const std::string SINGLE_VER_CACHE_STORE; 78 79 static const std::string SQLITE_URL_PRE; 80 static const std::string SQLITE_DB_EXTENSION; 81 static const std::string SQLITE_MEMDB_IDENTIFY; 82 static const std::string SCHEMA_KEY; 83 static const std::string RELATIONAL_SCHEMA_KEY; 84 85 static const std::string PATH_POSTFIX_UNPACKED; 86 static const std::string PATH_POSTFIX_IMPORT_BACKUP; 87 static const std::string PATH_POSTFIX_IMPORT_ORIGIN; 88 static const std::string PATH_POSTFIX_IMPORT_DUP; 89 static const std::string PATH_POSTFIX_EXPORT_BACKUP; 90 static const std::string PATH_POSTFIX_DB_INCOMPLETE; // use for make sure create datebase and set label complete 91 92 static const std::string REKEY_FILENAME_POSTFIX_PRE; 93 static const std::string REKEY_FILENAME_POSTFIX_OK; 94 static const std::string UPGRADE_POSTFIX; 95 static const std::string SET_SECOPT_POSTFIX; // used for make sure meta split upgrade atomically 96 97 static const std::string PATH_BACKUP_POSTFIX; 98 99 static const std::string ID_CONNECTOR; 100 101 static const std::string DELETE_KVSTORE_REMOVING; 102 static const std::string DB_LOCK_POSTFIX; 103 104 static const std::string SUBSCRIBE_QUERY_PREFIX; 105 static const std::string TRIGGER_REFERENCES_NEW; 106 static const std::string TRIGGER_REFERENCES_OLD; 107 108 static const std::string UPDATE_META_FUNC; 109 110 static const std::string SYSTEM_TABLE_PREFIX; 111 112 // Prefix Key in meta db 113 static const std::string DEVICEID_PREFIX_KEY; 114 static const std::string QUERY_SYNC_PREFIX_KEY; 115 static const std::string DELETE_SYNC_PREFIX_KEY; 116 117 static constexpr uint32_t AUTO_SYNC_TIMEOUT = 5000; // 5s 118 static constexpr uint32_t MANUAL_SYNC_TIMEOUT = 5000; // 5s 119 120 static const size_t MAX_NORMAL_PACK_ITEM_SIZE = 4000; 121 static const size_t MAX_HPMODE_PACK_ITEM_SIZE = 2000; // slide window mode to reduce last ack transfer time 122 123 static constexpr uint32_t MIN_MTU_SIZE = 1024; // 1KB 124 static constexpr uint32_t MAX_MTU_SIZE = 5242880; // 5MB 125 126 static constexpr uint32_t MIN_TIMEOUT = 5000; // 5s 127 static constexpr uint32_t MAX_TIMEOUT = 60000; // 60s 128 129 static constexpr uint8_t DEFAULT_COMPTRESS_RATE = 100; 130 131 static constexpr size_t MAX_SYNC_BLOCK_SIZE = 31457280; // 30MB 132 133 static constexpr int DOUBLE_PRECISION = 15; 134 static constexpr int MAX_DISTRIBUTED_TABLE_COUNT = 32; 135 136 static constexpr uint64_t MAX_LOG_SIZE_HIGH = 0x400000000ULL; // 16GB 137 static constexpr uint64_t MAX_LOG_SIZE_LOW = 0x400000ULL; // 4MB 138 static constexpr uint64_t MAX_LOG_SIZE_DEFAULT = 0x40000000ULL; // 1GB 139 140 static constexpr int DEF_LIFE_CYCLE_TIME = 60000; // 60S 141 142 static constexpr int RELATIONAL_LOG_TABLE_FIELD_NUM = 7; // field num is relational distributed log table 143 144 static constexpr uint64_t IGNORE_CONNECTION_ID = 0; 145 // For relational 146 static const std::string RELATIONAL_PREFIX; 147 static const std::string TIMESTAMP_ALIAS; 148 static const std::string LOG_POSTFIX; 149 150 static const std::string LOG_TABLE_VERSION_1; 151 static const std::string LOG_TABLE_VERSION_2; 152 const char *LOG_TABLE_VERSION_3 = "3.0"; 153 static const std::string LOG_TABLE_VERSION_CURRENT; 154 155 static const std::string LOG_TABLE_VERSION_KEY; 156 157 static const std::string REMOTE_DEVICE_SCHEMA_KEY_PREFIX; 158 159 static constexpr uint32_t MAX_CONDITION_KEY_LEN = 128; 160 static constexpr uint32_t MAX_CONDITION_VALUE_LEN = 128; 161 static constexpr uint32_t MAX_CONDITION_COUNT = 32; 162 163 static constexpr uint32_t REMOTE_QUERY_MAX_SQL_LEN = 1000000U; 164 165 static constexpr int HASH_KEY_SIZE = 32; // size of SHA256_DIGEST_LENGTH 166 }; 167 } // namespace DistributedDB 168 #endif // DISTRIBUTEDDB_CONSTANT_H 169