Skip to content

Commit

Permalink
More reasonable write overload handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncle-betty committed Jul 1, 2015
1 parent 9a8e37a commit 7047984
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions aerospike/src/main/java/com/yahoo/ycsb/db/AerospikeClient.java
Expand Up @@ -37,7 +37,6 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
private String namespace = null;

private com.aerospike.client.AerospikeClient client = null;
private int writeOverloadTries = WRITE_OVERLOAD_TRIES;

private Policy readPolicy = new Policy();
private WritePolicy insertPolicy = new WritePolicy();
Expand Down Expand Up @@ -128,10 +127,6 @@ public int scan(String table, String start, int count, Set<String> fields,

private int write(String table, String key, WritePolicy writePolicy,
HashMap<String, ByteIterator> values) {
if (writeOverloadTries == 0) {
return RESULT_ERROR;
}

Bin[] bins = new Bin[values.size()];
int index = 0;

Expand All @@ -143,25 +138,16 @@ private int write(String table, String key, WritePolicy writePolicy,
int delay = WRITE_OVERLOAD_DELAY;
Key keyObj = new Key(namespace, table, key);

while (true) {
for (int tries = 0; tries < WRITE_OVERLOAD_TRIES; ++tries) {
try {
client.put(writePolicy, keyObj, bins);
writeOverloadTries = WRITE_OVERLOAD_TRIES;
return RESULT_OK;
} catch (AerospikeException e) {
if (e.getResultCode() != ResultCode.DEVICE_OVERLOAD) {
System.err.println("Error while writing key " + key + ": " + e);
return RESULT_ERROR;
}

if (--writeOverloadTries == 0) {
if (DEBUG) {
System.err.println("Device overload: " + e);
}

return RESULT_ERROR;
}

try {
Thread.sleep(delay);
} catch (InterruptedException e2) {
Expand All @@ -173,6 +159,12 @@ private int write(String table, String key, WritePolicy writePolicy,
delay *= 2;
}
}

if (DEBUG) {
System.err.println("Device overload");
}

return RESULT_ERROR;
}

@Override
Expand Down

0 comments on commit 7047984

Please sign in to comment.