Skip to content

Commit

Permalink
[FLINK-11744][core]Provide stable/final toHexString-method in AbstractID
Browse files Browse the repository at this point in the history
This closes apache#7825.
  • Loading branch information
StefanRRichter committed Feb 26, 2019
1 parent c7fb80f commit 435807e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
28 changes: 18 additions & 10 deletions flink-core/src/main/java/org/apache/flink/util/AbstractID.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class AbstractID implements Comparable<AbstractID>, java.io.Serializable
protected final long lowerPart;

/** The memoized value returned by toString(). */
private transient String toString;
private transient String hexString;

// --------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -127,6 +127,22 @@ public byte[] getBytes() {
return bytes;
}

/**
* Returns pure String representation of the ID in hexadecimal. This method should be used to construct things like
* paths etc., that require a stable representation and is therefore final.
*/
public final String toHexString() {
if (this.hexString == null) {
final byte[] ba = new byte[SIZE];
longToByteArray(this.lowerPart, ba, 0);
longToByteArray(this.upperPart, ba, SIZE_OF_LONG);

this.hexString = StringUtils.byteToHexString(ba);
}

return this.hexString;
}

// --------------------------------------------------------------------------------------------
// Standard Utilities
// --------------------------------------------------------------------------------------------
Expand All @@ -153,15 +169,7 @@ public int hashCode() {

@Override
public String toString() {
if (this.toString == null) {
final byte[] ba = new byte[SIZE];
longToByteArray(this.lowerPart, ba, 0);
longToByteArray(this.upperPart, ba, SIZE_OF_LONG);

this.toString = StringUtils.byteToHexString(ba);
}

return this.toString;
return toHexString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public TaskLocalStateStore localStateStoreForSubtask(

if (LOG.isDebugEnabled()) {
LOG.debug("Registered new allocation id {} for local state stores for job {}.",
allocationID, jobId);
allocationID.toHexString(), jobId);
}
}

Expand Down Expand Up @@ -232,7 +232,7 @@ File[] getLocalStateRootDirectories() {

@VisibleForTesting
String allocationSubDirString(AllocationID allocationID) {
return "aid_" + allocationID;
return "aid_" + allocationID.toHexString();
}

private File[] allocationBaseDirectories(AllocationID allocationID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public String toString() {
return "TaskLocalStateStore{" +
"jobID=" + jobID +
", jobVertexID=" + jobVertexID +
", allocationID=" + allocationID +
", allocationID=" + allocationID.toHexString() +
", subtaskIndex=" + subtaskIndex +
", localRecoveryConfig=" + localRecoveryConfig +
", storedCheckpointIDs=" + storedTaskStateByCheckpointID.keySet() +
Expand Down

0 comments on commit 435807e

Please sign in to comment.