YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/docdb/transaction_status_cache.h
Line
Count
Source
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_DOCDB_TRANSACTION_STATUS_CACHE_H
15
#define YB_DOCDB_TRANSACTION_STATUS_CACHE_H
16
17
#include "yb/common/read_hybrid_time.h"
18
#include "yb/common/transaction.h"
19
20
namespace yb {
21
namespace docdb {
22
23
// Caches transaction statuses fetched by single IntentAwareIterator.
24
// Thread safety is not required, because IntentAwareIterator is used in a single thread only.
25
class TransactionStatusCache {
26
 public:
27
  TransactionStatusCache(const TransactionOperationContext& txn_context_opt,
28
                         const ReadHybridTime& read_time,
29
                         CoarseTimePoint deadline)
30
8.28M
      : txn_context_opt_(txn_context_opt), read_time_(read_time), deadline_(deadline) {}
31
32
  // Returns transaction commit time if already committed by the specified time or HybridTime::kMin
33
  // otherwise.
34
  Result<CommitMetadata> GetCommitData(const TransactionId& transaction_id);
35
36
 private:
37
  struct GetCommitDataResult;
38
39
  boost::optional<CommitMetadata> GetLocalCommitData(const TransactionId& transaction_id);
40
  Result<GetCommitDataResult> DoGetCommitData(const TransactionId& transaction_id);
41
42
  const TransactionOperationContext& txn_context_opt_;
43
  ReadHybridTime read_time_;
44
  CoarseTimePoint deadline_;
45
  std::unordered_map<TransactionId, CommitMetadata, TransactionIdHash> cache_;
46
};
47
48
} // namespace docdb
49
} // namespace yb
50
51
#endif  // YB_DOCDB_TRANSACTION_STATUS_CACHE_H