1 /*
2 * Copyright (c) 2024 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 "process_recorder.h"
17
18 namespace DistributedDB {
ClearRecord()19 void ProcessRecorder::ClearRecord()
20 {
21 std::lock_guard<std::mutex> autoLock(recordMutex_);
22 downloadRecord_.clear();
23 uploadRecord_.clear();
24 }
25
IsDownloadFinish(int userIndex,const std::string & table) const26 bool ProcessRecorder::IsDownloadFinish(int userIndex, const std::string &table) const
27 {
28 return IsRecordFinish(userIndex, table, downloadRecord_);
29 }
30
MarkDownloadFinish(int userIndex,const std::string & table,bool finish)31 void ProcessRecorder::MarkDownloadFinish(int userIndex, const std::string &table, bool finish)
32 {
33 RecordFinish(userIndex, table, finish, downloadRecord_);
34 }
35
IsUploadFinish(int userIndex,const std::string & table) const36 bool ProcessRecorder::IsUploadFinish(int userIndex, const std::string &table) const
37 {
38 return IsRecordFinish(userIndex, table, uploadRecord_);
39 }
40
MarkUploadFinish(int userIndex,const std::string & table,bool finish)41 void ProcessRecorder::MarkUploadFinish(int userIndex, const std::string &table, bool finish)
42 {
43 RecordFinish(userIndex, table, finish, uploadRecord_);
44 }
45
IsRecordFinish(int userIndex,const std::string & table,const std::map<int,std::map<std::string,bool>> & record) const46 bool ProcessRecorder::IsRecordFinish(int userIndex, const std::string &table,
47 const std::map<int, std::map<std::string, bool>> &record) const
48 {
49 std::lock_guard<std::mutex> autoLock(recordMutex_);
50 if (record.find(userIndex) == record.end()) {
51 return false;
52 }
53 if (record.at(userIndex).find(table) == record.at(userIndex).end()) {
54 return false;
55 }
56 return record.at(userIndex).at(table);
57 }
58
RecordFinish(int userIndex,const std::string & table,bool finish,std::map<int,std::map<std::string,bool>> & record)59 void ProcessRecorder::RecordFinish(int userIndex, const std::string &table, bool finish,
60 std::map<int, std::map<std::string, bool>> &record)
61 {
62 std::lock_guard<std::mutex> autoLock(recordMutex_);
63 record[userIndex][table] = finish;
64 }
65 }