Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 d41dd1d4d -> 07e96a910


PHOENIX-3858 Index maintenance not required for local indexes of table with 
immutable rows


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/07e96a91
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/07e96a91
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/07e96a91

Branch: refs/heads/4.x-HBase-1.1
Commit: 07e96a910f1193feb1a8a6e2790e22c795c0b6d5
Parents: d41dd1d
Author: James Taylor <jamestay...@apache.org>
Authored: Thu May 18 10:14:01 2017 -0700
Committer: James Taylor <jamestay...@apache.org>
Committed: Thu May 18 11:32:47 2017 -0700

----------------------------------------------------------------------
 .../EndToEndCoveredColumnsIndexBuilderIT.java   |  19 ++-
 .../hbase/index/covered/LocalTableState.java    |  20 ++--
 .../hbase/index/covered/NonTxIndexBuilder.java  |   3 +
 .../phoenix/hbase/index/covered/TableState.java |   3 +-
 .../example/CoveredColumnIndexCodec.java        |  14 +--
 .../apache/phoenix/index/PhoenixIndexCodec.java |   4 +-
 .../index/PhoenixTransactionalIndexer.java      |   3 +-
 .../index/covered/TestLocalTableState.java      | 118 +++++++++++++++++--
 8 files changed, 151 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/07e96a91/phoenix-core/src/it/java/org/apache/phoenix/hbase/index/covered/EndToEndCoveredColumnsIndexBuilderIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/hbase/index/covered/EndToEndCoveredColumnsIndexBuilderIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/hbase/index/covered/EndToEndCoveredColumnsIndexBuilderIT.java
index 00157b1..97d8f3e 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/hbase/index/covered/EndToEndCoveredColumnsIndexBuilderIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/hbase/index/covered/EndToEndCoveredColumnsIndexBuilderIT.java
@@ -43,14 +43,14 @@ import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.regionserver.Region;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.util.EnvironmentEdge;
-import org.apache.phoenix.util.EnvironmentEdgeManager;
 import org.apache.phoenix.end2end.NeedsOwnMiniClusterTest;
 import org.apache.phoenix.hbase.index.IndexTestingUtils;
 import org.apache.phoenix.hbase.index.Indexer;
 import org.apache.phoenix.hbase.index.TableName;
 import org.apache.phoenix.hbase.index.covered.update.ColumnReference;
 import org.apache.phoenix.hbase.index.scanner.Scanner;
