Loading...
Searching...
No Matches
duplicate_manager.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <stdint.h>
23#include <unistd.h>
24
25#include <map>
26#include <memory>
27#include <mutex>
28#include <queue>
29#include <set>
30#include <thread>
31
33
34namespace resdb {
35
37 public:
38 DuplicateManager(const ResDBConfig& config);
40
41 bool CheckIfProposed(const std::string& hash);
42 uint64_t CheckIfExecuted(const std::string& hash);
43 void AddProposed(const std::string& hash);
44 void AddExecuted(const std::string& hash, uint64_t seq);
45 void EraseProposed(const std::string& hash);
46 void EraseExecuted(const std::string& hash);
47 bool CheckAndAddProposed(const std::string& hash);
48 bool CheckAndAddExecuted(const std::string& hash, uint64_t seq);
49 void UpdateRecentHash();
50
51 private:
52 bool IsStop();
53
54 private:
55 ResDBConfig config_;
56 std::set<std::string> proposed_hash_set_;
57 std::set<std::string> executed_hash_set_;
58 std::queue<std::pair<std::string, uint64_t>> proposed_hash_time_queue_;
59 std::queue<std::pair<std::string, uint64_t>> executed_hash_time_queue_;
60 std::map<std::string, uint64_t> executed_hash_seq_;
61 std::thread update_thread_;
62 std::mutex prop_mutex_;
63 std::mutex exec_mutex_;
64 uint64_t frequency_useconds_ = 5000000; // 5s
65 uint64_t window_useconds_ = 20000000; // 20s
66 bool stop_ = false;
67};
68
69} // namespace resdb
bool CheckAndAddExecuted(const std::string &hash, uint64_t seq)
void AddProposed(const std::string &hash)
void AddExecuted(const std::string &hash, uint64_t seq)
bool CheckAndAddProposed(const std::string &hash)
void EraseProposed(const std::string &hash)
bool CheckIfProposed(const std::string &hash)
uint64_t CheckIfExecuted(const std::string &hash)
void EraseExecuted(const std::string &hash)