gjacoby126 commented on a change in pull request #631: PHOENIX-5494 Batched, 
mutable Index updates are unnecessarily run one…
URL: https://github.com/apache/phoenix/pull/631#discussion_r346007881
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/data/LocalTable.java
 ##########
 @@ -49,15 +61,53 @@
 public class LocalTable implements LocalHBaseState {
 
   private RegionCoprocessorEnvironment env;
+    private Map<ImmutableBytesPtr, Result> results = new HashMap<>();;
 
   public LocalTable(RegionCoprocessorEnvironment env) {
     this.env = env;
   }
 
+  public void scanCurrentRowStates(Set<ImmutableBytesPtr> rows, Collection<? 
extends ColumnReference> columns, long ts) throws IOException {
+      Scan s = 
IndexManagementUtil.newLocalStateScan(Collections.singletonList(columns));
+      FilterList filterList = new 
FilterList(FilterList.Operator.MUST_PASS_ONE);
+      for (ImmutableBytesPtr row : rows) {
+          filterList.addFilter(new RowFilter(CompareOperator.EQUAL, new 
BinaryComparator(row.get())));
+      }
+      s.setFilter(filterList);
+      s.setTimeRange(0, ts);
+      Region region = this.env.getRegion();
+      try (RegionScanner scanner = region.getScanner(s)) {
+          boolean more;
+          do {
+              List<Cell> kvs = new ArrayList<Cell>(1);
+              more = scanner.next(kvs);
+              if (kvs.isEmpty()) {
+                  return;
+              }
+              Result r = Result.create(kvs);
+              Cell cell = kvs.get(0);
+              byte[] rowKey = new byte[cell.getRowLength()];
+              System.arraycopy(cell.getRowArray(), cell.getRowOffset(), 
rowKey, 0, cell.getRowLength());
+              results.put(new ImmutableBytesPtr(rowKey), r);
+          } while (more);
+      }
+  }
+
+  public void removeRowStates(Set<ImmutableBytesPtr> rows) {
+      for (ImmutableBytesPtr row : rows) {
+          results.remove(row);
+      }
+  }
+
   @Override
   public Result getCurrentRowState(Mutation m, Collection<? extends 
ColumnReference> columns, boolean ignoreNewerMutations)
       throws IOException {
-    byte[] row = m.getRow();
+      byte[] row = m.getRow();
+      Result r = results.get(new ImmutableBytesPtr(row));
+      if (r !=null) {
+          return r;
+      }
+
 
 Review comment:
   Is there actually a circumstance where the Mutation row we want isn't 
already in the cache? If so, this is good as is, if not, maybe either add 
logging or an exception rather than just leaving the old logic here as is. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to