+import org.apache.phoenix.util.EnvironmentEdge;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -146,9 +146,22 @@ public class EndToEndCoveredColumnsIndexBuilderIT {
 
     @Override
     public void verify(TableState state) {
+        IndexMetaData indexMetaData = new IndexMetaData() {
+
+            @Override
+            public boolean isImmutableRows() {
+                return false;
+            }
+
+            @Override
+            public boolean ignoreNewerMutations() {
+                return false;
+            }
+              
+          };
       try {
         Scanner kvs =
-            ((LocalTableState) 
state).getIndexedColumnsTableState(Arrays.asList(columns), false, 
false).getFirst();
+            ((LocalTableState) 
state).getIndexedColumnsTableState(Arrays.asList(columns), false, false, 
indexMetaData).getFirst();
 
         int count = 0;
         Cell kv;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07e96a91/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java
index 59e7801..245bd66 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java
@@ -136,6 +136,7 @@ public class LocalTableState implements TableState {
      * @param ignoreNewerMutations ignore mutations newer than m when 
determining current state. Useful
      *        when replaying mutation state for partial index rebuild where 
writes succeeded to the data
      *        table, but not to the index table.
+     * @param indexMetaData TODO
      * @return an iterator over the columns and the {@link IndexUpdate} that 
should be passed back to
      *         the builder. Even if no update is necessary for the requested 
columns, you still need
      *         to return the {@link IndexUpdate}, just don't set the update 
for the
@@ -143,8 +144,8 @@ public class LocalTableState implements TableState {
      * @throws IOException
      */
     public Pair<Scanner, IndexUpdate> getIndexedColumnsTableState(
-        Collection<? extends ColumnReference> indexedColumns, boolean 
ignoreNewerMutations, boolean returnNullScannerIfRowNotFound) throws 
IOException {
-        ensureLocalStateInitialized(indexedColumns, ignoreNewerMutations);
+        Collection<? extends ColumnReference> indexedColumns, boolean 
ignoreNewerMutations, boolean returnNullScannerIfRowNotFound, IndexMetaData 
indexMetaData) throws IOException {
+        ensureLocalStateInitialized(indexedColumns, ignoreNewerMutations, 
indexMetaData);
         // filter out things with a newer timestamp and track the column 
references to which it applies
         ColumnTracker tracker = new ColumnTracker(indexedColumns);
         synchronized (this.trackedColumns) {
@@ -163,16 +164,21 @@ public class LocalTableState implements TableState {
      * Initialize the managed local state. Generally, this will only be called 
by
      * {@link #getNonIndexedColumnsTableState(List)}, which is unlikely to be 
called concurrently from the outside. Even
      * then, there is still fairly low contention as each new Put/Delete will 
have its own table state.
+     * @param indexMetaData TODO
      */
-    private synchronized void ensureLocalStateInitialized(Collection<? extends 
ColumnReference> columns, boolean ignoreNewerMutations)
+    private synchronized void ensureLocalStateInitialized(Collection<? extends 
ColumnReference> columns, boolean ignoreNewerMutations, IndexMetaData 
indexMetaData)
             throws IOException {
         // check to see if we haven't initialized any columns yet
         Collection<? extends ColumnReference> toCover = 
this.columnSet.findNonCoveredColumns(columns);
         // we have all the columns loaded, so we are good to go.
         if (toCover.isEmpty()) { return; }
 
-        // add the current state of the row
-        this.addUpdate(this.table.getCurrentRowState(update, toCover, 
ignoreNewerMutations).list(), false);
+        // no need to perform scan to find prior row values when the indexed 
columns are immutable, as
+        // by definition, there won't be any.
+        if (!indexMetaData.isImmutableRows()) {
+            // add the current state of the row
+            this.addUpdate(this.table.getCurrentRowState(update, toCover, 
ignoreNewerMutations).list(), false);
+        }
 
         // add the covered columns to the set
         for (ColumnReference ref : toCover) {
@@ -238,9 +244,9 @@ public class LocalTableState implements TableState {
     }
 
     @Override
-    public Pair<ValueGetter, IndexUpdate> getIndexUpdateState(Collection<? 
extends ColumnReference> indexedColumns, boolean ignoreNewerMutations, boolean 
returnNullScannerIfRowNotFound)
+    public Pair<ValueGetter, IndexUpdate> getIndexUpdateState(Collection<? 
extends ColumnReference> indexedColumns, boolean ignoreNewerMutations, boolean 
returnNullScannerIfRowNotFound, IndexMetaData indexMetaData)
             throws IOException {
-        Pair<Scanner, IndexUpdate> pair = 
getIndexedColumnsTableState(indexedColumns, ignoreNewerMutations, 
returnNullScannerIfRowNotFound);
+        Pair<Scanner, IndexUpdate> pair = 
getIndexedColumnsTableState(indexedColumns, ignoreNewerMutations, 
returnNullScannerIfRowNotFound, indexMetaData);
         ValueGetter valueGetter = 
IndexManagementUtil.createGetterFromScanner(pair.getFirst(), 
getCurrentRowKey());
         return new Pair<ValueGetter, IndexUpdate>(valueGetter, 
pair.getSecond());
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07e96a91/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
index e335cdc..9c7ec2e 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
@@ -383,6 +383,9 @@ public class NonTxIndexBuilder extends BaseIndexBuilder {
      */
     protected void addDeleteUpdatesToMap(IndexUpdateManager updateMap, 
LocalTableState state, long ts, IndexMetaData indexMetaData)
             throws IOException {
+        if (indexMetaData.isImmutableRows()) {
+            return;
+        }
         Iterable<IndexUpdate> cleanup = codec.getIndexDeletes(state, 
indexMetaData);
         if (cleanup != null) {
             for (IndexUpdate d : cleanup) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07e96a91/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/TableState.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/TableState.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/TableState.java
index aa3c39d..f85de59 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/TableState.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/TableState.java
@@ -61,9 +61,10 @@ public interface TableState {
  * @param ignoreNewerMutations ignore mutations newer than m when determining 
current state. Useful
    *        when replaying mutation state for partial index rebuild where 
writes succeeded to the data
    *        table, but not to the index table.
+ * @param indexMetaData TODO
    */
   Pair<ValueGetter, IndexUpdate> getIndexUpdateState(
-      Collection<? extends ColumnReference> indexedColumns, boolean 
ignoreNewerMutations, boolean returnNullScannerIfRowNotFound) throws 
IOException;
+      Collection<? extends ColumnReference> indexedColumns, boolean 
ignoreNewerMutations, boolean returnNullScannerIfRowNotFound, IndexMetaData 
indexMetaData) throws IOException;
 
   /**
    * @return the row key for the current row for which we are building an 
index update.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07e96a91/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java
index 6f8d1be..5963f2e 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumnIndexCodec.java
@@ -60,10 +60,10 @@ public class CoveredColumnIndexCodec extends BaseIndexCodec 
{
     }
 
     @Override
-    public Iterable<IndexUpdate> getIndexUpserts(TableState state, 
IndexMetaData context) {
+    public Iterable<IndexUpdate> getIndexUpserts(TableState state, 
IndexMetaData indexMetaData) {
         List<IndexUpdate> updates = new ArrayList<IndexUpdate>();
         for (ColumnGroup group : groups) {
-            IndexUpdate update = getIndexUpdateForGroup(group, state);
+            IndexUpdate update = getIndexUpdateForGroup(group, state, 
indexMetaData);
             updates.add(update);
         }
         return updates;
@@ -74,10 +74,10 @@ public class CoveredColumnIndexCodec extends BaseIndexCodec 
{
      * @param state
      * @return the update that should be made to the table
      */
-    private IndexUpdate getIndexUpdateForGroup(ColumnGroup group, TableState 
state) {
+    private IndexUpdate getIndexUpdateForGroup(ColumnGroup group, TableState 
state, IndexMetaData indexMetaData) {
         List<CoveredColumn> refs = group.getColumns();
         try {
-            Pair<Scanner, IndexUpdate> stateInfo = 
((LocalTableState)state).getIndexedColumnsTableState(refs, false, false);
+            Pair<Scanner, IndexUpdate> stateInfo = 
((LocalTableState)state).getIndexedColumnsTableState(refs, false, false, 
indexMetaData);
             Scanner kvs = stateInfo.getFirst();
             Pair<Integer, List<ColumnEntry>> columns = getNextEntries(refs, 
kvs, state.getCurrentRowKey());
             // make sure we close the scanner
@@ -117,7 +117,7 @@ public class CoveredColumnIndexCodec extends BaseIndexCodec 
{
     public Iterable<IndexUpdate> getIndexDeletes(TableState state, 
IndexMetaData context) {
         List<IndexUpdate> deletes = new ArrayList<IndexUpdate>();
         for (ColumnGroup group : groups) {
-            deletes.add(getDeleteForGroup(group, state));
+            deletes.add(getDeleteForGroup(group, state, context));
         }
         return deletes;
     }
@@ -129,10 +129,10 @@ public class CoveredColumnIndexCodec extends 
BaseIndexCodec {
      *            index information
      * @return the cleanup for the given index, or <tt>null</tt> if no cleanup 
is necessary
      */
-    private IndexUpdate getDeleteForGroup(ColumnGroup group, TableState state) 
{
+    private IndexUpdate getDeleteForGroup(ColumnGroup group, TableState state, 
IndexMetaData indexMetaData) {
         List<CoveredColumn> refs = group.getColumns();
         try {
-            Pair<Scanner, IndexUpdate> kvs = 
((LocalTableState)state).getIndexedColumnsTableState(refs, false, false);
+            Pair<Scanner, IndexUpdate> kvs = 
((LocalTableState)state).getIndexedColumnsTableState(refs, false, false, 
indexMetaData);
             Pair<Integer, List<ColumnEntry>> columns = getNextEntries(refs, 
kvs.getFirst(), state.getCurrentRowKey());
             // make sure we close the scanner reference
             kvs.getFirst().close();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07e96a91/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java 
b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java
index 2f162e3..1726b1f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java
@@ -72,7 +72,7 @@ public class PhoenixIndexCodec extends BaseIndexCodec {
         ptr.set(state.getCurrentRowKey());
         List<IndexUpdate> indexUpdates = Lists.newArrayList();
         for (IndexMaintainer maintainer : indexMaintainers) {
-            Pair<ValueGetter, IndexUpdate> statePair = 
state.getIndexUpdateState(maintainer.getAllColumns(), 
metaData.ignoreNewerMutations(), false);
+            Pair<ValueGetter, IndexUpdate> statePair = 
state.getIndexUpdateState(maintainer.getAllColumns(), 
metaData.ignoreNewerMutations(), false, context);
             ValueGetter valueGetter = statePair.getFirst();
             IndexUpdate indexUpdate = statePair.getSecond();
             indexUpdate.setTable(maintainer.isLocalIndex() ? 
state.getEnvironment().getRegion()
@@ -99,7 +99,7 @@ public class PhoenixIndexCodec extends BaseIndexCodec {
             // client side.
             Set<ColumnReference> cols = 
Sets.newHashSet(maintainer.getAllColumns());
             cols.add(new 
ColumnReference(indexMaintainers.get(0).getDataEmptyKeyValueCF(), 
indexMaintainers.get(0).getEmptyKeyValueQualifier()));
-            Pair<ValueGetter, IndexUpdate> statePair = 
state.getIndexUpdateState(cols, metaData.ignoreNewerMutations(), true);
+            Pair<ValueGetter, IndexUpdate> statePair = 
state.getIndexUpdateState(cols, metaData.ignoreNewerMutations(), true, context);
             ValueGetter valueGetter = statePair.getFirst();
             if (valueGetter!=null) {
                 IndexUpdate indexUpdate = statePair.getSecond();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07e96a91/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
index 453f38f..563b79e 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java
@@ -62,6 +62,7 @@ import org.apache.phoenix.compile.ScanRanges;
 import org.apache.phoenix.filter.SkipScanFilter;
 import org.apache.phoenix.hbase.index.MultiMutation;
 import org.apache.phoenix.hbase.index.ValueGetter;
+import org.apache.phoenix.hbase.index.covered.IndexMetaData;
 import org.apache.phoenix.hbase.index.covered.IndexUpdate;
 import org.apache.phoenix.hbase.index.covered.TableState;
 import org.apache.phoenix.hbase.index.covered.update.ColumnReference;
@@ -594,7 +595,7 @@ public class PhoenixTransactionalIndexer extends 
BaseRegionObserver {
         }
 
         @Override
-        public Pair<ValueGetter, IndexUpdate> getIndexUpdateState(Collection<? 
extends ColumnReference> indexedColumns, boolean ignoreNewerMutations, boolean 
returnNullScannerIfRowNotFound)
+        public Pair<ValueGetter, IndexUpdate> getIndexUpdateState(Collection<? 
extends ColumnReference> indexedColumns, boolean ignoreNewerMutations, boolean 
returnNullScannerIfRowNotFound, IndexMetaData indexMetaData)
                 throws IOException {
             // TODO: creating these objects over and over again is wasteful
             ColumnTracker tracker = new ColumnTracker(indexedColumns);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07e96a91/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestLocalTableState.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestLocalTableState.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestLocalTableState.java
index db7b354..941493e 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestLocalTableState.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestLocalTableState.java
@@ -24,8 +24,8 @@ import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.KeyValue.Type;
+import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
@@ -33,16 +33,14 @@ import org.apache.hadoop.hbase.regionserver.Region;
 import org.apache.hadoop.hbase.regionserver.RegionScanner;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.apache.phoenix.hbase.index.covered.IndexUpdate;
-import org.apache.phoenix.hbase.index.covered.LocalTableState;
 import org.apache.phoenix.hbase.index.covered.data.LocalHBaseState;
 import org.apache.phoenix.hbase.index.covered.data.LocalTable;
 import org.apache.phoenix.hbase.index.covered.update.ColumnReference;
 import org.apache.phoenix.hbase.index.scanner.Scanner;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 
 /**
  *
@@ -54,6 +52,19 @@ public class TestLocalTableState {
   private static final byte[] qual = Bytes.toBytes("qual");
   private static final byte[] val = Bytes.toBytes("val");
   private static final long ts = 10;
+  private static final IndexMetaData indexMetaData = new IndexMetaData() {
+
+    @Override
+    public boolean isImmutableRows() {
+        return false;
+    }
+
+    @Override
+    public boolean ignoreNewerMutations() {
+        return false;
+    }
+      
+  };
 
   @SuppressWarnings("unchecked")
   @Test
@@ -91,7 +102,90 @@ public class TestLocalTableState {
     ColumnReference col = new ColumnReference(fam, qual);
     table.setCurrentTimestamp(ts);
     //check that our value still shows up first on scan, even though this is a 
lazy load
-    Pair<Scanner, IndexUpdate> p = 
table.getIndexedColumnsTableState(Arrays.asList(col), false, false);
+    Pair<Scanner, IndexUpdate> p = 
table.getIndexedColumnsTableState(Arrays.asList(col), false, false, 
indexMetaData);
+    Scanner s = p.getFirst();
+    assertEquals("Didn't get the pending mutation's value first", m.get(fam, 
qual).get(0), s.next());
+  }
+
+  public static final class ScannerCreatedException extends RuntimeException {
+      ScannerCreatedException(String msg) {
+          super(msg);
+      }
+  }
+  
+  @Test(expected = ScannerCreatedException.class)
+  public void testScannerForMutableRows() throws Exception {
+      IndexMetaData indexMetaData = new IndexMetaData() {
+
+          @Override
+          public boolean isImmutableRows() {
+              return false;
+          }
+
+          @Override
+          public boolean ignoreNewerMutations() {
+              return false;
+          }
+            
+        };
+    Put m = new Put(row);
+    m.add(fam, qual, ts, val);
+    // setup mocks
+    Configuration conf = new Configuration(false);
+    RegionCoprocessorEnvironment env = 
Mockito.mock(RegionCoprocessorEnvironment.class);
+    Mockito.when(env.getConfiguration()).thenReturn(conf);
+
+    Region region = Mockito.mock(Region.class);
+    Mockito.when(env.getRegion()).thenReturn(region);
+    Mockito.when(region.getScanner(Mockito.any(Scan.class))).thenThrow(new 
ScannerCreatedException("Should not open scanner when data is immutable"));
+
+    LocalHBaseState state = new LocalTable(env);
+    LocalTableState table = new LocalTableState(env, state, m);
+    //add the kvs from the mutation
+    table.addPendingUpdates(KeyValueUtil.ensureKeyValues(m.get(fam, qual)));
+
+    // setup the lookup
+    ColumnReference col = new ColumnReference(fam, qual);
+    table.setCurrentTimestamp(ts);
+    table.getIndexedColumnsTableState(Arrays.asList(col), false, false, 
indexMetaData);
+  }
+
+  @Test
+  public void testNoScannerForImmutableRows() throws Exception {
+      IndexMetaData indexMetaData = new IndexMetaData() {
+
+          @Override
+          public boolean isImmutableRows() {
+              return true;
+          }
+
+          @Override
+          public boolean ignoreNewerMutations() {
+              return false;
+          }
+            
+        };
+    Put m = new Put(row);
+    m.add(fam, qual, ts, val);
+    // setup mocks
+    Configuration conf = new Configuration(false);
+    RegionCoprocessorEnvironment env = 
Mockito.mock(RegionCoprocessorEnvironment.class);
+    Mockito.when(env.getConfiguration()).thenReturn(conf);
+
+    Region region = Mockito.mock(Region.class);
+    Mockito.when(env.getRegion()).thenReturn(region);
+    Mockito.when(region.getScanner(Mockito.any(Scan.class))).thenThrow(new 
ScannerCreatedException("Should not open scanner when data is immutable"));
+
+    LocalHBaseState state = new LocalTable(env);
+    LocalTableState table = new LocalTableState(env, state, m);
+    //add the kvs from the mutation
+    table.addPendingUpdates(KeyValueUtil.ensureKeyValues(m.get(fam, qual)));
+
+    // setup the lookup
+    ColumnReference col = new ColumnReference(fam, qual);
+    table.setCurrentTimestamp(ts);
+    //check that our value still shows up first on scan, even though this is a 
lazy load
+    Pair<Scanner, IndexUpdate> p = 
table.getIndexedColumnsTableState(Arrays.asList(col), false, false, 
indexMetaData);
     Scanner s = p.getFirst();
     assertEquals("Didn't get the pending mutation's value first", m.get(fam, 
qual).get(0), s.next());
   }
@@ -135,13 +229,13 @@ public class TestLocalTableState {
     ColumnReference col = new ColumnReference(fam, qual);
     table.setCurrentTimestamp(ts);
     // check that the value is there
-    Pair<Scanner, IndexUpdate> p = 
table.getIndexedColumnsTableState(Arrays.asList(col), false, false);
+    Pair<Scanner, IndexUpdate> p = 
table.getIndexedColumnsTableState(Arrays.asList(col), false, false, 
indexMetaData);
     Scanner s = p.getFirst();
     assertEquals("Didn't get the pending mutation's value first", kv, 
s.next());
 
     // rollback that value
     table.rollback(Arrays.asList(kv));
-    p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false);
+    p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, 
indexMetaData);
     s = p.getFirst();
     assertEquals("Didn't correctly rollback the row - still found it!", null, 
s.next());
     Mockito.verify(env, Mockito.times(1)).getRegion();
@@ -179,14 +273,14 @@ public class TestLocalTableState {
     ColumnReference col = new ColumnReference(fam, qual);
     table.setCurrentTimestamp(ts);
     // check that the value is there
-    Pair<Scanner, IndexUpdate> p = 
table.getIndexedColumnsTableState(Arrays.asList(col), false, false);
+    Pair<Scanner, IndexUpdate> p = 
table.getIndexedColumnsTableState(Arrays.asList(col), false, false, 
indexMetaData);
     Scanner s = p.getFirst();
     // make sure it read the table the one time
     assertEquals("Didn't get the stored keyvalue!", storedKv, s.next());
 
     // on the second lookup it shouldn't access the underlying table again - 
the cached columns
     // should know they are done
-    p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false);
+    p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, 
indexMetaData);
     s = p.getFirst();
     assertEquals("Lost already loaded update!", storedKv, s.next());
     Mockito.verify(env, Mockito.times(1)).getRegion();

Reply via email to