Skip to content

Commit f4aafaf

Browse files
authored
HBASE-28927 Fix spotbugs issues introduced by refactoring to hbase-diagnostics with HBASE-28432 (#6384)
Signed-off-by: Istvan Toth <[email protected]>
1 parent aea32d7 commit f4aafaf

File tree

9 files changed

+38
-24
lines changed

9 files changed

+38
-24
lines changed

hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/PerformanceEvaluation.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ public String toString() {
249249
public int compareTo(RunResult o) {
250250
return Long.compare(this.duration, o.duration);
251251
}
252+
253+
@Override
254+
public boolean equals(Object obj) {
255+
if (this == obj) {
256+
return true;
257+
}
258+
if (obj == null || getClass() != obj.getClass()) {
259+
return false;
260+
}
261+
return this.compareTo((RunResult) obj) == 0;
262+
}
263+
264+
@Override
265+
public int hashCode() {
266+
return Long.hashCode(duration);
267+
}
252268
}
253269

254270
/**
@@ -3144,14 +3160,15 @@ static TestOptions calculateRowsAndSize(final TestOptions opts) {
31443160
&& (opts.getCmdName().equals(RANDOM_READ) || opts.getCmdName().equals(RANDOM_SEEK_SCAN)))
31453161
&& opts.size != DEFAULT_OPTS.size && opts.perClientRunRows != DEFAULT_OPTS.perClientRunRows
31463162
) {
3147-
opts.totalRows = (int) opts.size * rowsPerGB;
3163+
opts.totalRows = (int) (opts.size * rowsPerGB);
31483164
} else if (opts.size != DEFAULT_OPTS.size) {
31493165
// total size in GB specified
3150-
opts.totalRows = (int) opts.size * rowsPerGB;
3166+
opts.totalRows = (int) (opts.size * rowsPerGB);
31513167
opts.perClientRunRows = opts.totalRows / opts.numClientThreads;
31523168
} else {
31533169
opts.totalRows = opts.perClientRunRows * opts.numClientThreads;
3154-
opts.size = opts.totalRows / rowsPerGB;
3170+
// Cast to float to ensure floating-point division
3171+
opts.size = (float) opts.totalRows / rowsPerGB;
31553172
}
31563173
return opts;
31573174
}

hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/util/LoadTestTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public class LoadTestTool extends AbstractHBaseTool {
164164
public static final String OPT_NUM_REGIONS_PER_SERVER = "num_regions_per_server";
165165
protected static final String OPT_NUM_REGIONS_PER_SERVER_USAGE =
166166
"Desired number of regions per region server. Defaults to 5.";
167-
public static int DEFAULT_NUM_REGIONS_PER_SERVER = 5;
167+
public static final int DEFAULT_NUM_REGIONS_PER_SERVER = 5;
168168

169169
public static final String OPT_REGION_REPLICATION = "region_replication";
170170
protected static final String OPT_REGION_REPLICATION_USAGE =

hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/util/MultiThreadedAction.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,16 @@ public void run() {
203203
long numKeysDelta = numKeys - priorNumKeys;
204204
long totalOpTimeDelta = totalOpTime - priorCumulativeOpTime;
205205

206-
double averageKeysPerSecond = (time > 0) ? (numKeys * 1000 / time) : 0;
206+
double averageKeysPerSecond = (time > 0) ? (numKeys * 1000.0 / time) : 0;
207207

208208
LOG.info(threadsLeft + "Keys=" + numKeys + ", cols="
209209
+ StringUtils.humanReadableInt(numCols.get()) + ", time=" + formatTime(time)
210210
+ ((numKeys > 0 && time > 0)
211-
? (" Overall: [" + "keys/s= " + numKeys * 1000 / time + ", latency="
211+
? (" Overall: [" + "keys/s= " + (numKeys * 1000.0 / time) + ", latency="
212212
+ String.format("%.2f", (double) totalOpTime / (double) numKeys) + " ms]")
213213
: "")
214214
+ ((numKeysDelta > 0)
215-
? (" Current: [" + "keys/s=" + numKeysDelta * 1000 / REPORTING_INTERVAL_MS
215+
? (" Current: [" + "keys/s=" + (numKeysDelta * 1000.0 / REPORTING_INTERVAL_MS)
216216
+ ", latency="
217217
+ String.format("%.2f", (double) totalOpTimeDelta / (double) numKeysDelta) + " ms]")
218218
: "")
@@ -407,15 +407,15 @@ public boolean verifyResultAgainstDataGenerator(Result result, boolean verifyVal
407407
verifyCfAndColumnIntegrity
408408
&& !dataGenerator.verify(result.getRow(), cf, columnValues.keySet())
409409
) {
410-
String colsStr = "";
410+
StringBuilder colsStr = new StringBuilder();
411411
for (byte[] col : columnValues.keySet()) {
412412
if (colsStr.length() > 0) {
413-
colsStr += ", ";
413+
colsStr.append(", ");
414414
}
415-
colsStr += "[" + Bytes.toString(col) + "]";
415+
colsStr.append("[").append(Bytes.toString(col)).append("]");
416416
}
417-
LOG.error("Error checking data for key [" + rowKeyStr + "], bad columns for family ["
418-
+ cfStr + "]: " + colsStr);
417+
LOG.error("Error checking data for key [{}], bad columns for family [{}]: {}", rowKeyStr,
418+
cfStr, colsStr.toString());
419419
printLocations(result);
420420
return false;
421421
}

hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/util/MultiThreadedReader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,15 @@ private Get[] readKey(long[] keysToRead) {
307307

308308
protected Get createGet(long keyToRead) throws IOException {
309309
Get get = new Get(dataGenerator.getDeterministicUniqueKey(keyToRead));
310-
String cfsString = "";
310+
StringBuilder cfsString = new StringBuilder();
311311
byte[][] columnFamilies = dataGenerator.getColumnFamilies();
312312
for (byte[] cf : columnFamilies) {
313313
get.addFamily(cf);
314314
if (verbose) {
315315
if (cfsString.length() > 0) {
316-
cfsString += ", ";
316+
cfsString.append(", ");
317317
}
318-
cfsString += "[" + Bytes.toStringBinary(cf) + "]";
318+
cfsString.append("[").append(Bytes.toStringBinary(cf)).append("]");
319319
}
320320
}
321321
get = dataGenerator.beforeGet(keyToRead, get);
@@ -324,7 +324,7 @@ protected Get createGet(long keyToRead) throws IOException {
324324
get.setConsistency(Consistency.TIMELINE);
325325
}
326326
if (verbose) {
327-
LOG.info("[" + readerId + "] " + "Querying key " + keyToRead + ", cfs " + cfsString);
327+
LOG.info("[{}] Querying key {}, cfs {}", readerId, keyToRead, cfsString.toString());
328328
}
329329
return get;
330330
}

hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/util/MultiThreadedReaderWithACL.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ protected void closeTable() {
8888
@Override
8989
public void queryKey(final Get get, final boolean verify, final long keyToRead)
9090
throws IOException {
91-
final String rowKey = Bytes.toString(get.getRow());
92-
9391
// read the data
9492
final long start = System.nanoTime();
9593
PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>() {

hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/util/MultiThreadedUpdater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void setBatchUpdate(boolean isBatchUpdate) {
7676
this.isBatchUpdate = isBatchUpdate;
7777
}
7878

79-
public void linkToWriter(MultiThreadedWriterBase writer) {
79+
public synchronized void linkToWriter(MultiThreadedWriterBase writer) {
8080
this.writer = writer;
8181
writer.setTrackWroteKeys(true);
8282
}

hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/util/MultiThreadedUpdaterWithACL.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ protected void addUpdaterThreads(int numThreads) throws IOException {
7575
}
7676

7777
public class HBaseUpdaterThreadWithACL extends HBaseUpdaterThread {
78-
79-
private Table table;
8078
private MutateAccessAction mutateAction = new MutateAccessAction();
8179

8280
public HBaseUpdaterThreadWithACL(int updaterId) throws IOException {

hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/wal/WALPerformanceEvaluation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void run() {
168168
loopSpan.end();
169169
}
170170
}
171-
} catch (Exception e) {
171+
} catch (IOException e) {
172172
LOG.error(getClass().getSimpleName() + " Thread failed", e);
173173
} finally {
174174
threadSpan.end();
@@ -241,7 +241,7 @@ public int run(String[] args) throws Exception {
241241
System.err.println("UNEXPECTED: " + cmd);
242242
printUsageAndExit();
243243
}
244-
} catch (Exception e) {
244+
} catch (NumberFormatException e) {
245245
printUsageAndExit();
246246
}
247247
}
@@ -411,7 +411,7 @@ private static void logBenchmarkResult(String testName, long numTests, long tota
411411
}
412412

413413
private void printUsageAndExit() {
414-
System.err.printf("Usage: hbase %s [options]\n", getClass().getName());
414+
System.err.printf("Usage: hbase %s [options]%n", getClass().getName());
415415
System.err.println(" where [options] are:");
416416
System.err.println(" -h|-help Show this help and exit.");
417417
System.err.println(" -threads <N> Number of threads writing on the WAL.");

hbase-server/src/main/java/org/apache/hadoop/hbase/util/LoadTestKVGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public byte[] generateRandomSizeValue(byte[]... seedStrings) {
9898
* Generates random bytes of the given size for the given row and column qualifier. The random
9999
* seed is fully determined by these parameters.
100100
*/
101+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "DMI_RANDOM_USED_ONLY_ONCE")
101102
private static byte[] getValueForRowColumn(int dataSize, byte[]... seedStrings) {
102103
long seed = dataSize;
103104
for (byte[] str : seedStrings) {

0 commit comments

Comments
 (0)