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..ba75a60772b 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,22 @@ public void basicServiceTest() throws InterruptedException { Assert.assertEquals(3, timeStoreTable.size()); } + @Test + public void putKeyReturnsFileFullAfterRetriesExhausted() throws IllegalAccessException { + IndexStoreService service = Mockito.spy(new IndexStoreService(fileAllocator, filePath, false)); + IndexFile fullIndexFile = Mockito.mock(IndexFile.class); + Mockito.when(fullIndexFile.putKey( + TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, 1L)) + .thenReturn(AppendResult.FILE_FULL); + FieldUtils.writeField(service, "currentWriteFile", fullIndexFile, true); + Mockito.doNothing().when(service).createNewIndexFile(Mockito.anyLong()); + + Assert.assertEquals(AppendResult.FILE_FULL, service.putKey( + TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, 1L)); + Mockito.verify(fullIndexFile, Mockito.times(3)).putKey( + TOPIC_NAME, TOPIC_ID, QUEUE_ID, KEY_SET, MESSAGE_OFFSET, MESSAGE_SIZE, 1L); + } + @Test public void doConvertOldFormatTest() throws IOException { indexService = new IndexStoreService(fileAllocator, filePath); @@ -392,4 +409,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 +}