Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ShardAcknowledgementManager {

private static final long WAIT_FOR_ACKNOWLEDGMENTS_TIMEOUT = 10L;

static final Duration CHECKPOINT_INTERVAL = Duration.ofMinutes(2);
static final long CHECKPOINT_INTERVAL = Duration.ofMinutes(2).toMillis();

private final DynamoDBSourceConfig dynamoDBSourceConfig;
private final Map<StreamPartition, ConcurrentLinkedQueue<ShardCheckpointStatus>> checkpoints = new ConcurrentHashMap<>();
Expand All @@ -61,7 +61,7 @@ public class ShardAcknowledgementManager {
private final List<StreamPartition> partitionsToGiveUp;
private boolean shutdownTriggered;

private Instant lastCheckpointTime;
private long lastCheckpointTime;

public ShardAcknowledgementManager(final AcknowledgementSetManager acknowledgementSetManager,
final EnhancedSourceCoordinator sourceCoordinator,
Expand All @@ -72,9 +72,9 @@ public ShardAcknowledgementManager(final AcknowledgementSetManager acknowledgeme
this.sourceCoordinator = sourceCoordinator;
this.dynamoDBSourceConfig = dynamoDBSourceConfig;
this.executorService = Executors.newSingleThreadExecutor(BackgroundThreadFactory.defaultExecutorThreadFactory("dynamodb-shard-ack-monitor"));
this.partitionsToRemove = Collections.synchronizedList(new ArrayList<>());
this.partitionsToRemove = new ArrayList<>();
this.partitionsToGiveUp = Collections.synchronizedList(new ArrayList<>());
this.lastCheckpointTime = Instant.now();
this.lastCheckpointTime = System.currentTimeMillis();

executorService.submit(() -> monitorAcknowledgments(stopWorkerConsumer));
}
Expand All @@ -85,6 +85,12 @@ void monitorAcknowledgments(final Consumer<StreamPartition> stopWorkerConsumer)
if (exit) {
break;
}
try {
// Idle between loops to save on CPU
Thread.sleep(300);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

LOG.info("Exiting acknowledgment manager");
Expand Down Expand Up @@ -189,14 +195,14 @@ public AcknowledgementSet createAcknowledgmentSet(
}

void updateOwnershipForAllShardPartitions() {
if (Duration.between(lastCheckpointTime, Instant.now()).compareTo(CHECKPOINT_INTERVAL) > 0) {
if (System.currentTimeMillis() - lastCheckpointTime > CHECKPOINT_INTERVAL) {
for (final StreamPartition streamPartition : checkpoints.keySet()) {
if (!partitionsToRemove.contains(streamPartition)) {
sourceCoordinator.saveProgressStateForPartition(streamPartition, dynamoDBSourceConfig.getShardAcknowledgmentTimeout());
}
}

lastCheckpointTime = Instant.now();
lastCheckpointTime = System.currentTimeMillis();
}
}

Expand Down Expand Up @@ -233,12 +239,13 @@ public void shutdown() {
}

private void removePartitions() {
partitionsToRemove.forEach(streamPartition -> {
for (final StreamPartition streamPartition : partitionsToRemove) {
checkpoints.remove(streamPartition);
ackStatuses.remove(streamPartition);
});

partitionsToRemove.clear();
}
if (!partitionsToRemove.isEmpty()){
partitionsToRemove.clear();
}
}

public void giveUpPartition(final StreamPartition streamPartition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,12 @@ public void run() {
LOG.debug("Reached end of shard");
break;
}

if (System.currentTimeMillis() - lastCheckpointTime > DEFAULT_CHECKPOINT_INTERVAL_MILLS) {
LOG.debug("{} records written to buffer for shard {}", recordsWrittenToBuffer, shardId);
if (shardAcknowledgementManager == null) {
if (shardAcknowledgementManager == null) {
if (System.currentTimeMillis() - lastCheckpointTime > DEFAULT_CHECKPOINT_INTERVAL_MILLS) {
LOG.debug("{} records written to buffer for shard {}", recordsWrittenToBuffer, shardId);
checkpointer.checkpoint(sequenceNumber);
lastCheckpointTime = System.currentTimeMillis();
}
lastCheckpointTime = System.currentTimeMillis();
}

GetRecordsResponse response = callGetRecords(shardIterator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.opensearch.dataprepper.plugins.source.dynamodb.coordination.state.StreamProgressState;

import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import java.util.function.Consumer;

Expand Down Expand Up @@ -107,7 +106,7 @@ void testUpdateOwnershipForAllShardPartitions() throws Exception {

// Set lastCheckpointTime to past to trigger checkpoint interval
setField(ShardAcknowledgementManager.class, shardAcknowledgementManager,
"lastCheckpointTime", Instant.now().minus(Duration.ofMinutes(5)));
"lastCheckpointTime", System.currentTimeMillis() - Duration.ofMinutes(5).toMillis());

// Call updateOwnershipForAllShardPartitions directly
shardAcknowledgementManager.updateOwnershipForAllShardPartitions();
Expand Down
Loading