Skip to content

Commit

Permalink
fix spotbugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Apache9 committed Jul 1, 2024
1 parent be322c7 commit 489b5d7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@ default CompletableFuture<Boolean> balance() {
* @deprecated Since 2.5.0. Will be removed in 4.0.0. Use {@link #balance(BalanceRequest)}
* instead.
*/
@Deprecated
default CompletableFuture<Boolean> balance(boolean forcible) {
return balance(BalanceRequest.newBuilder().setIgnoreRegionsInTransition(forcible).build())
.thenApply(BalanceResponse::isBalancerRan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public long getCpRequestsCount(String table) {
return 99;
}

@Override
public long getStaticIndexSize(String table) {
return 101;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1441,50 +1441,6 @@ private void dumpPrefetchList() {
}
}

/**
* Create an input stream that deletes the file after reading it. Use in try-with-resources to
* avoid this pattern where an exception thrown from a finally block may mask earlier exceptions:
*
* <pre>
* File f = ...
* try (FileInputStream fis = new FileInputStream(f)) {
* // use the input stream
* } finally {
* if (!f.delete()) throw new IOException("failed to delete");
* }
* </pre>
*
* @param file the file to read and delete
* @return a FileInputStream for the given file
* @throws IOException if there is a problem creating the stream
*/
private FileInputStream deleteFileOnClose(final File file) throws IOException {
return new FileInputStream(file) {
private File myFile;

private FileInputStream init(File file) {
myFile = file;
return this;
}

@Override
public void close() throws IOException {
// close() will be called during try-with-resources and it will be
// called by finalizer thread during GC. To avoid double-free resource,
// set myFile to null after the first call.
if (myFile == null) {
return;
}

super.close();
if (!myFile.delete()) {
throw new IOException("Failed deleting persistence file " + myFile.getAbsolutePath());
}
myFile = null;
}
}.init(file);
}

private void verifyCapacityAndClasses(long capacitySize, String ioclass, String mapclass)
throws IOException {
if (capacitySize != cacheCapacity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
*/
package org.apache.hadoop.hbase.regionserver;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -46,7 +47,8 @@ public class ServerNonceManager {
*/
private int conflictWaitIterationMs = 30000;

private static final SimpleDateFormat tsFormat = new SimpleDateFormat("HH:mm:ss.SSS");
private static final DateTimeFormatter TS_FORMAT =
DateTimeFormatter.ofPattern("HH:mm:ss.SSS").withZone(ZoneId.systemDefault());

// This object is used to synchronize on in case of collisions, and for cleanup.
private static class OperationContext {
Expand All @@ -65,7 +67,7 @@ private static class OperationContext {
@Override
public String toString() {
return "[state " + getState() + ", hasWait " + hasWait() + ", activity "
+ tsFormat.format(new Date(getActivityTime())) + "]";
+ TS_FORMAT.format(Instant.ofEpochMilli(getActivityTime())) + "]";
}

public OperationContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void start(Map<byte[], List<Cell>> familyMaps) throws RegionTooBusyExcept
return;
}

String tooBusyStore = null;
StringBuilder tooBusyStore = new StringBuilder();
boolean aboveParallelThreadLimit = false;
boolean aboveParallelPrePutLimit = false;

Expand All @@ -148,9 +148,10 @@ public void start(Map<byte[], List<Cell>> familyMaps) throws RegionTooBusyExcept
store.getCurrentParallelPutCount() > this.parallelPutToStoreThreadLimit;
boolean storeAbovePrePut = preparePutCount > this.parallelPreparePutToStoreThreadLimit;
if (storeAboveThread || storeAbovePrePut) {
tooBusyStore = (tooBusyStore == null
? store.getColumnFamilyName()
: tooBusyStore + "," + store.getColumnFamilyName());
if (tooBusyStore.length() > 0) {
tooBusyStore.append(',');
}
tooBusyStore.append(store.getColumnFamilyName());
}
aboveParallelThreadLimit |= storeAboveThread;
aboveParallelPrePutLimit |= storeAbovePrePut;
Expand Down

0 comments on commit 489b5d7

Please sign in to comment.