From 066197d5cb9ebd1b6e83f13e5bfe46f5ce48f07c Mon Sep 17 00:00:00 2001 From: beautyarbutin <169455703+beautyarbutin@users.noreply.github.com> Date: Mon, 21 Sep 2026 14:09:53 +0800 Subject: [PATCH] [ISSUE #10859] Fix exhausted tiered index write result --- .../tieredstore/index/IndexStoreService.java | 5 +++-- .../index/IndexStoreServiceTest.java | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tieredstore/src/main/java/org/apache/rocketmq/tieredstore/index/IndexStoreService.java b/tieredstore/src/main/java/org/apache/rocketmq/tieredstore/index/IndexStoreService.java index 74f2b94afa8..6a56bca2b6b 100644 --- a/tieredstore/src/main/java/org/apache/rocketmq/tieredstore/index/IndexStoreService.java +++ b/tieredstore/src/main/java/org/apache/rocketmq/tieredstore/index/IndexStoreService.java @@ -211,8 +211,9 @@ public AppendResult putKey( return AppendResult.SUCCESS; } + AppendResult result = AppendResult.UNKNOWN_ERROR; for (int i = 0; i < 3; i++) { - AppendResult result = this.currentWriteFile.putKey( + result = this.currentWriteFile.putKey( topic, topicId, queueId, keySet, offset, size, timestamp); if (AppendResult.SUCCESS.equals(result)) { @@ -225,7 +226,7 @@ public AppendResult putKey( log.error("IndexStoreService#putKey, put key three times return error, topic={}, topicId={}, queueId={}, keySize={}, timestamp={}", topic, topicId, queueId, keySet.size(), timestamp); - return AppendResult.SUCCESS; + return result; } @Override diff --git a/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/index/IndexStoreServiceTest.java b/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/index/IndexStoreServiceTest.java index 0d849d5927f..7d6202c98f7 100644 --- a/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/index/IndexStoreServiceTest.java +++ b/tieredstore/src/test/java/org/apache/rocketmq/tieredstore/index/IndexStoreServiceTest.java @@ -50,6 +50,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -110,6 +111,23 @@ public void basicServiceTest() throws InterruptedException { Assert.assertEquals(3, timeStoreTable.size()); } + @Test + public void putKeyReturnsLastFailureAfterRetriesTest() throws IllegalAccessException { + IndexStoreService service = Mockito.spy(new IndexStoreService(fileAllocator, filePath, false)); + IndexFile indexFile = Mockito.mock(IndexFile.class); + Mockito.when(indexFile.putKey( + TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, 1L)) + .thenReturn(AppendResult.FILE_FULL, AppendResult.FILE_FULL, AppendResult.UNKNOWN_ERROR); + FieldUtils.writeField(service, "currentWriteFile", indexFile, true); + Mockito.doNothing().when(service).createNewIndexFile(Mockito.anyLong()); + + Assert.assertEquals(AppendResult.UNKNOWN_ERROR, service.putKey( + TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, 1L)); + Mockito.verify(indexFile, Mockito.times(3)).putKey( + TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, 1L); + Mockito.verify(service, Mockito.times(2)).createNewIndexFile(Mockito.anyLong()); + } + @Test public void doConvertOldFormatTest() throws IOException { indexService = new IndexStoreService(fileAllocator, filePath); @@ -392,4 +410,4 @@ public void queryCrossFileBoundaryTest() throws InterruptedException, ExecutionE Assert.assertFalse("Should find index items from file covering query range", results.isEmpty()); } -} \ No newline at end of file +}