Skip to content

Commit

Permalink
Merge pull request #3 from kakao/mini666-hbase-tools-phoenix
Browse files Browse the repository at this point in the history
Mini666 hbase tools phoenix
  • Loading branch information
EungsopYoo authored Nov 1, 2018
2 parents 47aa19e + 31a6795 commit 981e130
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public abstract class Args {
public static final String OPTION_INTERACTIVE = "interactive";
public static final String OPTION_CONF = "conf";
public static final String OPTION_CONF_SHORT = "c";
public static final String OPTION_PHOENIX = "phoenix-salting-table";

public static final String INVALID_ARGUMENTS = "Invalid arguments";
public static final String ALL_TABLES = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private static Number diffRatioNumber(Number one, Number two) {
if (one == null) {
if (two == null) return null;
else {
if (two == 0) {
if (two.intValue() == 0) {
return RatioNumber.ZERO.doubleValue();
} else {
return -two.doubleValue();
Expand All @@ -409,7 +409,7 @@ private static Number diffRatioNumber(Number one, Number two) {
} else {
if (two == null) return one.doubleValue();
else {
if (two == 0) {
if (two.intValue() == 0) {
return one.doubleValue();
} else {
return one.doubleValue() - two.doubleValue();
Expand All @@ -432,7 +432,7 @@ private static Number addRatioNumber(Number one, Number two) {
if (one == null) {
if (two == null) return null;
else {
if (two == 0) {
if (two.intValue() == 0) {
return RatioNumber.ZERO;
} else {
return two;
Expand All @@ -441,9 +441,9 @@ private static Number addRatioNumber(Number one, Number two) {
} else {
if (two == null) return one;
else {
if (one == 0) {
if (one.intValue() == 0) {
return two;
} else if (two == 0) {
} else if (two.intValue() == 0) {
return one;
} else {
return ((RatioNumber) one).add((RatioNumber) two);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected OptionParser createOptionParser() {
optionParser.accepts(OPTION_LOCALITY_THRESHOLD).withRequiredArg().ofType(Double.class);
optionParser.accepts(OPTION_CF).withRequiredArg().ofType(String.class);
optionParser.accepts(OPTION_INTERACTIVE);
optionParser.accepts(OPTION_PHOENIX);
return optionParser;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.*;
Expand All @@ -43,6 +44,7 @@ public class Merge implements Command {
private final HConnection connection;
private boolean proceed = false;
private boolean test = false;
private boolean isPhoenixSaltingTable;

public Merge(HBaseAdmin admin, Args args) throws IOException {
if (args.getOptionSet().nonOptionArguments().size() < 2
Expand All @@ -57,6 +59,8 @@ public Merge(HBaseAdmin admin, Args args) throws IOException {
this.connection = HConnectionManager.createConnection(admin.getConfiguration());

tableNameSet = Util.parseTableSet(admin, args);

if (args.has(Args.OPTION_PHOENIX)) this.isPhoenixSaltingTable = true;
}

@SuppressWarnings("unused")
Expand All @@ -70,6 +74,7 @@ public static String usage() {
+ " empty - Merge all empty regions.\n"
+ " options:\n"
+ " --" + Args.OPTION_MAX_ITERATION + " - Set max iteration.\n"
+ " --" + Args.OPTION_PHOENIX + " - Set if the table to be merged is phoenix salted table.\n"
+ Args.commonUsage();
}

Expand Down Expand Up @@ -213,6 +218,27 @@ private int getSize(TableInfo tableInfo, HRegionInfo region) {
return Integer.MAX_VALUE;
}

private boolean isRegionBoundaryOfPhoenixSaltingTable(HRegionInfo regionInfo) {
byte[] endKey = regionInfo.getEndKey();
boolean boundaryRegionForPhoenix = true;

if (endKey.length > 0) {
for (int i = 1, limit = endKey.length; i < limit; i++) {
if (endKey[i] != 0) {
boundaryRegionForPhoenix = false;
break;
}
}
}

if (boundaryRegionForPhoenix) {
Util.printVerboseMessage(args, regionInfo.getEncodedName() + " is boundary region of phoenix : "
+ Bytes.toStringBinary(regionInfo.getStartKey()) + " ~ " + Bytes.toStringBinary(regionInfo.getEndKey()));
}

return boundaryRegionForPhoenix;
}

private void emptyFast(TableInfo tableInfo) throws Exception {
long timestampPrev;
boolean merged;
Expand Down Expand Up @@ -243,6 +269,11 @@ private void emptyFast(TableInfo tableInfo) throws Exception {

for (int i = 0; i < emptyRegions.size(); i++) {
HRegionInfo regionA = emptyRegions.get(i);
// 첫번째 리전의 endKey가 피닉스 솔팅 테이블의 리전 바운더리가 아니여야 한다.
if (isPhoenixSaltingTable && isRegionBoundaryOfPhoenixSaltingTable(regionA)) {
continue;
}

if (i != emptyRegions.size() - 1) {
HRegionInfo regionB = emptyRegions.get(i + 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public boolean isRecordChanged(Level level) {
}

public boolean isSummaryChanged(LoadEntry loadEntry) {
return summaryChangeMap.get(loadEntry) == ChangeState.changed.ordinal();
return summaryChangeMap.get(loadEntry).intValue() == ChangeState.changed.ordinal();
}

public boolean isDiffFromStart() {
Expand Down

0 comments on commit 981e130

Please sign in to comment.