YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
4.20k
  bool operator==(const ProducerTabletInfo& other) const {
38
4.20k
    return universe_uuid == other.universe_uuid &&
39
4.20k
           stream_id == other.stream_id &&
40
2.27k
           tablet_id == other.tablet_id;
41
4.20k
  }
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
228
  std::string MetricsString() const {
50
228
    std::stringstream ss;
51
228
    ss << universe_uuid << ":" << stream_id << ":" << tablet_id;
52
228
    return ss.str();
53
228
  }
54
55
  struct Hash {
56
8.09k
    std::size_t operator()(const ProducerTabletInfo& p) const noexcept {
57
8.09k
      std::size_t hash = 0;
58
8.09k
      boost::hash_combine(hash, p.universe_uuid);
59
8.09k
      boost::hash_combine(hash, p.stream_id);
60
8.09k
      boost::hash_combine(hash, p.tablet_id);
61
62
8.09k
      return hash;
63
8.09k
    }
64
  };
65
};
66
67
struct CDCCreationState {
68
  std::vector<CDCStreamId> created_cdc_streams;
69
  std::vector<ProducerTabletInfo> producer_entries_modified;
70
71
153
  void Clear() {
72
153
    created_cdc_streams.clear();
73
153
    producer_entries_modified.clear();
74
153
  }
75
};
76
77
7.77k
inline size_t hash_value(const ProducerTabletInfo& p) noexcept {
78
7.77k
  return ProducerTabletInfo::Hash()(p);
79
7.77k
}
80
81
} // namespace cdc
82
} // namespace yb
83
84
85
#endif // ENT_SRC_YB_CDC_CDC_UTIL_H