public void add(SourceRecord record) { ++numRecords; lastOffset = record.sourceOffset(); }
@Override public synchronized void markProcessed(SourceRecord record) throws InterruptedException { task.commitRecord(record); recordsSinceLastCommit += 1; offsetWriter.offset(record.sourcePartition(), record.sourceOffset()); }
protected static Struct keyFor(SourceRecord record) { return (Struct) record.key(); }
private SourceRecord createSourceRecordWithOffset(Map<String, ?> offset) { return new SourceRecord(null, offset, null, null, null); }
/** * Verify that the given {@link SourceRecord} is a valid tombstone, meaning it has a non-null key and key schema but null * value and value schema. * * @param record the source record; may not be null */ public static void isValidTombstone(SourceRecord record) { assertThat(record.key()).isNotNull(); assertThat(record.keySchema()).isNotNull(); assertThat(record.value()).isNull(); assertThat(record.valueSchema()).isNull(); }
private Struct getValue(List<SourceRecord> produced) { SourceRecord record = produced.get(0); return (Struct) record.value(); }
private static SourceRecord record() { return new SourceRecord(null, null, null, null, null, null); }
private Struct getValue(List<SourceRecord> produced) { SourceRecord record = produced.get(0); return (Struct) record.value(); }
@Override public boolean accepts(SourceRecord sourceRecord) { Document offsetDocument = SourceInfo.createDocumentFromOffset(sourceRecord.sourceOffset()); // .isPositionAtOrBefore is true IFF leadingReaderFinalOffsetDocument <= offsetDocument // we should stop (return false) IFF leadingReaderFinalOffsetDocument <= offsetDocument return ! SourceInfo.isPositionAtOrBefore(leadingReaderFinalOffsetDocument, offsetDocument, gtidFilter); } }
private Predicate<SourceRecord> stopOnPKPredicate(int pkValue) { return record -> { Struct key = (Struct) record.key(); return ((Integer) key.get(PK_FIELD)) == pkValue; }; }
/** * Produce an empty record to the heartbeat topic. * */ private SourceRecord heartbeatRecord(Map<String, ?> sourcePartition, Map<String, ?> sourceOffset) { final Integer partition = 0; return new SourceRecord(sourcePartition, sourceOffset, topicName, partition, KEY_SCHEMA, serverNameKey(key), null, null); }
private void changeSourceToLastSnapshotRecord(SourceRecord currentRecord) { final Struct envelope = (Struct)currentRecord.value(); final Struct source = (Struct)envelope.get("source"); if (source.getBoolean(SourceInfo.LAST_SNAPSHOT_RECORD_KEY) != null) { source.put(SourceInfo.LAST_SNAPSHOT_RECORD_KEY, true); } }
protected void assertOffset(SourceRecord record, String offsetField, Object expectedValue) { Map<String,?> offset = record.sourceOffset(); Object value = offset.get(offsetField); assertSameValue(value,expectedValue); }
/** * Create an "offset" containing a single timestamp element with the given value. * Needed because {@link ParallelSnapshotReader.ParallelHaltingPredicate} halts based on how * close the record's timestamp is to the present time. * @param tsSec the timestamp in the resulting offset. * @return an "offset" containing the given timestamp. */ private SourceRecord createSourceRecordWithTimestamp(Instant ts) { Map<String, ?> offset = Collections.singletonMap(SourceInfo.TIMESTAMP_KEY, ts.getEpochSecond()); return new SourceRecord(null, offset, null, null, null); } }
private Struct getAfter(SourceRecord record) { return (Struct)((Struct)record.value()).get("after"); }
protected void assertOffset(SourceRecord record, Map<String,?> expectedOffset) { Map<String,?> offset = record.sourceOffset(); assertThat(offset).isEqualTo(expectedOffset); }
private void assertFieldAbsent(SourceRecord record, String fieldName) { Struct value = (Struct) ((Struct) record.value()).get(Envelope.FieldName.AFTER); try { value.get(fieldName); fail("field should not be present"); } catch (DataException e) { //expected } }
protected void assertSourceInfo(SourceRecord record, String db, String schema, String table) { assertTrue(record.value() instanceof Struct); Struct source = ((Struct) record.value()).getStruct("source"); assertEquals(db, source.getString("db")); assertEquals(schema, source.getString("schema")); assertEquals(table, source.getString("table")); }
protected static Struct sourceFor(SourceRecord record) { Struct envelope = (Struct) record.value(); Field field = envelope.schema().field(Envelope.FieldName.SOURCE); if (field != null) { return envelope.getStruct(field.name()); } return null; } }