diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cdc0396..c9380698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +### Fixes +- Report writes to missing retention policies through the batch exception handler and continue writing later batches. [Issue #1012](https://github.com/influxdata/influxdb-java/issues/1012) + ## 2.25 [2025-03-26] ### Improvements diff --git a/src/main/java/org/influxdb/InfluxDBException.java b/src/main/java/org/influxdb/InfluxDBException.java index 9f826f8e..930d6f24 100644 --- a/src/main/java/org/influxdb/InfluxDBException.java +++ b/src/main/java/org/influxdb/InfluxDBException.java @@ -48,6 +48,7 @@ public boolean isRetryWorth() { static final String CACHE_MAX_MEMORY_SIZE_EXCEEDED_ERROR = "cache-max-memory-size exceeded"; /* For all messages below see https://github.com/influxdata/influxdb/blob/master/services/httpd/handler.go */ static final String DATABASE_NOT_FOUND_ERROR = "database not found"; + static final String RETENTION_POLICY_NOT_FOUND_ERROR = "retention policy not found"; static final String USER_REQUIRED_ERROR = "user is required to write to database"; static final String USER_NOT_AUTHORIZED_ERROR = "user is not authorized to write to database"; static final String AUTHORIZATION_FAILED_ERROR = "authorization failed"; @@ -63,6 +64,17 @@ public boolean isRetryWorth() { } } + private static final class RetentionPolicyNotFoundException extends InfluxDBException { + private RetentionPolicyNotFoundException(final String message) { + super(message); + } + + @Override + public boolean isRetryWorth() { + return false; + } + } + public static final class HintedHandOffQueueNotEmptyException extends InfluxDBException { private HintedHandOffQueueNotEmptyException(final String message) { super(message); @@ -137,6 +149,9 @@ private static InfluxDBException buildExceptionFromErrorMessage(final String err if (errorMessage.contains(DATABASE_NOT_FOUND_ERROR)) { return new DatabaseNotFoundException(errorMessage); } + if (errorMessage.startsWith(RETENTION_POLICY_NOT_FOUND_ERROR)) { + return new RetentionPolicyNotFoundException(errorMessage); + } if (errorMessage.contains(POINTS_BEYOND_RETENTION_POLICY_ERROR)) { return new PointsBeyondRetentionPolicyException(errorMessage); } diff --git a/src/test/java/org/influxdb/impl/RetryCapableBatchWriterTest.java b/src/test/java/org/influxdb/impl/RetryCapableBatchWriterTest.java index 0a4f9de9..9807d278 100644 --- a/src/test/java/org/influxdb/impl/RetryCapableBatchWriterTest.java +++ b/src/test/java/org/influxdb/impl/RetryCapableBatchWriterTest.java @@ -37,6 +37,27 @@ BatchPoints getBP(int count) { return b.build(); } + @Test + public void testMissingRetentionPolicyDoesNotBlockLaterBatches() { + InfluxDB influxDB = mock(InfluxDB.class); + BiConsumer, Throwable> errorHandler = mock(BiConsumer.class); + RetryCapableBatchWriter writer = new RetryCapableBatchWriter(influxDB, errorHandler, 150, 100); + BatchPoints invalidBatch = BatchPoints.database("db99").retentionPolicy("rp_not_exist") + .point(Point.measurement("invalid").addField("value", 1).build()).build(); + BatchPoints validBatch = BatchPoints.database("db99").retentionPolicy("autogen") + .point(Point.measurement("valid").addField("value", 1).build()).build(); + InfluxDBException failure = InfluxDBException.buildExceptionForErrorState( + createErrorBody("retention policy not found: rp_not_exist")); + doThrow(failure).when(influxDB).write(invalidBatch); + + writer.write(Collections.singletonList(invalidBatch)); + writer.write(Collections.singletonList(validBatch)); + + verify(influxDB).write(validBatch); + verify(influxDB).write(invalidBatch); + verify(errorHandler).accept(invalidBatch.getPoints(), failure); + } + @Test public void test() { InfluxDB mockInfluxDB = mock(InfluxDBImpl.class);