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

 ##########
 File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/mob/FaultyMobStoreCompactor.java
 ##########
 @@ -0,0 +1,373 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.mob;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.PrivateCellUtil;
+import org.apache.hadoop.hbase.io.hfile.CorruptHFileException;
+import org.apache.hadoop.hbase.regionserver.CellSink;
+import org.apache.hadoop.hbase.regionserver.HStore;
+import org.apache.hadoop.hbase.regionserver.InternalScanner;
+import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
+import org.apache.hadoop.hbase.regionserver.ScannerContext;
+import org.apache.hadoop.hbase.regionserver.ShipperListener;
+import org.apache.hadoop.hbase.regionserver.StoreFileWriter;
+import org.apache.hadoop.hbase.regionserver.throttle.ThroughputControlUtil;
+import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+/**
+ * This class is used for testing only. The main purpose is to emulate
+ * random failures during MOB compaction process.
+ * Example of usage:
+ * <pre>{@code
+ * public class SomeTest {
+ *
+ *   public void initConfiguration(Configuration conf){
+ *     conf.set(MobStoreEngine.DEFAULT_MOB_COMPACTOR_CLASS_KEY,
+         FaultyMobStoreCompactor.class.getName());
+       conf.setDouble("hbase.mob.compaction.fault.probability", 0.1);
+ *   }
+ * }
+ * }</pre>
+ * @see org.apache.hadoop.hbase.mob.MobStressToolRunner on how to use and 
configure
+ *   this class.
+ *
+ */
+@InterfaceAudience.Private
+public class FaultyMobStoreCompactor extends DefaultMobStoreCompactor {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(FaultyMobStoreCompactor.class);
+
+  public static AtomicLong mobCounter = new AtomicLong();
+  public static AtomicLong totalFailures = new AtomicLong();
+  public static AtomicLong totalCompactions = new AtomicLong();
+  public static AtomicLong totalMajorCompactions = new AtomicLong();
+
+  static double failureProb = 0.1d;
+  static Random rnd = new Random();
+
+  public FaultyMobStoreCompactor(Configuration conf, HStore store) {
+    super(conf, store);
+    failureProb = conf.getDouble("hbase.mob.compaction.fault.probability", 
0.1);
+  }
+
+  @Override
+  protected boolean performCompaction(FileDetails fd, InternalScanner scanner, 
CellSink writer,
+      long smallestReadPoint, boolean cleanSeqId, ThroughputController 
throughputController,
+      boolean major, int numofFilesToCompact) throws IOException {
+
+    totalCompactions.incrementAndGet();
+    if (major) {
+      totalMajorCompactions.incrementAndGet();
+    }
+    long bytesWrittenProgressForCloseCheck = 0;
+    long bytesWrittenProgressForLog = 0;
+    long bytesWrittenProgressForShippedCall = 0;
+    // Clear old mob references
+    mobRefSet.get().clear();
+    boolean isUserRequest = userRequest.get();
+    boolean compactMOBs = major && isUserRequest;
+    boolean discardMobMiss = 
conf.getBoolean(MobConstants.MOB_UNSAFE_DISCARD_MISS_KEY,
+      MobConstants.DEFAULT_MOB_DISCARD_MISS);
+
+    boolean mustFail = false;
+    if (compactMOBs) {
+      mobCounter.incrementAndGet();
+      double dv = rnd.nextDouble();
+      if (dv < failureProb) {
+        mustFail = true;
+        totalFailures.incrementAndGet();
+      }
+    }
+
+    FileSystem fs = FileSystem.get(conf);
+
+    // Since scanner.next() can return 'false' but still be delivering data,
+    // we have to use a do/while loop.
+    List<Cell> cells = new ArrayList<>();
+    // Limit to "hbase.hstore.compaction.kv.max" (default 10) to avoid OOME
+    int closeCheckSizeLimit = HStore.getCloseCheckInterval();
+    long lastMillis = 0;
+    if (LOG.isDebugEnabled()) {
+      lastMillis = EnvironmentEdgeManager.currentTime();
+    }
+    String compactionName = ThroughputControlUtil.getNameForThrottling(store, 
"compaction");
+    long now = 0;
+    boolean hasMore;
+    Path path = MobUtils.getMobFamilyPath(conf, store.getTableName(), 
store.getColumnFamilyName());
+    byte[] fileName = null;
+    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();
+
+    Cell mobCell = null;
+
+    long counter = 0;
+    long countFailAt = -1;
+    if (mustFail) {
+      countFailAt = rnd.nextInt(100); // randomly fail fast
+    }
+
+    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) {
+        // Bailing out
+        LOG.error("Failed to create mob writer, ", e);
+        throw 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) {
+          counter++;
+          if (compactMOBs) {
+            if (MobUtils.isMobReferenceCell(c)) {
+              if (counter == countFailAt) {
+                LOG.warn("\n\n INJECTED FAULT mobCounter=" + mobCounter.get() 
+ "\n\n");
+                throw new CorruptHFileException("injected fault");
+              }
+              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).getCell();
+              } catch (FileNotFoundException fnfe) {
+                if (discardMobMiss) {
+                  LOG.error("Missing MOB cell: file=" + pp + " not found");
 
 Review comment:
   log fname instead of pp

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