jsancio commented on code in PR #12761:
URL: https://github.com/apache/kafka/pull/12761#discussion_r1028467761


##########
metadata/src/main/java/org/apache/kafka/controller/QuorumController.java:
##########
@@ -568,45 +576,62 @@ void cancel() {
         }
 
         void reschedule(long delayNs) {
-            ControlEvent event = new ControlEvent(GENERATE_SNAPSHOT, this);
+            ControllerEvent event = new ControllerEvent(GENERATE_SNAPSHOT, 
this);
             queue.scheduleDeferred(event.name,
                 new EarliestDeadlineFunction(time.nanoseconds() + delayNs), 
event);
         }
 
+        void handleSnapshotFinished(Optional<Exception> exception) {
+            if (exception.isPresent()) {
+                log.error("Error while generating snapshot {}", 
generator.lastContainedLogOffset(), exception.get());
+            } else {
+                log.info("Finished generating snapshot {}.", 
generator.lastContainedLogOffset());
+            }
+
+            generator.writer().close();
+            generator = null;
+
+            // Delete every in-memory snapshot up to the committed offset. 
They are not needed since this
+            // snapshot generation finished.
+            snapshotRegistry.deleteSnapshotsUpTo(lastCommittedOffset);
+
+            // The snapshot counters for size-based and time-based snapshots 
could have changed to cause a new
+            // snapshot to get generated.
+            maybeGenerateSnapshot();

Review Comment:
   The quorum controller resets the size-based 
(`committedBytesSinceLastSnapshot`) and time-based 
(`oldestNonSnapshottedTimestamp`) variables when it starts a snapshot. If the 
snapshot fails these variables were still reset when snapshot generation 
started.
   
   This acts as a throttle. Snapshot generation will be trigger as often as 
what is described in `metadata.log.max.record.bytes.between.snapshots` and 
`metadata.log.max.snapshot.interval.ms` even if the snapshot happens to fail.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to