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 STORAGE_EXECUTOR_H 17 #define STORAGE_EXECUTOR_H 18 19 #include <cstdint> 20 #include <string> 21 22 #include "macro_utils.h" 23 #include "single_ver_natural_store_commit_notify_data.h" 24 #include "types_export.h" 25 26 namespace DistributedDB { 27 enum class EngineState { 28 INVALID = -1, // default value, representative database is not generated 29 CACHEDB, 30 ATTACHING, // main db and cache db attach together 31 MIGRATING, // began to Migrate data 32 MAINDB, 33 ENGINE_BUSY, // In order to change handle during the migration process, it is temporarily unavailable 34 }; 35 36 enum class SingleVerDataType { 37 META_TYPE, 38 LOCAL_TYPE_SQLITE, 39 SYNC_TYPE, 40 }; 41 42 enum class DataStatus { 43 NOEXISTED, 44 DELETED, 45 EXISTED, 46 }; 47 48 enum class ExecutorState { 49 INVALID = -1, 50 MAINDB, 51 CACHEDB, 52 MAIN_ATTACH_CACHE, // After process crash and cacheDb existed 53 CACHE_ATTACH_MAIN, // while cacheDb migrating to mainDb 54 }; 55 56 struct DataOperStatus { 57 DataStatus preStatus = DataStatus::NOEXISTED; 58 bool isDeleted = false; 59 bool isDefeated = false; // whether the put data is defeated. 60 }; 61 62 struct SingleVerRecord { 63 Key key; 64 Value value; 65 Timestamp timestamp = 0; 66 uint64_t flag = 0; 67 std::string device; 68 std::string origDevice; 69 Key hashKey; 70 Timestamp writeTimestamp = 0; 71 }; 72 73 struct DeviceInfo { 74 bool isLocal = false; 75 std::string deviceName; 76 }; 77 78 struct LocalDataItem { 79 Key key; 80 Value value; 81 Timestamp timestamp = 0; 82 Key hashKey; 83 uint64_t flag = 0; 84 }; 85 86 struct NotifyConflictAndObserverData { 87 SingleVerNaturalStoreCommitNotifyData *committedData = nullptr; 88 DataItem getData; 89 Key hashKey; 90 DataOperStatus dataStatus; 91 }; 92 93 struct NotifyMigrateSyncData { 94 bool isRemote = false; 95 bool isRemoveDeviceData = false; 96 bool isPermitForceWrite = true; 97 SingleVerNaturalStoreCommitNotifyData *committedData = nullptr; 98 std::vector<Entry> entries{}; 99 }; 100 101 struct SyncDataDevices { 102 std::string origDev; 103 std::string dev; 104 }; 105 106 class StorageExecutor { 107 public: 108 explicit StorageExecutor(bool writable); 109 virtual ~StorageExecutor(); 110 111 // Delete the copy and assign constructors 112 DISABLE_COPY_ASSIGN_MOVE(StorageExecutor); 113 114 virtual bool GetWritable() const; 115 116 virtual int CheckCorruptedStatus(int errCode) const; 117 118 virtual bool GetCorruptedStatus() const; 119 120 virtual void SetCorruptedStatus() const; 121 122 virtual int Reset() = 0; 123 124 protected: 125 bool writable_; 126 mutable bool isCorrupted_; 127 }; 128 } // namespace DistributedDB 129 130 #endif // STORAGE_EXECUTOR_H 131