This is an automated email from the ASF dual-hosted git repository.
ctubbsii pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new 5f20e38 Avoid NPE when comparing equality (#2326)
5f20e38 is described below
commit 5f20e38628abd6385a5ee652634f4d748ecd013f
Author: EdColeman
AuthorDate: Mon Oct 25 13:29:22 2021 -0400
Avoid NPE when comparing equality (#2326)
* Use Objects.equals(a,b) instead of a.equals(b) to avoid NPE when a is null
* Apply other minor IDE suggested checkstyle corrections
Co-authored-by: Ed Coleman etcoleman
---
.../apache/accumulo/gc/SimpleGarbageCollector.java | 43 ++
1 file changed, 20 insertions(+), 23 deletions(-)
diff --git
a/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
b/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
index 3b7761f..2c67b7c 100644
--- a/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
+++ b/server/gc/src/main/java/org/apache/accumulo/gc/SimpleGarbageCollector.java
@@ -31,6 +31,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Set;
import java.util.SortedMap;
import java.util.UUID;
@@ -97,7 +98,6 @@ import org.apache.accumulo.server.rpc.ThriftServerType;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.htrace.Trace;
-import org.apache.htrace.TraceScope;
import org.apache.htrace.impl.ProbabilitySampler;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
@@ -110,19 +110,17 @@ import com.google.protobuf.InvalidProtocolBufferException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-// Could/Should implement HighlyAvaialbleService but the Thrift server is
already started before
+// Could/Should implement HighlyAvailableService but the Thrift server is
already started before
// the ZK lock is acquired. The server is only for metrics, there are no
concerns about clients
// using the service before the lock is acquired.
public class SimpleGarbageCollector extends AbstractServer implements Iface {
private static final Logger log =
LoggerFactory.getLogger(SimpleGarbageCollector.class);
- private ServiceLock lock;
-
- private GCStatus status =
+ private final GCStatus status =
new GCStatus(new GcCycleStats(), new GcCycleStats(), new GcCycleStats(),
new GcCycleStats());
- private GcCycleMetrics gcCycleMetrics = new GcCycleMetrics();
+ private final GcCycleMetrics gcCycleMetrics = new GcCycleMetrics();
public static void main(String[] args) throws Exception {
try (SimpleGarbageCollector gc = new SimpleGarbageCollector(new
ServerOpts(), args)) {
@@ -201,14 +199,14 @@ public class SimpleGarbageCollector extends
AbstractServer implements Iface {
private class GCEnv implements GarbageCollectionEnvironment {
-private DataLevel level;
+private final DataLevel level;
GCEnv(Ample.DataLevel level) {
this.level = level;
}
@Override
-public Iterator getCandidates() throws TableNotFoundException {
+public Iterator getCandidates() {
return getContext().getAmple().getGcCandidates(level);
}
@@ -262,7 +260,7 @@ public class SimpleGarbageCollector extends AbstractServer
implements Iface {
.checkConsistency().fetch(DIR, FILES, SCANS).build().stream();
}
- Stream refStream = tabletStream.flatMap(tm -> {
+ return tabletStream.flatMap(tm -> {
Stream refs = Stream.concat(tm.getFiles().stream(),
tm.getScans().stream())
.map(f -> new Reference(tm.getTableId(), f.getMetaUpdateDelete(),
false));
if (tm.getDirName() != null) {
@@ -271,8 +269,6 @@ public class SimpleGarbageCollector extends AbstractServer
implements Iface {
}
return refs;
});
-
- return refStream;
}
@Override
@@ -323,7 +319,7 @@ public class SimpleGarbageCollector extends AbstractServer
implements Iface {
// volume switching when something needs to be deleted. Since
the rest of the code
// uses suffixes to compare delete entries, there is no danger
// of deleting something that should not be deleted. Must not
change value of delete
- // variable because thats whats stored in metadata table.
+ // variable because that's what's stored in metadata table.
log.debug("Volume replaced {} -> {}", delete, switchedDelete);
fullPath = TabletFileUtil.validate(switchedDelete);
} else {
@@ -402,7 +398,7 @@ public class SimpleGarbageCollector extends AbstractServer
implements Iface {
// if dir exist and is empty, then empty list is returned...
// hadoop 2.0 will throw an