Skip to content
Permalink
Browse files
[minor] [optimize] Remove redundant toString call (#3254)
  • Loading branch information
Shoothzj committed May 5, 2022
1 parent e79da7c commit 90d55017da68111ffc578b611de998269f701f82
Showing 37 changed files with 77 additions and 98 deletions.
@@ -404,7 +404,7 @@ public void process(WatchedEvent event) {
OutputStream fos = new BufferedOutputStream(new FileOutputStream(latencyFile));

for (Long l: latency) {
fos.write((Long.toString(l) + "\t" + (l / 1000000) + "ms\n").getBytes(UTF_8));
fos.write((l + "\t" + (l / 1000000) + "ms\n").getBytes(UTF_8));
}
fos.flush();
fos.close();
@@ -310,7 +310,7 @@ private Map<String, Object> toMap() {
Map<String, Object> configMap = new HashMap<>();
Iterator<String> iterator = this.getKeys();
while (iterator.hasNext()) {
String key = iterator.next().toString();
String key = iterator.next();
Object property = this.getProperty(key);
if (property != null) {
configMap.put(key, property.toString());
@@ -167,7 +167,7 @@ public String toString() {
}
StringBuilder b = new StringBuilder();
b.append(CURRENT_COOKIE_LAYOUT_VERSION).append("\n");
b.append(builder.build().toString());
b.append(builder.build());
return b.toString();
}

@@ -1222,7 +1222,7 @@ journalFormatVersionToWrite, getBufferedChannelBuilder(),
LOG.info("Journal exits when shutting down");
} finally {
// There could be packets queued for forceWrite on this logFile
// That is fine as this exception is going to anyway take down the
// That is fine as this exception is going to anyway take down
// the bookie. If we execute this as a part of graceful shutdown,
// close will flush the file system cache making any previous
// cached writes durable so this is fine as well.
@@ -1277,7 +1277,6 @@ private static int fullRead(JournalChannel fc, ByteBuffer bb) throws IOException
return total;
}

//
/**
* Wait for the Journal thread to exit.
* This is method is needed in order to mock the journal, we can't mock final method of java.lang.Thread class
@@ -23,12 +23,9 @@

import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.annotations.VisibleForTesting;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Arrays;
@@ -58,7 +55,7 @@ class JournalChannel implements Closeable {

static final int SECTOR_SIZE = 512;
private static final int START_OF_FILE = -12345;
private static long cacheDropLagBytes = 8 * MB;
private static final long cacheDropLagBytes = 8 * MB;

// No header
static final int V1 = 1;
@@ -71,7 +68,7 @@ class JournalChannel implements Closeable {
// 1) expanding header to 512
// 2) Padding writes to align sector size
static final int V5 = 5;
// Adding explicitlac entry
// Adding explicit lac entry
public static final int V6 = 6;

static final int HEADER_SIZE = SECTOR_SIZE; // align header to sector size
@@ -309,12 +306,4 @@ public void forceWrite(boolean forceMetadata) throws IOException {
}
}

@VisibleForTesting
public static FileChannel openFileChannel(RandomAccessFile randomAccessFile) {
if (randomAccessFile == null) {
throw new IllegalArgumentException("Input cannot be null");
}

return randomAccessFile.getChannel();
}
}
@@ -1248,7 +1248,7 @@ private Map<String, Object> toMap() {
Map<String, Object> configMap = new HashMap<>();
Iterator<String> iterator = this.getKeys();
while (iterator.hasNext()) {
String key = iterator.next().toString();
String key = iterator.next();
Object property = this.getProperty(key);
if (property != null) {
configMap.put(key, property.toString());
@@ -115,7 +115,7 @@ public Map<String, String> getSwitchMap() {
public String dumpTopology() {
Map<String, String> rack = getSwitchMap();
StringBuilder builder = new StringBuilder();
builder.append("Mapping: ").append(toString()).append("\n");
builder.append("Mapping: ").append(this).append("\n");
if (rack != null) {
builder.append("Map:\n");
Set<String> switches = new HashSet<String>();
@@ -421,7 +421,7 @@ public void add(Node node) {
Node rack = getNodeForNetworkLocation(node);
if (rack != null && !(rack instanceof InnerNode)) {
LOG.error("Unexpected data node {} at an illegal network location", node);
throw new IllegalArgumentException("Unexpected data node " + node.toString()
throw new IllegalArgumentException("Unexpected data node " + node
+ " at an illegal network location");
}
if (clusterMap.add(node)) {
@@ -436,7 +436,7 @@ public void add(Node node) {
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("NetworkTopology became:\n" + this.toString());
LOG.debug("NetworkTopology became:\n" + this);
}
} finally {
netlock.writeLock().unlock();
@@ -507,7 +507,7 @@ public void remove(Node node) {
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("NetworkTopology became:\n" + this.toString());
LOG.debug("NetworkTopology became:\n" + this);
}
} finally {
netlock.writeLock().unlock();
@@ -210,8 +210,8 @@ public List<String> resolve(List<String> names) {

if (m.size() != names.size()) {
// invalid number of entries returned by the script
LOG.error("Script " + scriptName + " returned " + Integer.toString(m.size()) + " values when "
+ Integer.toString(names.size()) + " were expected.");
LOG.error("Script " + scriptName + " returned " + m.size() + " values when "
+ names.size() + " were expected.");
return null;
}
} else {
@@ -239,8 +239,8 @@ private String runResolveCommand(List<String> args) {
StringBuilder allOutput = new StringBuilder();
int numProcessed = 0;
if (maxArgs < MIN_ALLOWABLE_ARGS) {
LOG.warn("Invalid value " + Integer.toString(maxArgs) + " for " + SCRIPT_ARG_COUNT_KEY
+ "; must be >= " + Integer.toString(MIN_ALLOWABLE_ARGS));
LOG.warn("Invalid value " + maxArgs + " for " + SCRIPT_ARG_COUNT_KEY
+ "; must be >= " + MIN_ALLOWABLE_ARGS);
return null;
}

@@ -78,8 +78,7 @@ private SaslServer createSaslServer(final Subject subject, ServerConfiguration s

final String servicePrincipalNameAndHostname = servicePrincipal.getName();
int indexOf = servicePrincipalNameAndHostname.indexOf("/");
final String serviceHostnameAndKerbDomain = servicePrincipalNameAndHostname.substring(indexOf + 1,
servicePrincipalNameAndHostname.length());
final String serviceHostnameAndKerbDomain = servicePrincipalNameAndHostname.substring(indexOf + 1);
int indexOfAt = serviceHostnameAndKerbDomain.indexOf("@");

final String servicePrincipalName, serviceHostname;
@@ -162,7 +162,7 @@ public void run() {
LOG.info("refreshing now because expiry is before next scheduled refresh time.");
} else if (now < nextRefresh) {
Date until = new Date(nextRefresh);
LOG.info("TGT refresh sleeping until: {}", until.toString());
LOG.info("TGT refresh sleeping until: {}", until);
try {
Thread.sleep(nextRefresh - now);
} catch (InterruptedException ie) {
@@ -87,7 +87,7 @@ public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
});

response.setCode(HttpServer.StatusCode.OK);
response.setBody("Success send decommission Bookie command " + bookieSrc.toString());
response.setBody("Success send decommission Bookie command " + bookieSrc);
return response;
} catch (Exception e) {
LOG.error("Exception occurred while decommissioning bookie: ", e);
@@ -87,7 +87,7 @@ public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
hostname = resolved.getHostName();
}
output.putIfAbsent(b.toString(), hostname);
LOG.debug("bookie: " + b.toString() + " hostname:" + hostname);
LOG.debug("bookie: " + b + " hostname:" + hostname);
}
String jsonResponse = JsonUtil.toJson(output);

@@ -102,12 +102,12 @@ public boolean handler(ServerConfiguration conf, LBRDFlags flags)
try {
if (getter) {
int lostBookieRecoveryDelay = admin.getLostBookieRecoveryDelay();
LOG.info("LostBookieRecoveryDelay value in ZK: {}", String.valueOf(lostBookieRecoveryDelay));
LOG.info("LostBookieRecoveryDelay value in ZK: {}", lostBookieRecoveryDelay);
} else {
int lostBookieRecoveryDelay = flags.set;
admin.setLostBookieRecoveryDelay(lostBookieRecoveryDelay);
LOG.info("Successfully set LostBookieRecoveryDelay value in ZK: {}",
String.valueOf(lostBookieRecoveryDelay));
lostBookieRecoveryDelay);
}
} finally {
if (admin != null) {
@@ -246,21 +246,21 @@ public float checkDir(File dir) throws DiskErrorException,
float usage = checkDiskFull(dir);
if (!mkdirsWithExistsCheck(dir)) {
throw new DiskErrorException("can not create directory: "
+ dir.toString());
+ dir);
}

if (!dir.isDirectory()) {
throw new DiskErrorException("not a directory: " + dir.toString());
throw new DiskErrorException("not a directory: " + dir);
}

if (!dir.canRead()) {
throw new DiskErrorException("directory is not readable: "
+ dir.toString());
+ dir);
}

if (!dir.canWrite()) {
throw new DiskErrorException("directory is not writable: "
+ dir.toString());
+ dir);
}
return usage;
}
@@ -72,10 +72,10 @@ public static String getShortHierarchicalLedgerPath(long ledgerId) {
// do 2-4-4 split
StringBuilder sb = new StringBuilder();
sb.append("/")
.append(ledgerIdStr.substring(0, 2)).append("/")
.append(ledgerIdStr.substring(2, 6)).append("/")
.append(ledgerIdStr, 0, 2).append("/")
.append(ledgerIdStr, 2, 6).append("/")
.append(LEDGER_NODE_PREFIX)
.append(ledgerIdStr.substring(6, 10));
.append(ledgerIdStr, 6, 10);
return sb.toString();
}

@@ -91,12 +91,12 @@ public static String getLongHierarchicalLedgerPath(long ledgerId) {
// do 3-4-4-4-4 split
StringBuilder sb = new StringBuilder();
sb.append("/")
.append(ledgerIdStr.substring(0, 3)).append("/")
.append(ledgerIdStr.substring(3, 7)).append("/")
.append(ledgerIdStr.substring(7, 11)).append("/")
.append(ledgerIdStr.substring(11, 15)).append("/")
.append(ledgerIdStr, 0, 3).append("/")
.append(ledgerIdStr, 3, 7).append("/")
.append(ledgerIdStr, 7, 11).append("/")
.append(ledgerIdStr, 11, 15).append("/")
.append(LEDGER_NODE_PREFIX)
.append(ledgerIdStr.substring(15, 19));
.append(ledgerIdStr, 15, 19);
return sb.toString();
}

@@ -301,7 +301,7 @@ EntryIterator getIterator() {

void openWrite(long entryID) {
writesInProgress.add(entryID);
System.out.format("Open writes, %s%n", writesInProgress.toString());
System.out.format("Open writes, %s%n", writesInProgress);
}

void incReads() {
@@ -382,7 +382,7 @@ private void checkWriteComplete(Consumer<Integer> cb) {
System.out.format(
"checkWriteComplete: ledger %d, writesInProgress %s%n",
ledgerID,
writesInProgress.toString());
writesInProgress);
cb.accept(0);
}
}
@@ -396,7 +396,7 @@ private void checkOpComplete(Consumer<Integer> cb) {
System.out.format(
"checkOpComplete: ledger %d, writesInProgress %s, readsInProgress %d%n",
ledgerID,
writesInProgress.toString(), readsInProgress);
writesInProgress, readsInProgress);
cb.accept(0);
}
}
@@ -190,7 +190,7 @@ public void testConcurrency() throws Exception {
}
AllocBuffer other = treeMap.put(buf.alloc.getOffset(), buf);
if (other != null) {
fail("Buffer " + other.toString() + " overlapped with " + buf.toString());
fail("Buffer " + other + " overlapped with " + buf);
}
}
}
@@ -56,7 +56,7 @@ public PersistentEntryLogMetadataMapTest() {
@Test
public void simple() throws Exception {
File tmpDir = tempFolder.newFolder("metadata-cache");
String path = tmpDir.getAbsolutePath().toString();
String path = tmpDir.getAbsolutePath();
PersistentEntryLogMetadataMap entryMetadataMap = new PersistentEntryLogMetadataMap(path, configuration);

List<EntryLogMetadata> metadatas = Lists.newArrayList();
@@ -104,7 +104,7 @@ public void simple() throws Exception {
@Test
public void closeAndOpen() throws Exception {
File tmpDir = tempFolder.newFolder();
String path = tmpDir.getAbsolutePath().toString();
String path = tmpDir.getAbsolutePath();
PersistentEntryLogMetadataMap entryMetadataMap = new PersistentEntryLogMetadataMap(path, configuration);

List<EntryLogMetadata> metadatas = Lists.newArrayList();
@@ -70,7 +70,7 @@ void blockUntilBookieWeightIs(BookieId bookie, Optional<Long> target) throws Int
}
fail(String.format(
"Server %s still has weight %s rather than %s",
bookie.toString(), freeDiskSpace.toString(), target.toString()));
bookie.toString(), freeDiskSpace, target.toString()));
}
}

@@ -151,7 +151,7 @@ private void prepareReadBookieServiceInfo(BookieId address, boolean readonly) th
Code.NONODE.intValue(),
new byte[] {},
new Stat());
mockZkGetData(regReadonlyPath + "/" + address.toString(),
mockZkGetData(regReadonlyPath + "/" + address,
zkRegistrationClient.isBookieAddressTracking(),
Code.OK.intValue(),
new byte[] {},
@@ -162,7 +162,7 @@ private void prepareReadBookieServiceInfo(BookieId address, boolean readonly) th
Code.OK.intValue(),
new byte[] {},
new Stat());
mockZkGetData(regReadonlyPath + "/" + address.toString(),
mockZkGetData(regReadonlyPath + "/" + address,
zkRegistrationClient.isBookieAddressTracking(),
Code.NONODE.intValue(),
new byte[] {},

0 comments on commit 90d5501

Please sign in to comment.