Skip to content

Commit

Permalink
Hold LeafSpanIdInfo into MtContextThreadLocal transferInfo, fix LeafS…
Browse files Browse the repository at this point in the history
…panIdInfo GCed unexpectedly #53
  • Loading branch information
oldratlee committed Dec 7, 2015
1 parent 6565c5a commit 4e5b0a5
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ public Thread newThread(Runnable r) {
static class DtTransferInfo {
public String traceId;
public String baseSpanId;
public LeafSpanIdInfo leafSpanIdInfo;

public DtTransferInfo(String traceId, String baseSpanId) {
public DtTransferInfo(String traceId, String baseSpanId, LeafSpanIdInfo leafSpanIdInfo) {
this.traceId = traceId;
this.baseSpanId = baseSpanId;
this.leafSpanIdInfo = leafSpanIdInfo;
}

@Override
public String toString() {
return "DtTransferInfo{" +
"traceId='" + traceId + '\'' +
", baseSpanId='" + baseSpanId + '\'' +
", leafSpanIdInfo=" + leafSpanIdInfo +
'}';
}
}

Expand All @@ -63,9 +74,9 @@ public String toString() {
@Override
public void onRemoval(RemovalNotification<String, LeafSpanIdInfo> notification) {
if (notification.getCause() != RemovalCause.COLLECTED) {
System.err.println("Bug!! Should COLLECTED");
System.err.println("ERROR: Bug!! Should COLLECTED");
}
System.out.printf("DEBUG: Remove traceId %s in thread %s by cause %s: %s\n",
System.out.printf("ERROR: Remove traceId %s in thread %s by cause %s: %s\n",
notification.getKey(), Thread.currentThread().getName(), notification.getCause(), notification.getValue());
}
}).build();
Expand Down Expand Up @@ -102,9 +113,9 @@ static void rpcInvokeIn() {
String traceId = "traceId_XXXYYY" + traceIdCounter.getAndIncrement();
String baseSpanId = "1.1";

transferInfo.set(new DtTransferInfo(traceId, baseSpanId));
LeafSpanIdInfo leafSpanIdInfo = new LeafSpanIdInfo();
traceId2LeafSpanIdInfo.put(traceId, leafSpanIdInfo);
transferInfo.set(new DtTransferInfo(traceId, baseSpanId, leafSpanIdInfo));


////////////////////////////////////////////////
Expand Down

0 comments on commit 4e5b0a5

Please sign in to comment.