Skip to content
Merged
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 @@ -305,7 +305,7 @@ void unsafeRun() {
this.run0();
} catch (Throwable e) {
LOGGER.error("[SNAPSHOT_SUBSCRIBE_ERROR]", e);
reset();
reset("SUBSCRIBE_ERROR: " + e.getMessage());
scheduler.schedule(this::run, 1, TimeUnit.SECONDS);
}
}
Expand All @@ -321,8 +321,8 @@ private void run0() {
applySnapshot();
}

void reset() {
LOGGER.info("[SNAPSHOT_READ_SUBSCRIBER_RESET],node={}", node);
void reset(String reason) {
LOGGER.info("[SNAPSHOT_READ_SUBSCRIBER_RESET],node={},reason={}", node, reason);
partitions.forEach(SnapshotReadPartitionsManager.this::removePartition);
partitions.clear();
waitingMetadataReadyQueue.clear();
Expand All @@ -348,7 +348,7 @@ void applySnapshot() {
case ADD: {
Optional<Partition> partition = addPartition(topicIdPartition, snapshotWithOperation.snapshot);
if (partition.isEmpty()) {
reset();
reset(String.format("Cannot find partition %s", topicIdPartition));
return;
}
partition.ifPresent(p -> partitions.put(topicIdPartition, p));
Expand All @@ -360,7 +360,7 @@ void applySnapshot() {
if (partition != null) {
partition.snapshot(snapshotWithOperation.snapshot);
} else {
LOGGER.warn("[SNAPSHOT_READ_PATCH],[SKIP],{}", snapshotWithOperation);
LOGGER.error("[SNAPSHOT_READ_PATCH],[SKIP],{}", snapshotWithOperation);
}
snapshotWithOperations.poll();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
private int sessionId;
private int sessionEpoch;
boolean requestCommit = false;
boolean requestReset = false;

private final SnapshotReadPartitionsManager.Subscriber subscriber;
private final Node node;
Expand All @@ -81,8 +82,7 @@ public SubscriberRequester(SnapshotReadPartitionsManager.Subscriber subscriber,
}

public void reset() {
sessionId = 0;
sessionEpoch = 0;
requestReset = true;
}

public void close() {
Expand All @@ -97,6 +97,7 @@ private void request0() {
if (closed) {
return;
}
tryReset0();
lastRequestTime = time.milliseconds();
AutomqGetPartitionSnapshotRequestData data = new AutomqGetPartitionSnapshotRequestData().setSessionId(sessionId).setSessionEpoch(sessionEpoch).setVersion((short) 1);
if (version.isZeroZoneV2Supported()) {
Expand Down Expand Up @@ -132,6 +133,10 @@ private void handleResponse(ClientResponse clientResponse) {
if (closed) {
return;
}
if (tryReset0()) {
// If it needs to reset, then drop the response.
return;
}
if (!clientResponse.hasResponse()) {
if (clientResponse.wasDisconnected() || clientResponse.wasTimedOut()) {
LOGGER.warn("[GET_SNAPSHOTS],[REQUEST_FAIL],response={}", clientResponse);
Expand All @@ -149,16 +154,17 @@ private void handleResponse(ClientResponse clientResponse) {
LOGGER.error("[GET_SNAPSHOTS],[ERROR],response={}", resp);
return;
}
if (resp.sessionId() != sessionId) {
if (sessionId != 0 && resp.sessionId() != sessionId) {
// switch to a new session
subscriber.reset();
subscriber.reset(String.format("switch sessionId from %s to %s", sessionId, resp.sessionId()));
}
SnapshotReadPartitionsManager.OperationBatch batch = new SnapshotReadPartitionsManager.OperationBatch();
resp.topics().forEach(topic -> topic.partitions().forEach(partition -> {
String topicName = topicNameGetter.apply(topic.topicId());
if (topicName == null) {
subscriber.reset();
throw new RuntimeException(String.format("Cannot find topic uuid=%s, the kraft metadata replay delay or the topic is deleted.", topic.topicId()));
String reason = String.format("Cannot find topic uuid=%s, the kraft metadata replay delay or the topic is deleted.", topic.topicId());
subscriber.reset(reason);
throw new RuntimeException(reason);
}
batch.operations.add(convert(new TopicIdPartition(topic.topicId(), partition.partitionIndex(), topicName), partition));
}));
Expand All @@ -174,6 +180,17 @@ private void handleResponse(ClientResponse clientResponse) {
sessionEpoch = resp.sessionEpoch();
}

private boolean tryReset0() {
if (requestReset) {
sessionId = 0;
sessionEpoch = 0;
requestReset = false;
return true;
} else {
return false;
}
}

static SnapshotReadPartitionsManager.SnapshotWithOperation convert(TopicIdPartition topicIdPartition,
AutomqGetPartitionSnapshotResponseData.PartitionSnapshot src) {
PartitionSnapshot.Builder snapshot = PartitionSnapshot.builder();
Expand Down
Loading