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 KV_STORE_TYPE_H 17 #define KV_STORE_TYPE_H 18 19 #include <functional> 20 #include <string> 21 #include <map> 22 23 #include "types_export.h" 24 25 namespace DistributedDB { 26 enum DBStatus { 27 DB_ERROR = -1, 28 OK = 0, 29 BUSY, 30 NOT_FOUND, 31 INVALID_ARGS, 32 TIME_OUT, 33 NOT_SUPPORT, 34 INVALID_PASSWD_OR_CORRUPTED_DB, 35 OVER_MAX_LIMITS, 36 INVALID_FILE, 37 NO_PERMISSION, 38 FILE_ALREADY_EXISTED, 39 SCHEMA_MISMATCH, 40 INVALID_SCHEMA, 41 READ_ONLY, 42 INVALID_VALUE_FIELDS, // invalid put value for json schema. 43 INVALID_FIELD_TYPE, // invalid put value field type for json schema. 44 CONSTRAIN_VIOLATION, // invalid put value constrain for json schema. 45 INVALID_FORMAT, // invalid put value format for json schema. 46 STALE, // new record is staler compared to the same key existed in db. 47 LOCAL_DELETED, // local data is deleted by the unpublish. 48 LOCAL_DEFEAT, // local data defeat the sync data while unpublish. 49 LOCAL_COVERED, // local data is covered by the sync data while unpublish. 50 INVALID_QUERY_FORMAT, 51 INVALID_QUERY_FIELD, 52 PERMISSION_CHECK_FORBID_SYNC, // permission check result , forbid sync. 53 ALREADY_SET, // already set. 54 COMM_FAILURE, // communicator may get some error. 55 EKEYREVOKED_ERROR, // EKEYREVOKED error when operating db file 56 SECURITY_OPTION_CHECK_ERROR, // such as remote device's SecurityOption not equal to local 57 SCHEMA_VIOLATE_VALUE, // Values already exist in dbFile do not match new schema 58 INTERCEPT_DATA_FAIL, // Interceptor push data failed. 59 LOG_OVER_LIMITS, // Log size is over the limits. 60 DISTRIBUTED_SCHEMA_NOT_FOUND, // the sync table is not a relational table 61 DISTRIBUTED_SCHEMA_CHANGED, // the schema was changed 62 MODE_MISMATCH, 63 NOT_ACTIVE, 64 USER_CHANGED, 65 }; 66 67 struct KvStoreConfig { 68 std::string dataDir; 69 }; 70 71 enum PragmaCmd { 72 AUTO_SYNC = 1, 73 SYNC_DEVICES = 2, 74 RM_DEVICE_DATA = 3, // remove the device data synced from remote by device name 75 PERFORMANCE_ANALYSIS_GET_REPORT, 76 PERFORMANCE_ANALYSIS_OPEN, 77 PERFORMANCE_ANALYSIS_CLOSE, 78 PERFORMANCE_ANALYSIS_SET_REPORTFILENAME, 79 GET_IDENTIFIER_OF_DEVICE, 80 GET_DEVICE_IDENTIFIER_OF_ENTRY, 81 GET_QUEUED_SYNC_SIZE, 82 SET_QUEUED_SYNC_LIMIT, 83 GET_QUEUED_SYNC_LIMIT, 84 SET_WIPE_POLICY, // set the policy of wipe remote stale data 85 RESULT_SET_CACHE_MODE, // Accept ResultSetCacheMode Type As PragmaData 86 RESULT_SET_CACHE_MAX_SIZE, // Allowed Int Type Range [1,16], Unit MB 87 SET_SYNC_RETRY, 88 SET_MAX_LOG_SIZE, 89 EXEC_CHECKPOINT, 90 }; 91 92 enum ResolutionPolicyType { 93 AUTO_LAST_WIN = 0, // resolve conflicts by timestamp(default value) 94 CUSTOMER_RESOLUTION = 1 // resolve conflicts by user 95 }; 96 97 enum ObserverMode { 98 OBSERVER_CHANGES_NATIVE = 1, 99 OBSERVER_CHANGES_FOREIGN = 2, 100 OBSERVER_CHANGES_LOCAL_ONLY = 4, 101 }; 102 103 enum SyncMode { 104 SYNC_MODE_PUSH_ONLY, 105 SYNC_MODE_PULL_ONLY, 106 SYNC_MODE_PUSH_PULL, 107 }; 108 109 enum ConflictResolvePolicy { 110 LAST_WIN = 0, 111 DEVICE_COLLABORATION, 112 }; 113 114 struct TableStatus { 115 std::string tableName; 116 DBStatus status; 117 }; 118 using KvStoreCorruptionHandler = std::function<void (const std::string &appId, const std::string &userId, 119 const std::string &storeId)>; 120 using StoreCorruptionHandler = std::function<void (const std::string &appId, const std::string &userId, 121 const std::string &storeId)>; 122 using SyncStatusCallback = std::function<void(const std::map<std::string, std::vector<TableStatus>> &devicesMap)>; 123 } // namespace DistributedDB 124 #endif // KV_STORE_TYPE_H 125