Search in sources :

Example 1 with SnapshotMarker

use of com.couchbase.client.dcp.highlevel.SnapshotMarker in project kafka-connect-couchbase by couchbase.

the class CouchbaseReader method restoreSavedOffsets.

private void restoreSavedOffsets() {
    LOGGER.info("Resuming from saved offsets for {} of {} partitions", partitionToSavedSeqno.size(), partitions.size());
    for (Map.Entry<Integer, SeqnoAndVbucketUuid> entry : partitionToSavedSeqno.entrySet()) {
        final int partition = entry.getKey();
        final SeqnoAndVbucketUuid offset = entry.getValue();
        final long savedSeqno = offset.seqno();
        PartitionState ps = client.sessionState().get(partition);
        ps.setStartSeqno(savedSeqno);
        ps.setSnapshot(new SnapshotMarker(savedSeqno, savedSeqno));
        if (offset.vbucketUuid().isPresent()) {
            long vbuuid = offset.vbucketUuid().getAsLong();
            LOGGER.debug("Initializing failover log for partition {} using stored vbuuid {} ", partition, vbuuid);
            // Use seqno -1 (max unsigned) so this synthetic failover log entry will always be pruned
            // if the initial streamOpen request gets a rollback response. If there's no rollback
            // on initial request, then the seqno used here doesn't matter, because the failover log
            // gets reset when the stream is opened.
            ps.setFailoverLog(singletonList(new FailoverLogEntry(-1L, vbuuid)));
        } else {
            // If we get here, we're probably restoring the stream offset from a previous version of the connector
            // which didn't save vbucket UUIDs. Hope the current vbuuid in the failover log is the correct one.
            // CAVEAT: This doesn't always work, and sometimes triggers a rollback to zero.
            LOGGER.warn("No vBucket UUID is associated with stream offset for partition {}." + " This is normal if you're upgrading from connector version 3.4.5 or earlier," + " and should stop happening once the Kafka Connect framework asks the connector" + " to save its offsets (see connector worker config property 'offset.flush.interval.ms').", partition);
        }
        client.sessionState().set(partition, ps);
    }
}
Also used : FailoverLogEntry(com.couchbase.client.dcp.state.FailoverLogEntry) PartitionState(com.couchbase.client.dcp.state.PartitionState) SnapshotMarker(com.couchbase.client.dcp.highlevel.SnapshotMarker) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with SnapshotMarker

use of com.couchbase.client.dcp.highlevel.SnapshotMarker in project couchbase-elasticsearch-connector by couchbase.

the class DcpHelper method initSessionState.

public static void initSessionState(Client dcpClient, CheckpointService checkpointService, Set<Integer> partitions) throws IOException {
    final Map<Integer, Checkpoint> positions = checkpointService.load(partitions);
    final SessionState sessionState = dcpClient.sessionState();
    LOGGER.debug("Initializing DCP session state from checkpoint: {}", positions);
    for (Map.Entry<Integer, Checkpoint> entry : positions.entrySet()) {
        final int partition = entry.getKey();
        final Checkpoint checkpoint = entry.getValue();
        if (checkpoint == null) {
            continue;
        }
        final PartitionState ps = sessionState.get(partition);
        ps.setStartSeqno(checkpoint.getSeqno());
        ps.setSnapshot(new SnapshotMarker(checkpoint.getSnapshot().getStartSeqno(), checkpoint.getSnapshot().getEndSeqno()));
        // Use seqno -1 (max unsigned) so this synthetic failover log entry will always be pruned
        // if the initial streamOpen request gets a rollback response. If there's no rollback
        // on initial request, then the seqno used here doesn't matter, because the failover log
        // gets reset when the stream is opened.
        ps.setFailoverLog(singletonList(new FailoverLogEntry(-1L, checkpoint.getVbuuid())));
        LOGGER.debug("Initialized partition {} state = {}", partition, ps);
    }
}
Also used : SessionState(com.couchbase.client.dcp.state.SessionState) FailoverLogEntry(com.couchbase.client.dcp.state.FailoverLogEntry) PartitionState(com.couchbase.client.dcp.state.PartitionState) SnapshotMarker(com.couchbase.client.dcp.highlevel.SnapshotMarker) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

SnapshotMarker (com.couchbase.client.dcp.highlevel.SnapshotMarker)2 FailoverLogEntry (com.couchbase.client.dcp.state.FailoverLogEntry)2 PartitionState (com.couchbase.client.dcp.state.PartitionState)2 Map (java.util.Map)2 SessionState (com.couchbase.client.dcp.state.SessionState)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1