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