proxygen
SlidingBloomReplayCache.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <chrono>
12 #include <memory>
13 #include <vector>
14 
16 
19 
20 namespace fizz {
21 namespace server {
22 
24  private folly::AsyncTimeout {
25  public:
26  // CellType is the actual data type holding the buckets for a cell. The
27  // maximumum number of buckets corresponds to the bit size of the cell.
28  // You can use one of uint8_t, uint16_t, uint32_t, or uint64_t.
29  using CellType = uint64_t;
30  using HashFunction = std::function<CellType(const unsigned char*, size_t)>;
31  /*
32  * Create a time bucketed bloom filter with following parameters:
33  * - ttlInSeconds: TTL for each checked attempt in seconds.
34  * - requestsPerSecond: Estimated amount of requests to be able to handle
35  * without exceeding the acceptable false positive rate.
36  * - acceptableFPR: Acceptable rate of false positive for given TTL + RPS
37  * - evb: EventBase to run the clearing function on.
38  */
40  int64_t ttlInSeconds,
41  size_t requestsPerSecond,
42  double acceptableFPR,
43  folly::EventBase* evb);
44  ~SlidingBloomReplayCache() override = default;
45 
46  void set(folly::ByteRange query);
47 
48  bool test(folly::ByteRange query) const;
49 
50  bool testAndSet(folly::ByteRange query);
51 
53 
54  private:
55  void clearBucket(size_t bucket);
56  void clear();
57  void timeoutExpired() noexcept override;
58 
59  std::chrono::milliseconds bucketWidthInMs_;
60  size_t bitSize_;
61 
63 
64  // bit array as a buffer
65  std::unique_ptr<CellType[]> bitBuf_;
66 
68 };
69 
70 } // namespace server
71 } // namespace fizz
chrono
Definition: CMakeCache.txt:563
bool test(folly::ByteRange query) const
STL namespace.
requires E e noexcept(noexcept(s.error(std::move(e))))
std::function< CellType(const unsigned char *, size_t)> HashFunction
~SlidingBloomReplayCache() override=default
SlidingBloomReplayCache(int64_t ttlInSeconds, size_t requestsPerSecond, double acceptableFPR, folly::EventBase *evb)
folly::Future< ReplayCacheResult > check(folly::ByteRange) override
Definition: Actions.h:16
Definition: Traits.h:588