Commit c7a3c17
Dylan Terry
This commit addresses an issue where acknowledgments (ACKs) were sometimes sent to the master before binlog events were fully written and fsynced to disk during backup operations. Sending ACKs prematurely in semi-synchronous replication could lead to data loss if the replica fails after sending the ACK but before persisting the event.
Key changes:
- Introduced an `EventHandler` interface with a `HandleEvent` method for
processing binlog events. This allows custom event handling logic to
be injected into the replication stream.
- Added an `eventHandler` field to `BinlogSyncer` and provided a
`SetEventHandler` method to assign an event handler. This enables
`BinlogSyncer` to delegate event processing to the assigned handler.
- Implemented `BackupEventHandler` which writes binlog events to disk
and ensures that each event is fsynced before returning. This ensures
data durability before ACKs are sent.
- Modified the `onStream` method in `BinlogSyncer` to separate event
parsing (`parseEvent`) from event handling and ACK sending
(`handleEventAndACK`). This adheres to the single-responsibility
principle and makes the code cleaner.
- Moved state updates (e.g., updating `b.nextPos`) and GTID set handling
from `parseEvent` to `handleEventAndACK` to avoid side effects during
parsing.
- Ensured that ACKs are sent only after the event has been fully
processed and fsynced by sending the ACK in `handleEventAndACK` after
event handling.1 parent 3a665d0 commit c7a3c17
3 files changed
+253
-72
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
44 | 55 | | |
45 | 56 | | |
46 | 57 | | |
47 | 58 | | |
48 | 59 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 60 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 70 | + | |
| 71 | + | |
67 | 72 | | |
68 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
69 | 77 | | |
70 | | - | |
71 | | - | |
72 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
73 | 81 | | |
74 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
75 | 102 | | |
76 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
77 | 110 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 111 | + | |
| 112 | + | |
81 | 113 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
88 | 117 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 118 | + | |
95 | 119 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 120 | + | |
| 121 | + | |
99 | 122 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
104 | 126 | | |
105 | | - | |
106 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
107 | 136 | | |
108 | 137 | | |
109 | 138 | | |
110 | 139 | | |
111 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
112 | 152 | | |
113 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
114 | 163 | | |
115 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
116 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
117 | 184 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
0 commit comments