|
| 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_COMMON_UTIL_H |
| 15 | +#define ENT_SRC_YB_CDC_CDC_COMMON_UTIL_H |
| 16 | + |
| 17 | +#include <string> |
| 18 | +#include <boost/functional/hash.hpp> |
| 19 | + |
| 20 | +#include "yb/cdc/cdc_service.pb.h" |
| 21 | + |
| 22 | +#include "yb/common/common_fwd.h" |
| 23 | +#include "yb/common/wire_protocol.h" |
| 24 | + |
| 25 | +#include "yb/consensus/raft_consensus.h" |
| 26 | +#include "yb/consensus/replicate_msgs_holder.h" |
| 27 | + |
| 28 | +#include "yb/docdb/docdb.h" |
| 29 | +#include "yb/docdb/primitive_value.h" |
| 30 | +#include "yb/docdb/ql_rowwise_iterator_interface.h" |
| 31 | +#include "yb/docdb/value_type.h" |
| 32 | + |
| 33 | +#include "yb/tablet/tablet.h" |
| 34 | +#include "yb/tablet/tablet_metadata.h" |
| 35 | +#include "yb/tablet/tablet_peer.h" |
| 36 | +#include "yb/tablet/transaction_participant.h" |
| 37 | + |
| 38 | +#include "yb/tserver/tablet_server.h" |
| 39 | +#include "yb/tserver/ts_tablet_manager.h" |
| 40 | + |
| 41 | +#include "yb/util/format.h" |
| 42 | + |
| 43 | +namespace yb { |
| 44 | +namespace cdc { |
| 45 | + |
| 46 | +YB_STRONGLY_TYPED_BOOL(ReplicateIntents); |
| 47 | + |
| 48 | +// Use boost::unordered_map instead of std::unordered_map because gcc release build |
| 49 | +// fails to compile correctly when TxnStatusMap is used with Result<> (due to what seems like |
| 50 | +// a bug in gcc where it tries to incorrectly destroy Status part of Result). |
| 51 | +typedef boost::unordered_map<TransactionId, |
| 52 | + TransactionStatusResult, |
| 53 | + TransactionIdHash> TxnStatusMap; |
| 54 | +typedef std::pair<uint64_t, size_t> RecordTimeIndex; |
| 55 | + |
| 56 | +void AddColumnToMap( |
| 57 | + const ColumnSchema &col_schema, |
| 58 | + const docdb::PrimitiveValue &col, |
| 59 | + cdc::KeyValuePairPB *kv_pair); |
| 60 | + |
| 61 | +void AddProtoRecordColumnToMap( |
| 62 | + const ColumnSchema &col_schema, |
| 63 | + const docdb::PrimitiveValue &col, |
| 64 | + cdc::KeyValuePairPB *kv_pair, |
| 65 | + bool is_proto_record, |
| 66 | + DatumMessagePB *cdc_datum_message = nullptr); |
| 67 | + |
| 68 | +Result<bool> SetCommittedRecordIndexForReplicateMsg( |
| 69 | + const consensus::ReplicateMsgPtr &msg, |
| 70 | + size_t index, |
| 71 | + const TxnStatusMap &txn_map, |
| 72 | + ReplicateIntents replicate_intents, |
| 73 | + std::vector<RecordTimeIndex> *records); |
| 74 | + |
| 75 | +Result<std::vector<RecordTimeIndex>> GetCommittedRecordIndexes( |
| 76 | + const consensus::ReplicateMsgs &msgs, |
| 77 | + const TxnStatusMap &txn_map, |
| 78 | + ReplicateIntents replicate_intents, |
| 79 | + OpId *checkpoint); |
| 80 | + |
| 81 | +Result<consensus::ReplicateMsgs> FilterAndSortWrites( |
| 82 | + const consensus::ReplicateMsgs &msgs, |
| 83 | + const TxnStatusMap &txn_map, |
| 84 | + ReplicateIntents replicate_intents, |
| 85 | + OpId *checkpoint); |
| 86 | + |
| 87 | +Result<TransactionStatusResult> GetTransactionStatus( |
| 88 | + const TransactionId &txn_id, |
| 89 | + const HybridTime &hybrid_time, |
| 90 | + tablet::TransactionParticipant *txn_participant); |
| 91 | + |
| 92 | +Result<TxnStatusMap> BuildTxnStatusMap( |
| 93 | + const consensus::ReplicateMsgs &messages, |
| 94 | + bool more_replicate_msgs, |
| 95 | + const std::shared_ptr<tablet::TabletPeer> &tablet_peer, |
| 96 | + tablet::TransactionParticipant *txn_participant); |
| 97 | + |
| 98 | +} // namespace cdc |
| 99 | +} // namespace yb |
| 100 | + |
| 101 | +#endif // ENT_SRC_YB_CDC_CDC_COMMON_UTIL_H |
0 commit comments