From 1863bafaa9afd5769aa78c1815bb28ae1970a2d6 Mon Sep 17 00:00:00 2001
From: Andy Kruth <kruthar@gmail.com>
Date: Mon, 15 Feb 2016 11:39:28 -0600
Subject: [PATCH] [orientdb] fixed iterator usage in scan operation

---
 orientdb/README.md                                            | 1 -
 orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java  | 4 ++--
 .../src/test/java/com/yahoo/ycsb/db/OrientDBClientTest.java   | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/orientdb/README.md b/orientdb/README.md
index 09d6baf6..578a5abb 100644
--- a/orientdb/README.md
+++ b/orientdb/README.md
@@ -72,5 +72,4 @@ WARNING: Creating a new database will be done safely with multiple threads on a
 ## Known Issues
 
 * There is a performance issue around the scan operation. This binding uses OIndex.iterateEntriesMajor() which will return unnecessarily large iterators. This has a performance impact as the recordcount goes up. There are ideas in the works to fix it, track it here: [#568](https://github.com/brianfrankcooper/YCSB/issues/568).
-* The OIndexCursor used to run the scan operation currently seems to be broken. Because of this, if the startkey and recordcount combination on a particular operation were to cause the iterator to go to the end, a NullPointerException is thrown. With sufficiently high record counts, this does not happen very often, but it could cause false negatives. Track that issue here: https://github.com/orientechnologies/orientdb/issues/5541.
 * Iterator methods needed to perform scans are Unsupported in the OrientDB API for remote database connections and so will return NOT_IMPLEMENTED status if attempted.
diff --git a/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java b/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java
index 54378762..5ef0014d 100644
--- a/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java
+++ b/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java
@@ -282,8 +282,8 @@ public class OrientDBClient extends DB {
 
       if (fields != null && !fields.isEmpty()) {
         while (entries.hasNext() && entrycount < recordcount) {
-          final Entry<Object, OIdentifiable> entry = entries.nextEntry();
-          final ODocument document = entry.getValue().getRecord();
+          final OIdentifiable entry = entries.next();
+          final ODocument document = entry.getRecord();
 
           final HashMap<String, ByteIterator> map = new HashMap<String, ByteIterator>();
           result.add(map);
diff --git a/orientdb/src/test/java/com/yahoo/ycsb/db/OrientDBClientTest.java b/orientdb/src/test/java/com/yahoo/ycsb/db/OrientDBClientTest.java
index 717637d0..140a9773 100644
--- a/orientdb/src/test/java/com/yahoo/ycsb/db/OrientDBClientTest.java
+++ b/orientdb/src/test/java/com/yahoo/ycsb/db/OrientDBClientTest.java
@@ -224,7 +224,7 @@ public class OrientDBClientTest {
      * Track the issue here: https://github.com/orientechnologies/orientdb/issues/5541
      * This fix was implemented for orientechnologies:orientdb-client:2.1.8
      */
-    int testIndex = startIndex + 1; // <-- Remove the +1 when the known issue of broken iterator is fixed.
+    int testIndex = startIndex;
 
     // Check each vector row to make sure we have the correct fields
     for (HashMap<String, ByteIterator> result: resultVector) {
-- 
GitLab