diff --git a/store/src/main/java/com/automq/rocketmq/store/S3ObjectManager.java b/store/src/main/java/com/automq/rocketmq/store/S3ObjectManager.java index cd524dcaf..b934b01a8 100644 --- a/store/src/main/java/com/automq/rocketmq/store/S3ObjectManager.java +++ b/store/src/main/java/com/automq/rocketmq/store/S3ObjectManager.java @@ -44,6 +44,7 @@ public class S3ObjectManager implements ObjectManager { private static final Logger LOGGER = LoggerFactory.getLogger(S3ObjectManager.class); + static final int MIN_OBJECT_TTL_MINUTES = 10; private final StoreMetadataService metaService; public S3ObjectManager(StoreMetadataService metaService) { @@ -54,6 +55,7 @@ public S3ObjectManager(StoreMetadataService metaService) { public CompletableFuture prepareObject(int count, long ttl) { // Covert ttl from milliseconds to minutes int minutes = (int) TimeUnit.MILLISECONDS.toMinutes(ttl); + minutes = Math.max(minutes, MIN_OBJECT_TTL_MINUTES); return metaService.prepareS3Objects(count, minutes); } diff --git a/store/src/test/java/com/automq/rocketmq/store/S3ObjectManagerTest.java b/store/src/test/java/com/automq/rocketmq/store/S3ObjectManagerTest.java index 866d8a152..dc7dd4fc1 100644 --- a/store/src/test/java/com/automq/rocketmq/store/S3ObjectManagerTest.java +++ b/store/src/test/java/com/automq/rocketmq/store/S3ObjectManagerTest.java @@ -74,8 +74,11 @@ void prepareObject() { // 2 Minutes retention CompletableFuture preparedObject = objectManager.prepareObject(10, 1000 * 60 * 2); assertEquals(100L, preparedObject.join()); + verify(metadataService).prepareS3Objects(10, Math.max(2, S3ObjectManager.MIN_OBJECT_TTL_MINUTES)); - verify(metadataService).prepareS3Objects(10, 2); + preparedObject = objectManager.prepareObject(10, 1000 * 60 * 40); + assertEquals(100L, preparedObject.join()); + verify(metadataService).prepareS3Objects(10, Math.max(40, S3ObjectManager.MIN_OBJECT_TTL_MINUTES)); } @Test