Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public int compare(Cell a, Cell b) {
* @param a
* @param b
* @param ignoreSequenceid True if we are to compare the key portion only and ignore
* the sequenceid. Set to false to compare key and consider sequenceid.
* the sequenceid. Set to false to compare key and consider sequenceid.
* @return 0 if equal, -1 if a < b, and +1 if a > b.
*/
public static int compare(final Cell a, final Cell b, boolean ignoreSequenceid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* An immutable type to hold a hostname and port combo, like an Endpoint
* or java.net.InetSocketAddress (but without danger of our calling
* resolve -- we do NOT want a resolve happening every time we want
* to hold a hostname and port combo). This class is also <<Comparable>>.
* to hold a hostname and port combo). This class is also {@link Comparable}
* <p>In implementation this class is a facade over Guava's {@link HostAndPort}.
* We cannot have Guava classes in our API hence this Type.
*/
Expand Down Expand Up @@ -83,7 +83,10 @@ public int hashCode() {
@Override
public int compareTo(Address that) {
int compare = this.getHostname().compareTo(that.getHostname());
if (compare != 0) return compare;
if (compare != 0) {
return compare;
}

return this.getPort() - that.getPort();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class SpanReceiverHost {
private boolean closed = false;

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SE_BAD_FIELD")
private static enum SingletonHolder {
private enum SingletonHolder {
INSTANCE;
final Object lock = new Object();
SpanReceiverHost host = null; // FindBugs: SE_BAD_FIELD
Expand All @@ -64,14 +64,13 @@ public static SpanReceiverHost getInstance(Configuration conf) {
}

SpanReceiverHost(Configuration conf) {
receivers = new HashSet<SpanReceiver>();
receivers = new HashSet<>();
this.conf = conf;
}

/**
* Reads the names of classes specified in the {@code hbase.trace.spanreceiver.classes} property
* and instantiates and registers them with the Tracer.
*
*/
public void loadSpanReceivers() {
String[] receiverNames = conf.getStrings(SPAN_RECEIVERS_CONF_KEY);
Expand All @@ -98,7 +97,10 @@ public void loadSpanReceivers() {
* Calls close() on all SpanReceivers created by this SpanReceiverHost.
*/
public synchronized void closeReceivers() {
if (closed) return;
if (closed) {
return;
}

closed = true;
for (SpanReceiver rcvr : receivers) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class ByteRangeUtils {
public final class ByteRangeUtils {
Comment thread
busbey marked this conversation as resolved.
Outdated
private ByteRangeUtils() {
Comment thread
busbey marked this conversation as resolved.
Outdated
}

public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int rightInnerOffset) {
int maxCompares = Math.min(left.getLength(), right.getLength() - rightInnerOffset);
final byte[] lbytes = left.getBytes(), rbytes = right.getBytes();
final int loffset = left.getOffset(), roffset = right.getOffset();
final byte[] lbytes = left.getBytes();
final byte[] rbytes = right.getBytes();
final int loffset = left.getOffset();
final int roffset = right.getOffset();
for (int i = 0; i < maxCompares; ++i) {
if (lbytes[loffset + i] != rbytes[roffset + rightInnerOffset + i]) {
return i;
Expand All @@ -49,7 +53,7 @@ public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int right

public static ArrayList<byte[]> copyToNewArrays(Collection<ByteRange> ranges) {
if (ranges == null) {
return new ArrayList<byte[]>(0);
return new ArrayList<>(0);
}
ArrayList<byte[]> arrays = Lists.newArrayListWithCapacity(ranges.size());
for (ByteRange range : ranges) {
Expand All @@ -60,7 +64,7 @@ public static ArrayList<byte[]> copyToNewArrays(Collection<ByteRange> ranges) {

public static ArrayList<ByteRange> fromArrays(Collection<byte[]> arrays) {
if (arrays == null) {
return new ArrayList<ByteRange>(0);
return new ArrayList<>(0);
}
ArrayList<ByteRange> ranges = Lists.newArrayListWithCapacity(arrays.size());
for (byte[] array : arrays) {
Expand All @@ -78,5 +82,4 @@ public static void write(OutputStream os, ByteRange byteRange, int byteRangeInne
os.write(byteRange.getBytes(), byteRange.getOffset() + byteRangeInnerOffset,
byteRange.getLength() - byteRangeInnerOffset);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public static boolean isMatchingTail(final Path pathToSearch, final Path pathTai
* @return True if deleted <code>dir</code>
* @throws IOException e
*/
public static boolean deleteDirectory(final FileSystem fs, final Path dir)
throws IOException {
public static boolean deleteDirectory(final FileSystem fs, final Path dir) throws IOException {
return fs.exists(dir) && fs.delete(dir, true);
}

Expand All @@ -157,7 +156,7 @@ public static long getDefaultBlockSize(final FileSystem fs, final Path path) thr
Method m = null;
Class<? extends FileSystem> cls = fs.getClass();
try {
m = cls.getMethod("getDefaultBlockSize", new Class<?>[] { Path.class });
m = cls.getMethod("getDefaultBlockSize", Path.class);
Comment thread
busbey marked this conversation as resolved.
Outdated
} catch (NoSuchMethodException e) {
LOG.info("FileSystem doesn't support getDefaultBlockSize");
} catch (SecurityException e) {
Expand Down Expand Up @@ -192,7 +191,7 @@ public static short getDefaultReplication(final FileSystem fs, final Path path)
Method m = null;
Class<? extends FileSystem> cls = fs.getClass();
try {
m = cls.getMethod("getDefaultReplication", new Class<?>[] { Path.class });
m = cls.getMethod("getDefaultReplication", Path.class);
Comment thread
busbey marked this conversation as resolved.
Outdated
} catch (NoSuchMethodException e) {
LOG.info("FileSystem doesn't support getDefaultReplication");
} catch (SecurityException e) {
Expand Down Expand Up @@ -358,11 +357,11 @@ public static Path getRootDir(final Configuration c) throws IOException {
return p.makeQualified(fs);
}

public static void setRootDir(final Configuration c, final Path root) throws IOException {
public static void setRootDir(final Configuration c, final Path root) {
c.set(HConstants.HBASE_DIR, root.toString());
}

public static void setFsDefault(final Configuration c, final Path root) throws IOException {
public static void setFsDefault(final Configuration c, final Path root) {
c.set("fs.defaultFS", root.toString()); // for hadoop 0.21+
}

Expand All @@ -387,7 +386,7 @@ public static Path getWALRootDir(final Configuration c) throws IOException {
}

@VisibleForTesting
public static void setWALRootDir(final Configuration c, final Path root) throws IOException {
public static void setWALRootDir(final Configuration c, final Path root) {
c.set(HBASE_WAL_DIR, root.toString());
}

Expand Down Expand Up @@ -481,8 +480,7 @@ public static void setStoragePolicy(final FileSystem fs, final Configuration con
setStoragePolicy(fs, path, storagePolicy);
}

private static final Map<FileSystem, Boolean> warningMap =
new ConcurrentHashMap<FileSystem, Boolean>();
private static final Map<FileSystem, Boolean> warningMap = new ConcurrentHashMap<>();

/**
* Sets storage policy for given path.
Expand Down Expand Up @@ -560,8 +558,7 @@ private static void invokeSetStoragePolicy(final FileSystem fs, final Path path,
Method m = null;
Exception toThrow = null;
try {
m = fs.getClass().getDeclaredMethod("setStoragePolicy",
new Class<?>[] { Path.class, String.class });
m = fs.getClass().getDeclaredMethod("setStoragePolicy", Path.class, String.class);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

branch-1's minimum hadoop version is 2.8.5, so for that branch we can remove this reflection as well. Note to potential further backporters: the method is not in Hadoop 2.7, we'll need this reflection in branch-1.4 and branch-1.3.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the reflection part. Will create additional backports for branch-1.4 and branch-1.3.

m.setAccessible(true);
} catch (NoSuchMethodException e) {
toThrow = e;
Expand Down Expand Up @@ -621,7 +618,6 @@ private static void invokeSetStoragePolicy(final FileSystem fs, final Path path,
}
}


/**
* @param conf must not be null
* @return True if this filesystem whose scheme is 'hdfs'.
Expand All @@ -647,8 +643,7 @@ public static boolean isRecoveredEdits(Path path) {
* @return Returns the filesystem of the hbase rootdir.
* @throws IOException from underlying FileSystem
*/
public static FileSystem getCurrentFileSystem(Configuration conf)
throws IOException {
public static FileSystem getCurrentFileSystem(Configuration conf) throws IOException {
return getRootDir(conf).getFileSystem(conf);
}

Expand All @@ -666,7 +661,7 @@ public static FileSystem getCurrentFileSystem(Configuration conf)
* @param filter path filter
* @return null if dir is empty or doesn't exist, otherwise FileStatus array
*/
public static FileStatus [] listStatus(final FileSystem fs,
public static FileStatus[] listStatus(final FileSystem fs,
final Path dir, final PathFilter filter) throws IOException {
FileStatus [] status = null;
try {
Expand Down Expand Up @@ -753,21 +748,21 @@ public static boolean isExists(final FileSystem fs, final Path path) throws IOEx
* Log the current state of the filesystem from a certain root directory
* @param fs filesystem to investigate
* @param root root file/directory to start logging from
* @param LOG log to output information
* @param log log to output information
* @throws IOException if an unexpected exception occurs
*/
public static void logFileSystemState(final FileSystem fs, final Path root, Log LOG)
public static void logFileSystemState(final FileSystem fs, final Path root, Log log)
throws IOException {
LOG.debug("Current file system:");
logFSTree(LOG, fs, root, "|-");
log.debug("Current file system:");
logFSTree(log, fs, root, "|-");
}

/**
* Recursive helper to log the state of the FS
*
* @see #logFileSystemState(FileSystem, Path, Log)
*/
private static void logFSTree(Log LOG, final FileSystem fs, final Path root, String prefix)
private static void logFSTree(Log log, final FileSystem fs, final Path root, String prefix)
throws IOException {
FileStatus[] files = listStatus(fs, root, null);
if (files == null) {
Expand All @@ -776,10 +771,10 @@ private static void logFSTree(Log LOG, final FileSystem fs, final Path root, Str

for (FileStatus file : files) {
if (file.isDirectory()) {
LOG.debug(prefix + file.getPath().getName() + "/");
logFSTree(LOG, fs, file.getPath(), prefix + "---");
log.debug(prefix + file.getPath().getName() + "/");
logFSTree(log, fs, file.getPath(), prefix + "---");
} else {
LOG.debug(prefix + file.getPath().getName());
log.debug(prefix + file.getPath().getName());
}
}
}
Expand All @@ -791,25 +786,6 @@ public static boolean renameAndSetModifyTime(final FileSystem fs, final Path src
return fs.rename(src, dest);
}

/**
* Do our short circuit read setup.
* Checks buffer size to use and whether to do checksumming in hbase or hdfs.
* @param conf must not be null
*/
public static void setupShortCircuitRead(final Configuration conf) {
// Check that the user has not set the "dfs.client.read.shortcircuit.skip.checksum" property.
boolean shortCircuitSkipChecksum =
conf.getBoolean("dfs.client.read.shortcircuit.skip.checksum", false);
boolean useHBaseChecksum = conf.getBoolean(HConstants.HBASE_CHECKSUM_VERIFICATION, true);
if (shortCircuitSkipChecksum) {
LOG.warn("Configuration \"dfs.client.read.shortcircuit.skip.checksum\" should not " +
"be set to true." + (useHBaseChecksum ? " HBase checksum doesn't require " +
"it, see https://issues.apache.org/jira/browse/HBASE-6868." : ""));
assert !shortCircuitSkipChecksum; //this will fail if assertions are on
}
checkShortCircuitReadBufferSize(conf);
}

/**
* Check if short circuit read buffer size is set and if not, set it to hbase value.
* @param conf must not be null
Expand Down Expand Up @@ -912,5 +888,4 @@ public StreamLacksCapabilityException(String message) {
super(message);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ public T next() {
if (!components.isEmpty()) {
this.nextWasCalled = true;
List<T> src = components.get(currentComponent);
if (++indexWithinComponent < src.size()) return src.get(indexWithinComponent);
if (++indexWithinComponent < src.size()) {
return src.get(indexWithinComponent);
}

if (++currentComponent < components.size()) {
indexWithinComponent = 0;
src = components.get(currentComponent);
Expand Down
41 changes: 30 additions & 11 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/util/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,31 @@
@InterfaceAudience.Public
@InterfaceStability.Evolving
public enum Order {

ASCENDING {
@Override
public int cmp(int cmp) { /* noop */ return cmp; }
public int cmp(int cmp) {
/* noop */ return cmp;
}

@Override
public byte apply(byte val) { /* noop */ return val; }
public byte apply(byte val) {
/* noop */ return val;
}

@Override
public void apply(byte[] val) { /* noop */ }
public void apply(byte[] val) {
/* noop */
}

@Override
public void apply(byte[] val, int offset, int length) { /* noop */ }
public void apply(byte[] val, int offset, int length) {
/* noop */
}

@Override
public String toString() { return "ASCENDING"; }
public String toString() {
return "ASCENDING";
}
},

DESCENDING {
Expand All @@ -55,23 +64,33 @@ public void apply(byte[] val, int offset, int length) { /* noop */ }
private static final byte MASK = (byte) 0xff;

@Override
public int cmp(int cmp) { return -1 * cmp; }
public int cmp(int cmp) {
return -1 * cmp;
}

@Override
public byte apply(byte val) { return (byte) (val ^ MASK); }
public byte apply(byte val) {
return (byte) (val ^ MASK);
}

@Override
public void apply(byte[] val) {
for (int i = 0; i < val.length; i++) { val[i] ^= MASK; }
for (int i = 0; i < val.length; i++) {
val[i] ^= MASK;
}
}

@Override
public void apply(byte[] val, int offset, int length) {
for (int i = 0; i < length; i++) { val[offset + i] ^= MASK; }
for (int i = 0; i < length; i++) {
val[offset + i] ^= MASK;
}
}

@Override
public String toString() { return "DESCENDING"; }
public String toString() {
return "DESCENDING";
}
};

/**
Expand Down