1 /*
2 * Copyright (c) 2022 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 #include "single_ver_kv_sync_task_context.h"
17
18 namespace DistributedDB {
SingleVerKvSyncTaskContext()19 SingleVerKvSyncTaskContext::SingleVerKvSyncTaskContext()
20 : SingleVerSyncTaskContext(), syncStrategy_{}
21 {}
22
~SingleVerKvSyncTaskContext()23 SingleVerKvSyncTaskContext::~SingleVerKvSyncTaskContext()
24 {
25 }
26
GetQuerySyncId() const27 std::string SingleVerKvSyncTaskContext::GetQuerySyncId() const
28 {
29 std::lock_guard<std::mutex> autoLock(queryMutex_);
30 return query_.GetIdentify();
31 }
32
GetDeleteSyncId() const33 std::string SingleVerKvSyncTaskContext::GetDeleteSyncId() const
34 {
35 return GetDeviceId();
36 }
37
SetSyncStrategy(const SyncStrategy & strategy,bool isSchemaSync)38 void SingleVerKvSyncTaskContext::SetSyncStrategy(const SyncStrategy &strategy, bool isSchemaSync)
39 {
40 std::lock_guard<std::mutex> autoLock(syncStrategyMutex_);
41 syncStrategy_.permitSync = strategy.permitSync;
42 syncStrategy_.convertOnSend = strategy.convertOnSend;
43 syncStrategy_.convertOnReceive = strategy.convertOnReceive;
44 syncStrategy_.checkOnReceive = strategy.checkOnReceive;
45 isSchemaSync_ = isSchemaSync;
46 }
47
GetSchemaSyncStatus(QuerySyncObject & querySyncObject) const48 std::pair<bool, bool> SingleVerKvSyncTaskContext::GetSchemaSyncStatus(QuerySyncObject &querySyncObject) const
49 {
50 std::lock_guard<std::mutex> autoLock(syncStrategyMutex_);
51 (void) querySyncObject;
52 return {syncStrategy_.permitSync, isSchemaSync_};
53 }
54 }