You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2017/10/04 20:06:29 UTC

[accumulo] branch 1.7 updated: ACCUMULO-4713 Correct handling min and max timestamps (#303)

This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch 1.7
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/1.7 by this push:
     new 0241958  ACCUMULO-4713 Correct handling min and max timestamps (#303)
0241958 is described below

commit 0241958ec3cd5e764b94a1fbd485fc859fdc393f
Author: Charles Williams <cw...@gmail.com>
AuthorDate: Wed Oct 4 14:40:07 2017 -0400

    ACCUMULO-4713 Correct handling min and max timestamps (#303)
---
 .../accumulo/core/iterators/IteratorUtil.java      | 26 +++++++----
 .../iterators/system/TimeSettingIteratorTest.java  | 35 +++++++++++++++
 .../iterators/user/VersioningIteratorTest.java     | 50 ++++++++++++++++++++++
 3 files changed, 103 insertions(+), 8 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java b/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
index aee9771..4116e3e 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
@@ -300,10 +300,15 @@ public class IteratorUtil {
   public static Range maximizeStartKeyTimeStamp(Range range) {
     Range seekRange = range;
 
-    if (range.getStartKey() != null && range.getStartKey().getTimestamp() != Long.MAX_VALUE) {
-      Key seekKey = new Key(seekRange.getStartKey());
-      seekKey.setTimestamp(Long.MAX_VALUE);
-      seekRange = new Range(seekKey, true, range.getEndKey(), range.isEndKeyInclusive());
+    if (range.getStartKey() != null) {
+      Key seekKey = range.getStartKey();
+      if (range.getStartKey().getTimestamp() != Long.MAX_VALUE) {
+        seekKey = new Key(seekRange.getStartKey());
+        seekKey.setTimestamp(Long.MAX_VALUE);
+        seekRange = new Range(seekKey, true, range.getEndKey(), range.isEndKeyInclusive());
+      } else if (!range.isStartKeyInclusive()) {
+        seekRange = new Range(seekKey, true, range.getEndKey(), range.isEndKeyInclusive());
+      }
     }
 
     return seekRange;
@@ -312,10 +317,15 @@ public class IteratorUtil {
   public static Range minimizeEndKeyTimeStamp(Range range) {
     Range seekRange = range;
 
-    if (range.getEndKey() != null && range.getEndKey().getTimestamp() != Long.MIN_VALUE) {
-      Key seekKey = new Key(seekRange.getEndKey());
-      seekKey.setTimestamp(Long.MIN_VALUE);
-      seekRange = new Range(range.getStartKey(), range.isStartKeyInclusive(), seekKey, true);
+    if (range.getEndKey() != null) {
+      Key seekKey = seekRange.getEndKey();
+      if (range.getEndKey().getTimestamp() != Long.MIN_VALUE) {
+        seekKey = new Key(seekRange.getEndKey());
+        seekKey.setTimestamp(Long.MIN_VALUE);
+        seekRange = new Range(range.getStartKey(), range.isStartKeyInclusive(), seekKey, true);
+      } else if (!range.isEndKeyInclusive()) {
+        seekRange = new Range(range.getStartKey(), range.isStartKeyInclusive(), seekKey, true);
+      }
     }
 
     return seekRange;
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/system/TimeSettingIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/system/TimeSettingIteratorTest.java
index cc323f5..59c5a55 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/system/TimeSettingIteratorTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/system/TimeSettingIteratorTest.java
@@ -20,14 +20,17 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.TreeMap;
 
+import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.data.ByteSequence;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.iterators.SortedMapIterator;
+import org.apache.hadoop.io.Text;
 import org.junit.Test;
 
 public class TimeSettingIteratorTest {
@@ -106,4 +109,36 @@ public class TimeSettingIteratorTest {
     assertFalse(tsi.hasTop());
   }
 
+  @Test
+  public void testEndKeyRangeAtMinLongValue() throws IOException {
+    Text row = new Text("a");
+    Text colf = new Text("b");
+    Text colq = new Text("c");
+    Text cv = new Text();
+
+    for (boolean inclusiveEndRange : new boolean[] {true, false}) {
+      TreeMap<Key,Value> sources = new TreeMap<>();
+      sources.put(new Key(row.getBytes(), colf.getBytes(), colq.getBytes(), cv.getBytes(), Long.MIN_VALUE, true), new Value("00".getBytes()));
+      sources.put(new Key(row.getBytes(), colf.getBytes(), colq.getBytes(), cv.getBytes(), Long.MIN_VALUE), new Value("11".getBytes()));
+
+      TimeSettingIterator it = new TimeSettingIterator(new SortedMapIterator(sources), 111L);
+      IteratorSetting is = new IteratorSetting(1, TimeSettingIterator.class);
+      it.init(null, is.getOptions(), null);
+
+      Key startKey = new Key();
+      Key endKey = new Key(row, colf, colq, cv, Long.MIN_VALUE);
+      Range testRange = new Range(startKey, false, endKey, inclusiveEndRange);
+      it.seek(testRange, new HashSet<ByteSequence>(), false);
+
+      assertTrue(it.hasTop());
+      assertTrue(it.getTopValue().equals(new Value("00".getBytes())));
+      assertTrue(it.getTopKey().getTimestamp() == 111L);
+      it.next();
+      assertTrue(it.hasTop());
+      assertTrue(it.getTopValue().equals(new Value("11".getBytes())));
+      assertTrue(it.getTopKey().getTimestamp() == 111L);
+      it.next();
+      assertFalse(it.hasTop());
+    }
+  }
 }
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/user/VersioningIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/user/VersioningIteratorTest.java
index cdd0074..adf8959 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/user/VersioningIteratorTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/VersioningIteratorTest.java
@@ -28,6 +28,7 @@ import java.util.TreeMap;
 import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.data.ByteSequence;
 import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.PartialKey;
 import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.iterators.LongCombiner;
@@ -257,4 +258,53 @@ public class VersioningIteratorTest {
     assertTrue(it2.hasTop());
     assertTrue(it2.getTopKey().getTimestamp() == 18);
   }
+
+  @Test
+  public void test_maxLongExclusiveKey() throws IOException {
+    Text row = new Text("a");
+    Text colf = new Text("b");
+    Text colq = new Text("c");
+    Text cv = new Text();
+
+    TreeMap<Key,Value> tm = new TreeMap<>();
+    tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE), new Value("00".getBytes()));
+    tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE - 1), new Value("11".getBytes()));
+
+    VersioningIterator it = new VersioningIterator();
+    IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
+    VersioningIterator.setMaxVersions(is, 1);
+    it.init(new SortedMapIterator(tm), is.getOptions(), null);
+
+    Key startKey = new Key(row, colf, colq, cv, Long.MAX_VALUE);
+    Range testRange = new Range(startKey, false, startKey.followingKey(PartialKey.ROW), true);
+    it.seek(testRange, EMPTY_COL_FAMS, false);
+
+    assertFalse(it.hasTop());
+  }
+
+  @Test
+  public void test_maxLongInclusiveKey() throws IOException {
+    Text row = new Text("a");
+    Text colf = new Text("b");
+    Text colq = new Text("c");
+    Text cv = new Text();
+
+    TreeMap<Key,Value> tm = new TreeMap<>();
+    tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE), new Value("00".getBytes()));
+    tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE - 1), new Value("11".getBytes()));
+
+    VersioningIterator it = new VersioningIterator();
+    IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
+    VersioningIterator.setMaxVersions(is, 1);
+    it.init(new SortedMapIterator(tm), is.getOptions(), null);
+
+    Key startKey = new Key(row, colf, colq, cv, Long.MAX_VALUE);
+    Range testRange = new Range(startKey, true, startKey.followingKey(PartialKey.ROW), true);
+    it.seek(testRange, EMPTY_COL_FAMS, false);
+
+    assertTrue(it.hasTop());
+    assertTrue(it.getTopValue().equals("00".getBytes()));
+    it.next();
+    assertFalse(it.hasTop());
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@accumulo.apache.org" <co...@accumulo.apache.org>'].