Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/influxdb/InfluxDBException.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/influxdb/impl/RetryCapableBatchWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ BatchPoints getBP(int count) {
return b.build();
}

@Test
public void testMissingRetentionPolicyDoesNotBlockLaterBatches() {
InfluxDB influxDB = mock(InfluxDB.class);
BiConsumer<Iterable<Point>, 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);
Expand Down