From 70479849ec4f7eac43dc514720542a73d6521beb Mon Sep 17 00:00:00 2001
From: Thomas Lopatic <thomas@lopatic.de>
Date: Wed, 1 Jul 2015 15:32:32 +0200
Subject: [PATCH] More reasonable write overload handling.

---
 .../com/yahoo/ycsb/db/AerospikeClient.java    | 22 ++++++-------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/aerospike/src/main/java/com/yahoo/ycsb/db/AerospikeClient.java b/aerospike/src/main/java/com/yahoo/ycsb/db/AerospikeClient.java
index 361545ee..73ccd386 100644
--- a/aerospike/src/main/java/com/yahoo/ycsb/db/AerospikeClient.java
+++ b/aerospike/src/main/java/com/yahoo/ycsb/db/AerospikeClient.java
@@ -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();
@@ -128,10 +127,6 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
 
   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;
 
@@ -143,10 +138,9 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
     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) {
@@ -154,14 +148,6 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
           return RESULT_ERROR;
         }
 
-        if (--writeOverloadTries == 0) {
-          if (DEBUG) {
-            System.err.println("Device overload: " + e);
-          }
-
-          return RESULT_ERROR;
-        }
-
         try {
           Thread.sleep(delay);
         } catch (InterruptedException e2) {
@@ -173,6 +159,12 @@ public class AerospikeClient extends com.yahoo.ycsb.DB {
         delay *= 2;
       }
     }
+
+    if (DEBUG) {
+      System.err.println("Device overload");
+    }
+
+    return RESULT_ERROR;
   }
 
   @Override
-- 
GitLab