Search in sources :

Example 1 with SnapshotMarker

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

the class CheckpointClear method setCheckpointToNow.

private static void setCheckpointToNow(ConnectorConfig config, Set<SeedNode> kvNodes, CheckpointDao checkpointDao) throws IOException {
    final Client dcpClient = DcpHelper.newClient(config.group().name(), config.couchbase(), kvNodes, config.trustStore());
    try {
        dcpClient.connect().block();
        final int numPartitions = dcpClient.numPartitions();
        final Set<Integer> allPartitions = new HashSet<>(allPartitions(numPartitions));
        DcpHelper.getCurrentSeqnos(dcpClient, allPartitions);
        final SessionState sessionState = dcpClient.sessionState();
        final Map<Integer, Checkpoint> now = new HashMap<>();
        for (int i = 0; i < allPartitions.size(); i++) {
            PartitionState p = sessionState.get(i);
            final long seqno = p.getStartSeqno();
            now.put(i, new Checkpoint(p.getLastUuid(), seqno, new SnapshotMarker(seqno, seqno)));
        }
        checkpointDao.save("", now);
    } finally {
        dcpClient.disconnect().block();
    }
}
Also used : SessionState(com.couchbase.client.dcp.state.SessionState) Checkpoint(com.couchbase.connector.dcp.Checkpoint) HashMap(java.util.HashMap) PartitionState(com.couchbase.client.dcp.state.PartitionState) SnapshotMarker(com.couchbase.connector.dcp.SnapshotMarker) Client(com.couchbase.client.dcp.Client) Checkpoint(com.couchbase.connector.dcp.Checkpoint) HashSet(java.util.HashSet)

Aggregations

Client (com.couchbase.client.dcp.Client)1 PartitionState (com.couchbase.client.dcp.state.PartitionState)1 SessionState (com.couchbase.client.dcp.state.SessionState)1 Checkpoint (com.couchbase.connector.dcp.Checkpoint)1 SnapshotMarker (com.couchbase.connector.dcp.SnapshotMarker)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1