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 I_SYNC_STATE_MACHINE_H 17 #define I_SYNC_STATE_MACHINE_H 18 19 #include <string> 20 21 #include "icommunicator.h" 22 #include "ikvdb_sync_interface.h" 23 #include "query_sync_object.h" 24 #include "sync_target.h" 25 #include "sync_task_context.h" 26 27 namespace DistributedDB { 28 class ISyncStateMachine { 29 public: ~ISyncStateMachine()30 virtual ~ISyncStateMachine() {}; 31 32 // Init the SyncStateMachine, this function must be called before any other call. 33 virtual int Initialize(ISyncTaskContext *context, ISyncInterface *syncInterface, 34 const std::shared_ptr<Metadata> &metadata, ICommunicator *communicator) = 0; 35 36 // start a sync step 37 virtual int StartSync() = 0; 38 39 // send Message to the StateMachine 40 virtual int ReceiveMessageCallback(Message *inMsg) = 0; 41 42 // call when timeout 43 virtual int TimeoutCallback(TimerId timerId) = 0; 44 45 // Force stop the state machine 46 virtual void Abort() = 0; 47 48 // Force stop the state machine now 49 virtual void AbortImmediately() = 0; 50 51 // Force stop current task with sessionId 52 virtual void InnerErrorAbort(uint32_t sessionId) = 0; 53 54 // Called by CommErrHandler, Sub class should realize this function to abort sync when handle err 55 virtual void CommErrAbort(uint32_t sessionId = 0) = 0; 56 57 // start a timer to ResetWatchDog when sync data one (key,value) size bigger than mtu 58 virtual bool StartFeedDogForSync(uint32_t time, SyncDirectionFlag flag) = 0; 59 60 // stop timer to ResetWatchDog when sync data one (key,value) size bigger than mtu 61 virtual void StopFeedDogForSync(SyncDirectionFlag flag) = 0; 62 63 // check if need trigger query auto sync and get query from inMsg 64 virtual bool IsNeedTriggerQueryAutoSync(Message *inMsg, QuerySyncObject &query) = 0; 65 66 // Notify machine is closing, should release some lock 67 virtual void NotifyClosing() = 0; 68 69 // start a timer to ResetWatchDog when get data and send notify ack if need 70 virtual void StartFeedDogForGetData(uint32_t sessionId) = 0; 71 72 // start a timer to ResetWatchDog when get data 73 virtual void StopFeedDogForGetData() = 0; 74 75 // schema change and reset ability finish status 76 virtual void SchemaChange() = 0; 77 78 virtual void TimeChange() = 0; 79 }; 80 } // namespace DistributedDB 81 82 #endif // I_SYNC_STATE_MACHINE_H 83