-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cdc-connector][mysql]Mysql add numRecordsOutBySnapshot and numRecordsOutByIncremental metrics #3456
[cdc-connector][mysql]Mysql add numRecordsOutBySnapshot and numRecordsOutByIncremental metrics #3456
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -28,9 +28,12 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.apache.flink.connector.base.source.reader.RecordEmitter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.apache.flink.util.Collector; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import io.debezium.data.Envelope; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import io.debezium.document.Array; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import io.debezium.relational.TableId; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import io.debezium.relational.history.HistoryRecord; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import io.debezium.relational.history.TableChanges; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.apache.kafka.connect.data.Struct; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.apache.kafka.connect.source.SourceRecord; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.slf4j.Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.slf4j.LoggerFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -97,7 +100,7 @@ protected void processElement( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (RecordUtils.isDataChangeRecord(element)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
updateStartingOffsetForSplit(splitState, element); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
reportMetrics(element); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
reportMetrics(element, splitState); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
emitElement(element, output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (RecordUtils.isHeartbeatEvent(element)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
updateStartingOffsetForSplit(splitState, element); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -120,7 +123,31 @@ private void emitElement(SourceRecord element, SourceOutput<T> output) throws Ex | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
debeziumDeserializationSchema.deserialize(element, outputCollector); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private void reportMetrics(SourceRecord element) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private void reportMetrics(SourceRecord element, MySqlSplitState splitState) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TableId tableId = RecordUtils.getTableId(element); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (splitState.isSnapshotSplitState()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sourceReaderMetrics.numRecordsOutSnapshotIncrease(tableId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (splitState.isBinlogSplitState()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (RecordUtils.isDataChangeRecord(element)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Struct value = (Struct) element.value(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (value != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Envelope.Operation operation = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Envelope.Operation.forCode( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
value.getString(Envelope.FieldName.OPERATION)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
switch (operation) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case CREATE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sourceReaderMetrics.numRecordsOutInsertIncrease(tableId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case UPDATE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sourceReaderMetrics.numRecordsOutUpdateIncrease(tableId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case DELETE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sourceReaderMetrics.numRecordsOutDeleteIncrease(tableId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We checked whether element is data change record or not in line 101.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you very much for helping me review the code. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Long messageTimestamp = RecordUtils.getMessageTimestamp(element); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for contirbution @ChengJie1053
Nit: How about changing
INCREMENTAL
toBINLOG
orCHANGE_EVENT
?INCREMENTAL
can be understood as aIncremental Snapshot
step.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your suggestion is great, and I will CHANGE it to CHANGE EVENT