diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-08-05 23:30:09 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-08-05 23:30:09 +0100 |
commit | fdc6de263a58480519d683e67bb3dfa262d9b230 (patch) | |
tree | 1b2a5dbe54a02bacd008e38f2ef965ce40c9c8da /lib | |
parent | Add base handlers for gtid/xid events (diff) | |
download | mygrate-fdc6de263a58480519d683e67bb3dfa262d9b230.tar.bz2 mygrate-fdc6de263a58480519d683e67bb3dfa262d9b230.tar.xz mygrate-fdc6de263a58480519d683e67bb3dfa262d9b230.zip |
Handle gtid and xid transaction events
Diffstat (limited to 'lib')
-rw-r--r-- | lib/output/pq/updateDatabase.cpp | 30 | ||||
-rw-r--r-- | lib/output/pq/updateDatabase.h | 3 |
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp index 232e8f9..ea8797b 100644 --- a/lib/output/pq/updateDatabase.cpp +++ b/lib/output/pq/updateDatabase.cpp @@ -27,6 +27,8 @@ #include <streamSupport.h> namespace MyGrate::Output::Pq { + constexpr uint8_t STANDALONE {1}; + #ifndef __cpp_aggregate_paren_init ColumnDef::ColumnDef(std::string n, std::size_t o, bool p) : name {std::move(n)}, ordinal(o), is_pk(p) { } #endif @@ -266,14 +268,18 @@ namespace MyGrate::Output::Pq { void UpdateDatabase::beforeEvent(const MariaDB_Event_Ptr &) { - beginTx(); + if (!intx) { + beginTx(); + } } void UpdateDatabase::afterEvent(const MariaDB_Event_Ptr & e) { - output::pq::sql::updateSourcePosition::execute(this, e->next_event_pos, source); - commitTx(); + if (!intx) { + output::pq::sql::updateSourcePosition::execute(this, e->next_event_pos, source); + commitTx(); + } } void @@ -401,4 +407,22 @@ namespace MyGrate::Output::Pq { afterEvent(e); } } + + void + UpdateDatabase::gtid(MariaDB_Event_Ptr e) + { + beforeEvent(e); + if (!(e->event.gtid.flags & STANDALONE)) { + intx = true; + } + afterEvent(e); + } + + void + UpdateDatabase::xid(MariaDB_Event_Ptr e) + { + beforeEvent(e); + intx = false; + afterEvent(e); + } } diff --git a/lib/output/pq/updateDatabase.h b/lib/output/pq/updateDatabase.h index d2b4872..716d7f6 100644 --- a/lib/output/pq/updateDatabase.h +++ b/lib/output/pq/updateDatabase.h @@ -59,6 +59,8 @@ namespace MyGrate::Output::Pq { void insertRow(MariaDB_Event_Ptr) override; void tableMap(MariaDB_Event_Ptr) override; void rotate(MariaDB_Event_Ptr) override; + void gtid(MariaDB_Event_Ptr) override; + void xid(MariaDB_Event_Ptr) override; const uint64_t source; const std::string schema; @@ -81,6 +83,7 @@ namespace MyGrate::Output::Pq { Tables tables; Tables::const_iterator selected; MariaDB_Event_Ptr table_map; + bool intx {false}; }; } |