mimaison commented on code in PR #24336:
URL: https://github.com/apache/kafka/pull/24336#discussion_r4670104681
##########
storage/src/test/java/org/apache/kafka/storage/internals/log/LogLoaderTest.java:
##########
@@ -302,6 +304,49 @@ public UnifiedLog loadLog(File logDir, boolean
hadCleanShutdown, Map<TopicPartit
};
}
+ @Test
+ public void testRecoverySnapshotFailurePreservesRecords() throws
IOException {
+ LogConfig config = new LogConfig(Map.of());
+ UnifiedLog log = createLog(logDir, config);
+ log.appendAsLeader(LogTestUtils.singletonRecords("first".getBytes(),
mockTime.milliseconds()), 0);
+ log.roll();
+ log.appendAsLeader(LogTestUtils.singletonRecords("second".getBytes(),
mockTime.milliseconds()), 0);
+ List<Path> logFiles = log.logSegments().stream().map(s ->
s.log().file().toPath()).toList();
+ log.close();
+ log.producerStateManager().deleteSnapshotsBefore(Long.MAX_VALUE);
+ List<byte[]> originalBytes = new ArrayList<>();
+ for (Path file : logFiles) {
+ originalBytes.add(Files.readAllBytes(file));
+ }
+
+ // A directory at the snapshot path makes the write fail without
damaging either log segment.
+ Path snapshotPath = LogFileUtils.producerSnapshotFile(logDir,
1L).toPath();
+ Files.createDirectory(snapshotPath);
+ TopicPartition topicPartition =
UnifiedLog.parseTopicPartitionName(logDir);
+ LogDirFailureChannel failureChannel = new LogDirFailureChannel(1);
+ LeaderEpochFileCache epochCache = UnifiedLog.createLeaderEpochCache(
+ logDir, topicPartition, failureChannel, Optional.empty(),
mockTime.scheduler);
+ ProducerStateManager stateManager = new ProducerStateManager(
+ topicPartition, logDir, 60000, producerStateManagerConfig,
mockTime);
+ IOException failure = null;
+ try (LogSegments segments = new LogSegments(topicPartition)) {
+ LogLoader loader = new LogLoader(logDir, topicPartition, config,
mockTime.scheduler, mockTime,
+ failureChannel, false, segments, 0L, 0L, epochCache,
stateManager,
+ new ConcurrentHashMap<>(), false);
+ try {
+ loader.load();
+ } catch (IOException e) {
+ failure = e;
+ }
Review Comment:
Can we use assertThrows() here?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]