YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/ent/src/yb/cdc/cdc_util.h
Line
Count
Source (jump to first uncovered line)
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 ENT_SRC_YB_CDC_CDC_UTIL_H
15
#define ENT_SRC_YB_CDC_CDC_UTIL_H
16
17
#include <stdlib.h>
18
#include <string>
19
#include <boost/functional/hash.hpp>
20
21
#include "yb/common/entity_ids_types.h"
22
#include "yb/util/format.h"
23
24
namespace yb {
25
namespace cdc {
26
27
struct ConsumerTabletInfo {
28
  std::string tablet_id;
29
  TableId table_id;
30
};
31
32
struct ProducerTabletInfo {
33
  std::string universe_uuid; /* needed on Consumer side for uniqueness. Empty on Producer */
34
  CDCStreamId stream_id; /* unique ID on Producer, but not on Consumer. */
35
  std::string tablet_id;
36
37
8.41k
  bool operator==(const ProducerTabletInfo& other) const {
38
8.41k
    return universe_uuid == other.universe_uuid &&
39
8.41k
           stream_id == other.stream_id &&
40
8.41k
           
tablet_id == other.tablet_id4.44k
;
41
8.41k
  }
42
43
0
  std::string ToString() const {
44
0
    return Format("{ universe_uuid: $0 stream_id: $1 tablet_id: $2 }",
45
0
                  universe_uuid, stream_id, tablet_id);
46
0
  }
47
48
  // String used as a descriptor id for metrics.
49
444
  std::string MetricsString() const {
50
444
    std::stringstream ss;
51
444
    ss << universe_uuid << ":" << stream_id << ":" << tablet_id;
52
444
    return ss.str();
53
444
  }
54
55
  struct Hash {
56
16.1k
    std::size_t operator()(const ProducerTabletInfo& p) const noexcept {
57
16.1k
      std::size_t hash = 0;
58
16.1k
      boost::hash_combine(hash, p.universe_uuid);
59
16.1k
      boost::hash_combine(hash, p.stream_id);
60
16.1k
      boost::hash_combine(hash, p.tablet_id);
61
62
16.1k
      return hash;
63
16.1k
    }
64
  };
65
};
66
67
struct CDCCreationState {
68
  std::vector<CDCStreamId> created_cdc_streams;
69
  std::vector<ProducerTabletInfo> producer_entries_modified;
70
71
306
  void Clear() {
72
306
    created_cdc_streams.clear();
73
306
    producer_entries_modified.clear();
74
306
  }
75
};
76
77
15.6k
inline size_t hash_value(const ProducerTabletInfo& p) noexcept {
78
15.6k
  return ProducerTabletInfo::Hash()(p);
79
15.6k
}
80
81
} // namespace cdc
82
} // namespace yb
83
84
85
#endif // ENT_SRC_YB_CDC_CDC_UTIL_H