gokceni commented on a change in pull request #469: PHOENIX-5156 Consistent 
Global Indexes for Non-Transactional Tables
URL: https://github.com/apache/phoenix/pull/469#discussion_r269297454
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
 ##########
 @@ -509,28 +467,79 @@ public void 
preBatchMutateWithExceptions(ObserverContext<RegionCoprocessorEnviro
           byte[] tableName = 
c.getEnvironment().getRegion().getTableDescriptor().getTableName().getName();
           Iterator<Pair<Mutation, byte[]>> indexUpdatesItr = 
indexUpdates.iterator();
           List<Mutation> localUpdates = new 
ArrayList<Mutation>(indexUpdates.size());
+          List<Pair<Mutation, byte[]>> postIndexUpdates = new 
ArrayList<>(indexUpdates.size());
+          List<Pair<Mutation, byte[]>> indexUpdatesForDeletes = new 
ArrayList<>(indexUpdates.size());
+          IndexMetaData indexMetaData = 
this.builder.getIndexMetaData(miniBatchOp);
+          if (!(indexMetaData instanceof PhoenixIndexMetaData)) {
+              throw new DoNotRetryIOException(
+                      "preBatchMutateWithExceptions: indexMetaData is not an 
instance of PhoenixIndexMetaData " +
+                              
c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString());
+          }
+          List<IndexMaintainer> maintainers = 
((PhoenixIndexMetaData)indexMetaData).getIndexMaintainers();
           while(indexUpdatesItr.hasNext()) {
               Pair<Mutation, byte[]> next = indexUpdatesItr.next();
               if (Bytes.compareTo(next.getSecond(), tableName) == 0) {
                   localUpdates.add(next.getFirst());
                   indexUpdatesItr.remove();
               }
+              else {
+                  // get index maintainer for this index table
+                  IndexMaintainer indexMaintainer = 
getIndexMaintainer(maintainers, next.getSecond());
+                  if (indexMaintainer == null) {
+                      throw new DoNotRetryIOException(
+                              "preBatchMutateWithExceptions: indexMaintainer 
is null " +
+                                      
c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString());
+                  }
+                  byte[] emptyCF = 
indexMaintainer.getEmptyKeyValueFamily().copyBytesIfNecessary();
+                  byte[] emptyCQ = indexMaintainer.getEmptyKeyValueQualifier();
+                  // add the VERIFIED cell
+                  Mutation m = next.getFirst();
+                  boolean rebuild = 
PhoenixIndexMetaData.isIndexRebuild(m.getAttributesMap());
+                  long ts = getMaxTimestamp(m);
+                  if (rebuild) {
+                      if (m instanceof Put) {
+                          ((Put)m).addColumn(emptyCF, emptyCQ, ts, TRUE_BYTES);
+                      }
+                  } else {
+                      if (m instanceof Put) {
+                          ((Put)m).addColumn(emptyCF, emptyCQ, ts, 
FALSE_BYTES);
+                          Put put = new Put(m.getRow());
+                          put.addColumn(emptyCF, emptyCQ, ts, TRUE_BYTES);
+                          postIndexUpdates.add(new Pair<Mutation, byte[]>(put, 
next.getSecond()));
+                      } else {
+                          // For a delete mutation, first unverify the exiting 
row in the index table and then delete
+                          // the row from the index table after deleting the 
corresponding row from the data table
+                          indexUpdatesItr.remove();
+                          postIndexUpdates.add(next);
+                          Put put = new Put(m.getRow());
+                          put.addColumn(emptyCF, emptyCQ, ts, FALSE_BYTES);
 
 Review comment:
   nit: consider refactoring by moving this out of this else at line 504. This 
way all rebuild=false has FALSE_BYTES

----------------------------------------------------------------
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