busbey commented on a change in pull request #623: HBASE-22749: Distributed MOB 
compactions
URL: https://github.com/apache/hbase/pull/623#discussion_r325912232
 
 

 ##########
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/mob/DefaultMobStoreCompactor.java
 ##########
 @@ -183,105 +270,166 @@ protected boolean performCompaction(FileDetails fd, 
InternalScanner scanner, Cel
     boolean hasMore;
     Path path = MobUtils.getMobFamilyPath(conf, store.getTableName(), 
store.getColumnFamilyName());
     byte[] fileName = null;
-    StoreFileWriter mobFileWriter = null, delFileWriter = null;
-    long mobCells = 0, deleteMarkersCount = 0;
+    StoreFileWriter mobFileWriter = null;
+    long mobCells = 0;
     long cellsCountCompactedToMob = 0, cellsCountCompactedFromMob = 0;
     long cellsSizeCompactedToMob = 0, cellsSizeCompactedFromMob = 0;
     boolean finished = false;
+
     ScannerContext scannerContext =
         ScannerContext.newBuilder().setBatchLimit(compactionKVMax).build();
     throughputController.start(compactionName);
-    KeyValueScanner kvs = (scanner instanceof KeyValueScanner)? 
(KeyValueScanner)scanner : null;
-    long shippedCallSizeLimit = (long) numofFilesToCompact * 
this.store.getColumnFamilyDescriptor().getBlocksize();
+    KeyValueScanner kvs = (scanner instanceof KeyValueScanner) ? 
(KeyValueScanner) scanner : null;
+    long shippedCallSizeLimit =
+        (long) numofFilesToCompact * 
this.store.getColumnFamilyDescriptor().getBlocksize();
+
+    MobCell mobCell = null;
     try {
       try {
         // If the mob file writer could not be created, directly write the 
cell to the store file.
         mobFileWriter = mobStore.createWriterInTmp(new Date(fd.latestPutTs), 
fd.maxKeyCount,
           compactionCompression, store.getRegionInfo().getStartKey(), true);
         fileName = Bytes.toBytes(mobFileWriter.getPath().getName());
       } catch (IOException e) {
-        LOG.warn("Failed to create mob writer, "
-               + "we will continue the compaction by writing MOB cells 
directly in store files", e);
+        // Bailing out
+        LOG.error("Failed to create mob writer, ", e);
+        throw e;
       }
-      if (major) {
-        try {
-          delFileWriter = mobStore.createDelFileWriterInTmp(new 
Date(fd.latestPutTs),
-            fd.maxKeyCount, compactionCompression, 
store.getRegionInfo().getStartKey());
-        } catch (IOException e) {
-          LOG.warn(
-            "Failed to create del writer, "
-            + "we will continue the compaction by writing delete markers 
directly in store files",
-            e);
-        }
+      if (compactMOBs) {
+        // Add the only reference we get for compact MOB case
+        // because new store file will have only one MOB reference
+        // in this case - of newly compacted MOB file
+        mobRefSet.get().add(mobFileWriter.getPath().getName());
       }
       do {
         hasMore = scanner.next(cells, scannerContext);
         if (LOG.isDebugEnabled()) {
           now = EnvironmentEdgeManager.currentTime();
         }
         for (Cell c : cells) {
-          if (major && CellUtil.isDelete(c)) {
-            if (MobUtils.isMobReferenceCell(c) || delFileWriter == null) {
-              // Directly write it to a store file
-              writer.append(c);
+
+          if (compactMOBs) {
+            if (MobUtils.isMobReferenceCell(c)) {
+              String fName = MobUtils.getMobFileName(c);
+              Path pp = new Path(new Path(fs.getUri()), new Path(path, fName));
+
+              // Added to support migration
+              try {
+                mobCell = mobStore.resolve(c, true, false);
+              } catch (FileNotFoundException fnfe) {
+                if (discardMobMiss) {
+                  LOG.error("Missing MOB cell: file=" + pp + " not found");
+                  continue;
+                } else {
+                  throw fnfe;
+                }
+              }
+
+              if (discardMobMiss && mobCell.getCell().getValueLength() == 0) {
+                LOG.error("Missing MOB cell value: file=" + pp + " cell=" + 
mobCell);
+                continue;
+              }
+
+              if (mobCell.getCell().getValueLength() > mobSizeThreshold) {
+                // put the mob data back to the store file
+                PrivateCellUtil.setSequenceId(mobCell.getCell(), 
c.getSequenceId());
+                if (generationalMob) {
+                  //TODO: verify fName
+                  StoreFileWriter stw = 
mobWriters.getOutputWriterForInputFile(fName);
+                  if (stw != null) {
+                    stw.append(mobCell.getCell());
+                    mobWriters.incrementMobCountForOutputWriter(stw, 1);
+                  } else {
+                    // leave mob cell in a MOB file which is not in compaction 
selections
+                  }
+                } else {
+                  mobFileWriter.append(mobCell.getCell());
+                  mobCells++;
+                }
+                writer.append(MobUtils.createMobRefCell(mobCell.getCell(), 
fileName,
+                  this.mobStore.getRefCellTags()));
+                cellsCountCompactedFromMob++;
+                cellsSizeCompactedFromMob += 
mobCell.getCell().getValueLength();
+              } else {
+
+                // If MOB value is less than threshold, append it directly to 
a store file
+                PrivateCellUtil.setSequenceId(mobCell.getCell(), 
c.getSequenceId());
+                writer.append(mobCell.getCell());
+              }
+
             } else {
-              // Add a ref tag to this cell and write it to a store file.
-              writer.append(MobUtils.createMobRefDeleteMarker(c));
-              // Write the cell to a del file
-              delFileWriter.append(c);
-              deleteMarkersCount++;
+              // Not a MOB reference cell
+              int size = c.getValueLength();
+              if (size > mobSizeThreshold) {
+                // This MOB cell comes from a regular store file
+                // therefore we store it in original mob output
+                mobFileWriter.append(c);
+                writer
+                    .append(MobUtils.createMobRefCell(c, fileName, 
this.mobStore.getRefCellTags()));
+                mobCells++;
 
 Review comment:
   this should increment the cells*CompactedToMob counters

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


With regards,
Apache Git Services

Reply via email to