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 #ifndef CLOUD_UPLOAD_RECORDER_H
17 #define CLOUD_UPLOAD_RECORDER_H
18 
19 #include <map>
20 #include <mutex>
21 
22 #include "cloud/cloud_db_types.h"
23 #include "db_types.h"
24 
25 namespace DistributedDB {
26 class CloudUploadRecorder {
27 public:
28     void RecordUploadRecord(const std::string &table, const Bytes &hashKey, const CloudWaterType &type,
29         int64_t modifyTime);
30     bool IsIgnoreUploadRecord(const std::string &table, const Bytes &hashKey, const CloudWaterType &type,
31         int64_t modifyTime) const;
32     void ReleaseUploadRecord(const std::string &table, const CloudWaterType &type, Timestamp localWaterMark);
33     void SetUser(const std::string &user);
34 
35     CloudUploadRecorder() = default;
36     ~CloudUploadRecorder() = default;
37 private:
38     mutable std::mutex recordMutex_;
39     using TableUploadRecord = std::map<CloudWaterType, std::map<Bytes, int64_t>>;
40     using UserRecord = std::map<std::string, TableUploadRecord>;
41     std::map<std::string, UserRecord> uploadRecord_;
42     std::string currentUser_;
43 };
44 }
45 
46 #endif // CLOUD_UPLOAD_RECORDER_H