cmccabe commented on code in PR #12177: URL: https://github.com/apache/kafka/pull/12177#discussion_r876326240
########## metadata/src/main/java/org/apache/kafka/controller/QuorumController.java: ########## @@ -1735,17 +1742,38 @@ public CompletableFuture<UpdateFeaturesResponseData> updateFeatures( ControllerRequestContext context, UpdateFeaturesRequestData request ) { - return appendWriteEvent("updateFeatures", context.deadlineNs(), () -> { - Map<String, Short> updates = new HashMap<>(); - Map<String, FeatureUpdate.UpgradeType> upgradeTypes = new HashMap<>(); - request.featureUpdates().forEach(featureUpdate -> { - String featureName = featureUpdate.feature(); - upgradeTypes.put(featureName, FeatureUpdate.UpgradeType.fromCode(featureUpdate.upgradeType())); - updates.put(featureName, featureUpdate.maxVersionLevel()); - }); - return featureControl.updateFeatures(updates, upgradeTypes, clusterControl.brokerSupportedVersions(), - request.validateOnly()); + final AtomicLong offsetToSnapshot = new AtomicLong(0L); + return appendWriteEvent("updateFeatures", context.deadlineNs(), new ControllerWriteOperation<Map<String, ApiError>>() { + @Override + public ControllerResult<Map<String, ApiError>> generateRecordsAndResult() throws Exception { + Map<String, Short> updates = new HashMap<>(); + Map<String, FeatureUpdate.UpgradeType> upgradeTypes = new HashMap<>(); + request.featureUpdates().forEach(featureUpdate -> { + String featureName = featureUpdate.feature(); + upgradeTypes.put(featureName, FeatureUpdate.UpgradeType.fromCode(featureUpdate.upgradeType())); + updates.put(featureName, featureUpdate.maxVersionLevel()); + }); + return featureControl.updateFeatures(updates, upgradeTypes, clusterControl.brokerSupportedVersions(), + request.validateOnly()); + } + + @Override + public void processBatchEndOffset(long previousBatchEndOffset, long offset) { + log.debug("Offset before metadata.version update {}. Offset after update {}", previousBatchEndOffset, offset); + offsetToSnapshot.set(previousBatchEndOffset); + } + }).thenApply(result -> { + // The future that this chained callback is attached to is completed synchronously from the Raft thread via + // the controller purgatory. See QuorumMetaLogListener#handleCommit. Since this callback is synchronous, + // we can safely create a snapshot of the prior offset before it gets cleaned up by the Raft thread. + long offset = offsetToSnapshot.get(); + if (offset > 0) { + log.info("Generating a snapshot prior to a metadata.version update that includes (epoch={}, offset={}) after {}.", + lastCommittedEpoch, lastCommittedOffset, newBytesSinceLastSnapshot); + snapshotGeneratorManager.createSnapshotGenerator(offset, lastCommittedEpoch, lastCommittedTimestamp); Review Comment: this will throw an exception if another snapshot is in progress... -- 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