HBASE-17243 Reuse CompactionPartitionId and avoid creating MobFileName in PartitionedMobCompactor to avoid unnecessary new objects
Signed-off-by: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
This commit is contained in:
parent
7775feda05
commit
efcd15bf67
|
@ -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,12 +116,30 @@ 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue