You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2019/11/20 03:48:01 UTC

[GitHub] [phoenix] gjacoby126 commented on a change in pull request #638: PHOENIX-5494

gjacoby126 commented on a change in pull request #638: PHOENIX-5494
URL: https://github.com/apache/phoenix/pull/638#discussion_r347616474
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/IndexBuildManager.java
 ##########
 @@ -88,27 +111,102 @@ public void getIndexUpdates(ListMultimap<HTableInterfaceReference, Pair<Mutation
       IndexMetaData indexMetaData) throws Throwable {
     // notify the delegate that we have started processing a batch
     this.delegate.batchStarted(miniBatchOp, indexMetaData);
-
+    CachedLocalTable cachedLocalTable =
+            preScanAllRequiredRows(
+                    mutations,
+                    (PhoenixIndexMetaData)indexMetaData,
+                    this.regionCoprocessorEnvironment);
     // Avoid the Object overhead of the executor when it's not actually parallelizing anything.
     for (Mutation m : mutations) {
-      Collection<Pair<Mutation, byte[]>> updates = delegate.getIndexUpdate(m, indexMetaData);
+      Collection<Pair<Mutation, byte[]>> updates = delegate.getIndexUpdate(m, indexMetaData, cachedLocalTable);
       for (Pair<Mutation, byte[]> update : updates) {
         indexUpdates.put(new HTableInterfaceReference(new ImmutableBytesPtr(update.getSecond())), new Pair<>(update.getFirst(), m.getRow()));
       }
     }
   }
 
+  @VisibleForTesting
+  public static CachedLocalTable preScanAllRequiredRows(
+          Collection<? extends Mutation> dataTableMutationsWithSameRowKeyAndTimestamp,
+          final PhoenixIndexMetaData indexMetaData,
+          RegionCoprocessorEnvironment regionCoprocessorEnvironment) throws IOException {
+      List<IndexMaintainer> indexTableMaintainers = indexMetaData.getIndexMaintainers();
+      Set<KeyRange> keys = new HashSet<KeyRange>(dataTableMutationsWithSameRowKeyAndTimestamp.size());
+      for (Mutation mutation : dataTableMutationsWithSameRowKeyAndTimestamp) {
+          keys.add(PVarbinary.INSTANCE.getKeyRange(mutation.getRow()));
+      }
+
+      Set<ColumnReference> getterColumnReferences = Sets.newHashSet();
+      for (IndexMaintainer indexTableMaintainer : indexTableMaintainers)
+      {
+          getterColumnReferences.addAll(
+                  indexTableMaintainer.getAllColumns());
+
+      }
+
+      getterColumnReferences.add(new ColumnReference(
+              indexTableMaintainers.get(0).getDataEmptyKeyValueCF(),
+              indexTableMaintainers.get(0).getEmptyKeyValueQualifier()));
+
+      Scan scan = IndexManagementUtil.newLocalStateScan(
+              Collections.singletonList(getterColumnReferences));
+      ScanRanges scanRanges = ScanRanges.createPointLookup(new ArrayList<KeyRange>(keys));
+      scanRanges.initializeScan(scan);
+      scan.setFilter(new SkipScanFilter(scanRanges.getSkipScanFilter(), true));
+
+      if(indexMetaData.getReplayWrite() != null) {
+          long timestamp = getMaxTimestamp(dataTableMutationsWithSameRowKeyAndTimestamp);
+          scan.setTimeRange(0, timestamp);
+      }
+
+      Region region = regionCoprocessorEnvironment.getRegion();
+      HashMap<ImmutableBytesPtr, List<Cell>> rowKeyPtrToCells =
+              new HashMap<ImmutableBytesPtr, List<Cell>>();
+      try (RegionScanner scanner = region.getScanner(scan)) {
+          boolean more = true;
+          while(more)
+          {
+              List<Cell> cells = new ArrayList<Cell>();
+              more = scanner.next(cells);
+              if (cells.isEmpty()) {
+                  continue;
+              }
+              Cell cell = cells.get(0);
+              byte[] rowKey = CellUtil.cloneRow(cell);
+              rowKeyPtrToCells.put(new ImmutableBytesPtr(rowKey), cells);
+          }
+      }
+
+      return new CachedLocalTable(rowKeyPtrToCells);
+  }
+
+  private static long getMaxTimestamp(Collection<? extends Mutation> dataTableMutationsWithSameRowKeyAndTimestamp){
+      long maxTimestamp = Long.MIN_VALUE;
+      for(Mutation mutation : dataTableMutationsWithSameRowKeyAndTimestamp) {
+          long timestamp = mutation.getFamilyCellMap().values().iterator().next().get(0).getTimestamp();
 
 Review comment:
   1. Can we guarantee that all Cells in a mutation have the same timestamp?
   2. Since we do this operation in a couple of places (see CachedLocalTable), might be good to have a static util method that encapsulates the logic so it's clear, abstracted and consistent. 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services