hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mberto...@apache.org
Subject hbase git commit: HBASE-17243 Reuse CompactionPartitionId and avoid creating MobFileName in PartitionedMobCompactor to avoid unnecessary new objects
Date Sat, 03 Dec 2016 11:56:17 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 7775feda0 -> efcd15bf6


HBASE-17243 Reuse CompactionPartitionId and avoid creating MobFileName in PartitionedMobCompactor
to avoid unnecessary new objects

Signed-off-by: Matteo Bertozzi <matteo.bertozzi@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/efcd15bf
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/efcd15bf
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/efcd15bf

Branch: refs/heads/master
Commit: efcd15bf67f155e29b337886fe38eadfce75ffc6
Parents: 7775fed
Author: Huaxiang Sun <hsun@cloudera.com>
Authored: Sat Dec 3 03:47:06 2016 -0800
Committer: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
Committed: Sat Dec 3 03:48:23 2016 -0800

----------------------------------------------------------------------
 .../apache/hadoop/hbase/mob/MobFileName.java    | 46 +++++++++++++-------
 .../PartitionedMobCompactionRequest.java        | 15 ++++++-
 .../compactions/PartitionedMobCompactor.java    | 17 +++++---
 3 files changed, 54 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/efcd15bf/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileName.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileName.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileName.java
