wchevreuil commented on a change in pull request #2009:
URL: https://github.com/apache/hbase/pull/2009#discussion_r449650680



##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
##########
@@ -3170,37 +3171,88 @@ public void prepareDeleteTimestamps(Mutation mutation, 
Map<byte[], List<Cell>> f
           count = kvCount.get(qual);
 
           Get get = new Get(CellUtil.cloneRow(cell));
-          get.readVersions(count);
-          get.addColumn(family, qual);
+          get.readVersions(Integer.MAX_VALUE);
           if (coprocessorHost != null) {
             if (!coprocessorHost.prePrepareTimeStampForDeleteVersion(mutation, 
cell,
                 byteNow, get)) {
-              updateDeleteLatestVersionTimestamp(cell, get, count, byteNow);
+              updateDeleteLatestVersionTimestamp(cell, get, count,
+                  
this.htableDescriptor.getColumnFamily(family).getMaxVersions(),
+                    byteNow, deleteCells);
+
             }
           } else {
-            updateDeleteLatestVersionTimestamp(cell, get, count, byteNow);
+            updateDeleteLatestVersionTimestamp(cell, get, count,
+                this.htableDescriptor.getColumnFamily(family).getMaxVersions(),
+                  byteNow, deleteCells);
           }
         } else {
           PrivateCellUtil.updateLatestStamp(cell, byteNow);
+          deleteCells.add(cell);
         }
       }
+      e.setValue(deleteCells);
     }
   }
 
-  void updateDeleteLatestVersionTimestamp(Cell cell, Get get, int count, 
byte[] byteNow)
-      throws IOException {
-    List<Cell> result = get(get, false);
-
+  void updateDeleteLatestVersionTimestamp(Cell cell, Get get, int count, int 
maxVersions,
+      byte[] byteNow, List<Cell> deleteCells) throws IOException {
+    List<Cell> result = new ArrayList<>();
+    result.addAll(deleteCells);
+    Scan scan = new Scan(get);
+    scan.setRaw(true);
+    this.getScanner(scan).next(result);
+    result.sort((cell1, cell2) -> {
+      if(cell1.getTimestamp()>cell2.getTimestamp()){
+        return -1;
+      } else if(cell1.getTimestamp()<cell2.getTimestamp()){
+        return 1;
+      } else {
+        if(CellUtil.isDelete(cell1)){
+          return -1;
+        } else if (CellUtil.isDelete(cell2)){
+          return 1;
+        }
+      }
+      return 0;
+    });
+    List<Cell> cells = new ArrayList<>();
     if (result.size() < count) {
       // Nothing to delete
       PrivateCellUtil.updateLatestStamp(cell, byteNow);
-      return;
-    }
-    if (result.size() > count) {
-      throw new RuntimeException("Unexpected size: " + result.size());
+      cells.add(cell);
+      deleteCells.addAll(cells);
+    } else if (result.size() > count) {
+      int currentVersion = 0;
+      long latestCellTS = Long.MAX_VALUE;
+      for(Cell getCell : result){
+        if(!(CellUtil.matchingFamily(getCell, cell) && 
CellUtil.matchingQualifier(getCell, cell))){
+          continue;
+        }
+        if(!PrivateCellUtil.isDeleteType(getCell) && 
getCell.getTimestamp()!=latestCellTS){
+          if (currentVersion >= maxVersions) {
+            Cell tempCell = null;
+            try {
+              tempCell = PrivateCellUtil.deepClone(cell);
+            } catch (CloneNotSupportedException e) {
+              throw new IOException(e);
+            }
+            PrivateCellUtil.setTimestamp(tempCell, getCell.getTimestamp());
+            cells.add(tempCell);
+          } else if (currentVersion == 0) {
+            PrivateCellUtil.setTimestamp(cell, getCell.getTimestamp());
+            cells.add(cell);
+          }
+          currentVersion++;
+        }
+        latestCellTS = getCell.getTimestamp();
+      }
+
+    } else {
+      Cell getCell = result.get(0);
+      PrivateCellUtil.setTimestamp(cell, getCell.getTimestamp());
+      cells.add(cell);

Review comment:
       It's been a while since I originally proposed this patch, but IIRC we 
don't need it here, because there's no extra version to fabricate a new delete 
marker.




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


Reply via email to