Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imlement issue #439 : Retry capability for write(final BatchPoints batchPoints) as well #495

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions src/main/java/org/influxdb/impl/BatchProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,7 @@ public ConsistencyLevel getConsistencyLevel() {
return consistencyLevel;
}

BatchWriter getBatchWriter() {
return batchWriter;
}
}
10 changes: 9 additions & 1 deletion src/main/java/org/influxdb/impl/InfluxDBImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
Expand Down Expand Up @@ -415,6 +416,14 @@ public void write(final int udpPort, final Point point) {

@Override
public void write(final BatchPoints batchPoints) {
if (isBatchEnabled()) {
batchProcessor.getBatchWriter().write(Collections.singleton(batchPoints));
} else {
writeNoRetry(batchPoints);
}
}

void writeNoRetry(final BatchPoints batchPoints) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand you don't want to expose this method but maybe we should review if this behavior is really necessary. I have some general points here (I hope I'm not being too picky):

  • Because of this method you will be forced to declare the implementation (InfluxDBImpl) instead of the interface (InfluxDB) as you did on a few classes like OneShotBatchWriter line 12 for example. IMHO we have to chose if we are going to follow the API contract 100% of the time or just abandon it because this hybrid approach is not a good standard;
  • The method name may cause some confusion. Check how the call stack when you use RetryCapableBatchWriter:
InfluxDBImpl.write(...)
   RetryCapableBatchWriter.write(...)
      RetryCapableBatchWriter.tryToWrite(...)
         InfluxDBImpl.writeNoRetry(...)

Unfortunately I don't have a better naming recommendation for it right now. I just want to point that you are calling a method writeNoRetry from a class that was supposed to be able to retry failed writes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will open a new PR to extend InfluxDB interface, (one specific method for this retry purpose)

this.batchedCount.add(batchPoints.getPoints().size());
RequestBody lineProtocol = RequestBody.create(MEDIA_TYPE_STRING, batchPoints.lineProtocol());
execute(this.influxDBService.writePoints(
Expand All @@ -425,7 +434,6 @@ public void write(final BatchPoints batchPoints) {
lineProtocol));
}


@Override
public void write(final String database, final String retentionPolicy, final ConsistencyLevel consistency,
final TimeUnit precision, final String records) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/influxdb/impl/OneShotBatchWriter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.influxdb.impl;

import org.influxdb.InfluxDB;
import org.influxdb.dto.BatchPoints;

import java.util.Collection;
Expand All @@ -10,16 +9,16 @@
*/
class OneShotBatchWriter implements BatchWriter {

private InfluxDB influxDB;
private InfluxDBImpl influxDB;

OneShotBatchWriter(final InfluxDB influxDB) {
OneShotBatchWriter(final InfluxDBImpl influxDB) {
this.influxDB = influxDB;
}

@Override
public void write(final Collection<BatchPoints> batchPointsCollection) {
for (BatchPoints batchPoints : batchPointsCollection) {
influxDB.write(batchPoints);
influxDB.writeNoRetry(batchPoints);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/influxdb/impl/RetryCapableBatchWriter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.influxdb.impl;

import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBException;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
Expand All @@ -18,14 +17,14 @@
*/
class RetryCapableBatchWriter implements BatchWriter {

private InfluxDB influxDB;
private InfluxDBImpl influxDB;
private BiConsumer<Iterable<Point>, Throwable> exceptionHandler;
private LinkedList<BatchPoints> batchQueue;
private int requestActionsLimit;
private int retryBufferCapacity;
private int usedRetryBufferCapacity;

RetryCapableBatchWriter(final InfluxDB influxDB, final BiConsumer<Iterable<Point>, Throwable> exceptionHandler,
RetryCapableBatchWriter(final InfluxDBImpl influxDB, final BiConsumer<Iterable<Point>, Throwable> exceptionHandler,
final int retryBufferCapacity, final int requestActionsLimit) {
this.influxDB = influxDB;
this.exceptionHandler = exceptionHandler;
Expand Down Expand Up @@ -124,7 +123,7 @@ public synchronized void close() {

private WriteResult tryToWrite(final BatchPoints batchPoints) {
try {
influxDB.write(batchPoints);
influxDB.writeNoRetry(batchPoints);
return WriteResult.WRITTEN;
} catch (InfluxDBException e) {
return new WriteResult(e);
Expand Down
Loading