index 2364a47..6ca67ad 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileName.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileName.java
@@ -41,12 +41,15 @@ import org.apache.hadoop.hbase.util.MD5Hash;
  */
 @InterfaceAudience.Private
 public final class MobFileName {
-
   private final String date;
   private final String startKey;
   private final String uuid;
   private final String fileName;
 
+  private static final int STARTKEY_END_INDEX = 32;
+  private static final int DATE_END_INDEX = 40;
+  private static final int UUID_END_INDEX = 72;
+
   /**
    * @param startKey
    *          The start key.
@@ -59,7 +62,7 @@ public final class MobFileName {
     this.startKey = MD5Hash.getMD5AsHex(startKey, 0, startKey.length);
     this.uuid = uuid;
     this.date = date;
-    this.fileName = this.startKey + date + uuid;
+    this.fileName = this.startKey + this.date + this.uuid;
   }
 
   /**
@@ -74,14 +77,14 @@ public final class MobFileName {
     this.startKey = startKey;
     this.uuid = uuid;
     this.date = date;
-    this.fileName = this.startKey + date + uuid;
+    this.fileName = this.startKey + this.date + this.uuid;
   }
 
   /**
    * Creates an instance of MobFileName
    *
    * @param startKey
-   *          The start key.
+   *          The md5 hex string of the start key.
    * @param date
    *          The string of the latest timestamp of cells in this file, the format is yyyymmdd.
    * @param uuid The uuid.
@@ -113,13 +116,31 @@ public final class MobFileName {
   public static MobFileName create(String fileName) {
     // The format of a file name is md5HexString(0-31bytes) + date(32-39bytes) + UUID
     // The date format is yyyyMMdd
-    String startKey = fileName.substring(0, 32);
-    String date = fileName.substring(32, 40);
-    String uuid = fileName.substring(40);
+    String startKey = fileName.substring(0, STARTKEY_END_INDEX);
+    String date = fileName.substring(STARTKEY_END_INDEX, DATE_END_INDEX);
+    String uuid = fileName.substring(DATE_END_INDEX, UUID_END_INDEX);
     return new MobFileName(startKey, date, uuid);
   }
 
   /**
+   * get startKey from MobFileName.
+   * @param fileName file name.
+   * @return startKey
+   */
+  public static String getStartKeyFromName(final String fileName) {
+    return fileName.substring(0, STARTKEY_END_INDEX);
+  }
+
+  /**
+   * get date from MobFileName.
+   * @param fileName file name.
+   * @return date
+   */
+  public static String getDateFromName(final String fileName) {
+    return fileName.substring(STARTKEY_END_INDEX, DATE_END_INDEX);
+  }
+
+  /**
    * Gets the hex string of the md5 for a start key.
    * @return The hex string of the md5 for a start key.
    */
@@ -137,11 +158,7 @@ public final class MobFileName {
 
   @Override
   public int hashCode() {
-    StringBuilder builder = new StringBuilder();
-    builder.append(startKey);
-    builder.append(date);
-    builder.append(uuid);
-    return builder.toString().hashCode();
+    return fileName.hashCode();
   }
 
   @Override
@@ -151,10 +168,7 @@ public final class MobFileName {
     }
     if (anObject instanceof MobFileName) {
       MobFileName another = (MobFileName) anObject;
-      if (this.startKey.equals(another.startKey) && this.date.equals(another.date)
-          && this.uuid.equals(another.uuid)) {
-        return true;
-      }
+      return this.getFileName().equals(another.getFileName());
     }
     return false;
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/efcd15bf/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactionRequest.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactionRequest.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactionRequest.java
index 227f1e4..e288571 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactionRequest.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactionRequest.java
@@ -92,10 +92,15 @@ public class PartitionedMobCompactionRequest extends MobCompactionRequest
{
    * The partition id that consists of start key and date of the mob file name.
    */
   public static class CompactionPartitionId {
-
     private String startKey;
     private String date;
 
+    public CompactionPartitionId() {
+      // initialize these fields to empty string
+      this.startKey = "";
+      this.date = "";
+    }
+
     public CompactionPartitionId(String startKey, String date) {
       if (startKey == null || date == null) {
         throw new IllegalArgumentException("Neither of start key and date could be null");
@@ -108,10 +113,18 @@ public class PartitionedMobCompactionRequest extends MobCompactionRequest
{
       return this.startKey;
     }
 
+    public void setStartKey(final String startKey) {
+      this.startKey = startKey;
+    }
+
     public String getDate() {
       return this.date;
     }
 
+    public void setDate(final String date) {
+      this.date = date;
+    }
+
     @Override
     public int hashCode() {
       int result = 17;

http://git-wip-us.apache.org/repos/asf/hbase/blob/efcd15bf/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactor.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactor.java
index 731fb45..6c8080c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/compactions/PartitionedMobCompactor.java
@@ -144,10 +144,12 @@ public class PartitionedMobCompactor extends MobCompactor {
    */
   protected PartitionedMobCompactionRequest select(List<FileStatus> candidates,
     boolean allFiles) throws IOException {
-    Collection<FileStatus> allDelFiles = new ArrayList<>();
-    Map<CompactionPartitionId, CompactionPartition> filesToCompact = new HashMap<>();
+    final Collection<FileStatus> allDelFiles = new ArrayList<>();
+    final Map<CompactionPartitionId, CompactionPartition> filesToCompact = new HashMap<>();
+    final CompactionPartitionId id = new CompactionPartitionId();
     int selectedFileCount = 0;
     int irrelevantFileCount = 0;
+
     for (FileStatus file : candidates) {
       if (!file.isFile()) {
         irrelevantFileCount++;
@@ -166,15 +168,16 @@ public class PartitionedMobCompactor extends MobCompactor {
       }
       if (StoreFileInfo.isDelFile(linkedFile.getPath())) {
         allDelFiles.add(file);
-      } else if (allFiles || linkedFile.getLen() < mergeableSize) {
+      } else if (allFiles || (linkedFile.getLen() < mergeableSize)) {
         // add all files if allFiles is true,
         // otherwise add the small files to the merge pool
-        MobFileName fileName = MobFileName.create(linkedFile.getPath().getName());
-        CompactionPartitionId id = new CompactionPartitionId(fileName.getStartKey(),
-          fileName.getDate());
+        String fileName = linkedFile.getPath().getName();
+        id.setStartKey(MobFileName.getStartKeyFromName(fileName));
+        id.setDate(MobFileName.getDateFromName(fileName));
         CompactionPartition compactionPartition = filesToCompact.get(id);
         if (compactionPartition == null) {
-          compactionPartition = new CompactionPartition(id);
+          compactionPartition = new CompactionPartition(
+              new CompactionPartitionId(id.getStartKey(), id.getDate()));
           compactionPartition.addFile(file);
           filesToCompact.put(id, compactionPartition);
         } else {


Mime
View raw message