/Users/deen/code/yugabyte-db/src/yb/docdb/transaction_dump.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 YB_DOCDB_TRANSACTION_DUMP_H |
15 | | #define YB_DOCDB_TRANSACTION_DUMP_H |
16 | | |
17 | | #include "yb/common/doc_hybrid_time.h" |
18 | | #include "yb/common/read_hybrid_time.h" |
19 | | #include "yb/common/transaction.h" |
20 | | |
21 | | #include "yb/util/enums.h" |
22 | | #include "yb/util/slice.h" |
23 | | |
24 | | DECLARE_bool(dump_transactions); |
25 | | |
26 | | namespace yb { |
27 | | namespace docdb { |
28 | | |
29 | | YB_DEFINE_ENUM(TransactionDumpOp, |
30 | | ((kApplyIntents, 1)) // Apply intents at participant. |
31 | | ((kRead, 2)) // Any read. |
32 | | ((kCommit, 3)) // Transaction committed. |
33 | | ((kStatus, 4)) // Transaction status received. |
34 | | ((kConflicts, 5)) // Transaction conflicts. |
35 | | ((kApplied, 6)) // Transaction applied on all involved tablets. |
36 | | ((kRemove, 7)) // Transaction removed from participant. |
37 | | ); |
38 | | |
39 | | void TransactionDump(const SliceParts& parts); |
40 | | |
41 | | template <class T> |
42 | | struct DumpToSliceAsPod : public std::is_pod<T> {}; |
43 | | |
44 | | template <> |
45 | | struct DumpToSliceAsPod<DocHybridTime> : public std::integral_constant<bool, true> {}; |
46 | | |
47 | | template <> |
48 | | struct DumpToSliceAsPod<HybridTime> : public std::integral_constant<bool, true> {}; |
49 | | |
50 | | template <> |
51 | | struct DumpToSliceAsPod<ReadHybridTime> : public std::integral_constant<bool, true> {}; |
52 | | |
53 | | template <class T> |
54 | 0 | typename std::enable_if<DumpToSliceAsPod<T>::value, Slice>::type ToDumpSlice(const T& value) { |
55 | 0 | return Slice(pointer_cast<const char*>(&value), sizeof(value)); |
56 | 0 | } Unexecuted instantiation: std::__1::enable_if<DumpToSliceAsPod<yb::HybridTime>::value, yb::Slice>::type yb::docdb::ToDumpSlice<yb::HybridTime>(yb::HybridTime const&) Unexecuted instantiation: std::__1::enable_if<DumpToSliceAsPod<int>::value, yb::Slice>::type yb::docdb::ToDumpSlice<int>(int const&) Unexecuted instantiation: std::__1::enable_if<DumpToSliceAsPod<unsigned char>::value, yb::Slice>::type yb::docdb::ToDumpSlice<unsigned char>(unsigned char const&) Unexecuted instantiation: std::__1::enable_if<DumpToSliceAsPod<yb::ReadHybridTime>::value, yb::Slice>::type yb::docdb::ToDumpSlice<yb::ReadHybridTime>(yb::ReadHybridTime const&) Unexecuted instantiation: std::__1::enable_if<DumpToSliceAsPod<yb::DocHybridTime>::value, yb::Slice>::type yb::docdb::ToDumpSlice<yb::DocHybridTime>(yb::DocHybridTime const&) Unexecuted instantiation: std::__1::enable_if<DumpToSliceAsPod<bool>::value, yb::Slice>::type yb::docdb::ToDumpSlice<bool>(bool const&) Unexecuted instantiation: std::__1::enable_if<DumpToSliceAsPod<unsigned long>::value, yb::Slice>::type yb::docdb::ToDumpSlice<unsigned long>(unsigned long const&) |
57 | | |
58 | 0 | inline Slice ToDumpSlice(const TransactionId& value) { |
59 | 0 | return Slice(value.data(), value.size()); |
60 | 0 | } |
61 | | |
62 | 0 | inline Slice ToDumpSlice(Slice slice) { |
63 | 0 | return slice; |
64 | 0 | } |
65 | | |
66 | | template<class... Args> |
67 | 0 | void TransactionDump(TransactionDumpOp op, Args&&... args) { |
68 | 0 | size_t size = 0; |
69 | 0 | std::array<Slice, 2 + sizeof...(Args)> array = { |
70 | 0 | Slice(pointer_cast<const char*>(&size), sizeof(size)), |
71 | 0 | Slice(pointer_cast<const char*>(&op), 1), |
72 | 0 | ToDumpSlice(args)... |
73 | 0 | }; |
74 | 0 | for (size_t i = 1; i != array.size(); ++i) { |
75 | 0 | size += array[i].size(); |
76 | 0 | } |
77 | 0 | SliceParts parts(array); |
78 | 0 | TransactionDump(parts); |
79 | 0 | } Unexecuted instantiation: void yb::docdb::TransactionDump<yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::HybridTime const&, int>(yb::docdb::TransactionDumpOp, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::HybridTime const&, int&&) Unexecuted instantiation: void yb::docdb::TransactionDump<yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::HybridTime const&>(yb::docdb::TransactionDumpOp, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::HybridTime const&) Unexecuted instantiation: void yb::docdb::TransactionDump<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::HybridTime, unsigned char>(yb::docdb::TransactionDumpOp, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::HybridTime&&, unsigned char&&) Unexecuted instantiation: void yb::docdb::TransactionDump<yb::StronglyTypedUuid<yb::TransactionId_Tag>, yb::HybridTime const&, yb::Slice>(yb::docdb::TransactionDumpOp, yb::StronglyTypedUuid<yb::TransactionId_Tag>&&, yb::HybridTime const&, yb::Slice&&) Unexecuted instantiation: void yb::docdb::TransactionDump<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, yb::StronglyTypedUuid<yb::TransactionId_Tag> const, yb::ReadHybridTime const&, yb::DocHybridTime&, bool&, unsigned long, yb::Slice&, unsigned long, yb::Slice>(yb::docdb::TransactionDumpOp, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&&, yb::ReadHybridTime const&, yb::DocHybridTime&, bool&, unsigned long&&, yb::Slice&, unsigned long&&, yb::Slice&&) Unexecuted instantiation: void yb::docdb::TransactionDump<yb::StronglyTypedUuid<yb::TransactionId_Tag> const, yb::ReadHybridTime&, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::HybridTime&, unsigned char, yb::HybridTime&, yb::HybridTime&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(yb::docdb::TransactionDumpOp, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&&, yb::ReadHybridTime&, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::HybridTime&, unsigned char&&, yb::HybridTime&, yb::HybridTime&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) |
80 | | |
81 | 854M | #define YB_TRANSACTION_DUMP(op, ...) do { \ |
82 | 854M | if (FLAGS_dump_transactions) { \ |
83 | 0 | TransactionDump(::yb::docdb::TransactionDumpOp::BOOST_PP_CAT(k, op), __VA_ARGS__); \ |
84 | 0 | } \ |
85 | 854M | } while (false) |
86 | | |
87 | | } // namespace docdb |
88 | | } // namespace yb |
89 | | |
90 | | #endif // YB_DOCDB_TRANSACTION_DUMP_H |