mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
merge fixups - partial
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>nosqlbench</artifactId>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<version>4.15.51-SNAPSHOT</version>
|
||||
<version>4.15.52-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -15,13 +15,15 @@
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.4.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>engine-api</artifactId>
|
||||
<version>4.15.51-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<version>4.15.52-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.nosqlbench.activitytype.jdbc.api;
|
||||
|
||||
import com.codahale.metrics.Counter;
|
||||
import com.codahale.metrics.Histogram;
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
@@ -11,7 +10,6 @@ import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
||||
import io.nosqlbench.engine.api.activityimpl.SimpleActivity;
|
||||
import io.nosqlbench.engine.api.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.engine.api.metrics.ExceptionCountMetrics;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -28,6 +26,7 @@ public abstract class JDBCActivity extends SimpleActivity {
|
||||
private Timer resultSuccessTimer;
|
||||
private Histogram triesHisto;
|
||||
private int maxTries;
|
||||
private int minRetryDelayMs;
|
||||
|
||||
protected DataSource dataSource;
|
||||
protected OpSequence<OpDispenser<String>> opSequence;
|
||||
@@ -47,6 +46,7 @@ public abstract class JDBCActivity extends SimpleActivity {
|
||||
super.onActivityDefUpdate(activityDef);
|
||||
|
||||
this.maxTries = getParams().getOptionalInteger("maxtries").orElse(3);
|
||||
this.minRetryDelayMs = getParams().getOptionalInteger("minretrydelayms").orElse(200);
|
||||
|
||||
LOGGER.debug("initializing data source");
|
||||
dataSource = newDataSource();
|
||||
@@ -79,10 +79,15 @@ public abstract class JDBCActivity extends SimpleActivity {
|
||||
}
|
||||
|
||||
public String errorNameMapper(Throwable e) {
|
||||
StringBuilder sb = new StringBuilder(e.getClass().getSimpleName());
|
||||
if (e instanceof SQLException) {
|
||||
return ((SQLException) e).getSQLState();
|
||||
String sqlState = ((SQLException) e).getSQLState();
|
||||
if (sqlState != null && !sqlState.isEmpty()) {
|
||||
sb.append('_');
|
||||
sb.append(sqlState);
|
||||
}
|
||||
}
|
||||
return e.getClass().getSimpleName();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,6 +99,10 @@ public abstract class JDBCActivity extends SimpleActivity {
|
||||
return this.maxTries;
|
||||
}
|
||||
|
||||
public int getMinRetryDelayMs() {
|
||||
return this.minRetryDelayMs;
|
||||
}
|
||||
|
||||
public DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ public class JDBCAction implements SyncAction {
|
||||
}
|
||||
|
||||
int maxTries = activity.getMaxTries();
|
||||
Exception error = null;
|
||||
|
||||
for (int tries = 1; tries <= maxTries; tries++) {
|
||||
Exception error = null;
|
||||
long startTimeNanos = System.nanoTime();
|
||||
|
||||
try (Connection conn = activity.getDataSource().getConnection()) {
|
||||
@@ -65,12 +65,31 @@ public class JDBCAction implements SyncAction {
|
||||
ErrorDetail detail = activity.getErrorHandler().handleError(error, cycle, executionTimeNanos);
|
||||
if (!detail.isRetryable()) {
|
||||
LOGGER.debug("Exit failure after non-retryable error");
|
||||
return 1;
|
||||
throw new RuntimeException("non-retryable error", error);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
int retryDelay = retryDelayMs(tries, activity.getMinRetryDelayMs());
|
||||
LOGGER.debug("tries=" + tries + " sleeping for " + retryDelay + " ms");
|
||||
Thread.sleep(retryDelay);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("thread interrupted", e);
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.debug("Exit failure after maxretries=" + maxTries);
|
||||
return 1;
|
||||
throw new RuntimeException("maxtries exceeded", error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute retry delay based on exponential backoff with full jitter
|
||||
* @param tries 1-indexed
|
||||
* @param minDelayMs lower bound of retry delay
|
||||
* @return retry delay
|
||||
*/
|
||||
private int retryDelayMs(int tries, int minDelayMs) {
|
||||
int exponentialDelay = minDelayMs * (int) Math.pow(2.0, tries - 1);
|
||||
return (int) (Math.random() * exponentialDelay);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user