• 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_CONSTANT_H
17 #define CLOUD_DB_CONSTANT_H
18 
19 #include "cloud/cloud_store_types.h"
20 #include <string>
21 
22 namespace DistributedDB {
23 class CloudDbConstant {
24 public:
25     static constexpr const char *CLOUD_META_TABLE_PREFIX = "naturalbase_cloud_meta_";
26     static constexpr const char *GID_FIELD = "#_gid";
27     static constexpr const char *CREATE_FIELD = "#_createTime";
28     static constexpr const char *MODIFY_FIELD = "#_modifyTime";
29     static constexpr const char *DELETE_FIELD = "#_deleted";
30     static constexpr const char *CURSOR_FIELD = "#_cursor";
31     static constexpr const char *TYPE_FIELD = "#_type";
32     static constexpr const char *QUERY_FIELD = "#_query";
33     static constexpr const char *REFERENCE_FIELD = "#_reference";
34     static constexpr const char *VERSION_FIELD = "#_version";
35     static constexpr const char *ERROR_FIELD = "#_error";
36     static constexpr const char *SHARING_RESOURCE_FIELD = "#_sharing_resource";
37     static constexpr const char *HASH_KEY_FIELD = "#_hash_key";
38     static constexpr const char *ASSET = "asset";
39     static constexpr const char *ASSETS = "assets";
40     static constexpr const char *SHARED = "_shared";
41     static constexpr const char *CLOUD_OWNER = "cloud_owner";
42     static constexpr const char *CLOUD_PRIVILEGE = "cloud_privilege";
43     static constexpr const char *DEFAULT_CLOUD_DEV = "cloud";
44 
45     // use for inner
46     static constexpr const char *FLAG = "flag";
47     static constexpr const char *TIMESTAMP = "timestamp";
48     static constexpr const char *HASH_KEY = "hash_key";
49     static constexpr const char *STATUS = "status";
50     static constexpr const char *CLOUD_FLAG = "cloud_flag";
51 
52     // kv cloud field
53     static constexpr const char *CLOUD_KV_FIELD_KEY = "key";
54     static constexpr const char *CLOUD_KV_FIELD_VALUE = "value";
55     static constexpr const char *CLOUD_KV_FIELD_DEVICE = "cur_device";
56     static constexpr const char *CLOUD_KV_FIELD_ORI_DEVICE = "ori_device";
57     static constexpr const char *CLOUD_KV_FIELD_DEVICE_CREATE_TIME = "device_create_time";
58     static constexpr const char *CLOUD_KV_TABLE_NAME = "sync_data";
59     static constexpr const char *CLOUD_KV_FIELD_USERID = "userid";
60 
61     // data status changes to lock_change
62     static constexpr const char *TO_LOCAL_CHANGE = "status = CASE WHEN status == 2 THEN 3 ELSE status END";
63     // data status changes from unlocking to unlock
64     static constexpr const char *UNLOCKING_TO_UNLOCK = "status = CASE WHEN status == 1 THEN 0 ELSE status END";
65     // data status changes to unlock
66     static constexpr const char *TO_UNLOCK = "status = CASE WHEN status == 2 THEN 0 WHEN status == 3 THEN 1"
67         " ELSE status END";
68     // data status changes to lock
69     static constexpr const char *TO_LOCK = "status = CASE WHEN status == 0 THEN 2 WHEN status == 1 THEN 3"
70         " ELSE status END";
71 
72     static constexpr const char *CLOUD_VERSION_RECORD_PREFIX_KEY = "naturalbase_cloud_version_";
73 
74     static constexpr const char *FLAG_AND_DATA_MODE_NOTIFY = "DELETE#ALL_CLOUDDATA";
75 
76     static constexpr const char *FLAG_ONLY_MODE_NOTIFY = "RESERVE#ALL_CLOUDDATA";
77 
78     // cloud data timestamp is utc ms precision
79     // used for 100ns to ms when handle cloud data timestamp
80     static constexpr const uint32_t TEN_THOUSAND = 10000;
81     static constexpr const int64_t CLOUD_DEFAULT_TIMEOUT = -1;
82     static constexpr const uint32_t ONE_SECOND = 1000 * TEN_THOUSAND; // 1000ms
83 
84     static constexpr const int32_t MAX_UPLOAD_BATCH_COUNT = 2000;
85     static constexpr const int32_t MIN_UPLOAD_BATCH_COUNT = 1;
86     static constexpr const int32_t MAX_UPLOAD_SIZE = 128 * 1024 * 1024; // 128M
87     static constexpr const int32_t MIN_UPLOAD_SIZE = 1024; // 1024Bytes
88     static constexpr const int32_t MIN_RETRY_CONFLICT_COUNTS = -1; // unlimited
89 
90     static constexpr const int32_t MAX_ASYNC_DOWNLOAD_TASK = 12; // max async download task in process
91     static constexpr const int32_t MIN_ASYNC_DOWNLOAD_TASK = 1;
92     static constexpr const int32_t MAX_ASYNC_DOWNLOAD_ASSETS = 2000; // max async download assets count in one batch
93     static constexpr const int32_t MIN_ASYNC_DOWNLOAD_ASSETS = 1;
94 
95     static constexpr const int32_t COMMON_TASK_PRIORITY_LEVEL = -1;
96     static constexpr const int32_t PRIORITY_TASK_DEFALUT_LEVEL = 0;
97     static constexpr const int32_t PRIORITY_TASK_MAX_LEVEL = 2;
98     static constexpr const int32_t MAX_CONDITIONS_SIZE = 100;
99 
100     static constexpr const uint32_t ON_CHANGE_TRACKER = 0x1;
101     static constexpr const uint32_t ON_CHANGE_P2P = 0x2;
102 };
103 } // namespace DistributedDB
104 #endif // CLOUD_DB_CONSTANT_H