Skip to content

Commit eb99124

Browse files
CURATOR-726: Improve tracing for MultiTransaction and GetChildren (#513)
1 parent ad19795 commit eb99124

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

curator-client/src/main/java/org/apache/curator/drivers/OperationTrace.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ public class OperationTrace {
3333

3434
private int returnCode = KeeperException.Code.OK.intValue();
3535
private long latencyMs;
36+
private int requestTransactionCount;
3637
private long requestBytesLength;
3738
private long responseBytesLength;
39+
private int responseChildrenCount = -1;
3840
private String path;
3941
private boolean withWatcher;
4042
private long sessionId;
@@ -57,6 +59,11 @@ public OperationTrace setReturnCode(int returnCode) {
5759
return this;
5860
}
5961

62+
public OperationTrace setRequestTransactionCount(int transactionCount) {
63+
this.requestTransactionCount = transactionCount;
64+
return this;
65+
}
66+
6067
public OperationTrace setRequestBytesLength(long length) {
6168
this.requestBytesLength = length;
6269
return this;
@@ -97,6 +104,11 @@ public OperationTrace setResponseBytesLength(byte[] data) {
97104
return this.setResponseBytesLength(data.length);
98105
}
99106

107+
public OperationTrace setResponseChildrenCount(int responseChildrenCount) {
108+
this.responseChildrenCount = responseChildrenCount;
109+
return this;
110+
}
111+
100112
public OperationTrace setPath(String path) {
101113
this.path = path;
102114
return this;
@@ -124,6 +136,10 @@ public long getLatencyMs() {
124136
return this.latencyMs;
125137
}
126138

139+
public int getRequestTransactionCount() {
140+
return this.requestTransactionCount;
141+
}
142+
127143
public long getRequestBytesLength() {
128144
return this.requestBytesLength;
129145
}
@@ -132,6 +148,10 @@ public long getResponseBytesLength() {
132148
return this.responseBytesLength;
133149
}
134150

151+
public int getResponseChildrenCount() {
152+
return this.responseChildrenCount;
153+
}
154+
135155
public long getSessionId() {
136156
return this.sessionId;
137157
}

curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorMultiTransactionImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.concurrent.Callable;
2727
import java.util.concurrent.Executor;
2828
import org.apache.curator.RetryLoop;
29-
import org.apache.curator.TimeTrace;
29+
import org.apache.curator.drivers.OperationTrace;
3030
import org.apache.curator.framework.api.BackgroundCallback;
3131
import org.apache.curator.framework.api.CuratorEvent;
3232
import org.apache.curator.framework.api.CuratorEventType;
@@ -160,11 +160,13 @@ public CuratorEventType getBackgroundEventType() {
160160
public void performBackgroundOperation(final OperationAndData<CuratorMultiTransactionRecord> operationAndData)
161161
throws Exception {
162162
try {
163-
final TimeTrace trace = client.getZookeeperClient().startTracer("CuratorMultiTransactionImpl-Background");
163+
final OperationTrace trace =
164+
client.getZookeeperClient().startAdvancedTracer("CuratorMultiTransactionImpl-Background");
164165
AsyncCallback.MultiCallback callback = new AsyncCallback.MultiCallback() {
165166
@Override
166167
public void processResult(int rc, String path, Object ctx, List<OpResult> opResults) {
167-
trace.commit();
168+
trace.setRequestTransactionCount(operationAndData.getData().size())
169+
.commit();
168170
List<CuratorTransactionResult> curatorResults = (opResults != null)
169171
? CuratorTransactionImpl.wrapResults(client, opResults, operationAndData.getData())
170172
: null;
@@ -192,15 +194,16 @@ public void processResult(int rc, String path, Object ctx, List<OpResult> opResu
192194

193195
private List<CuratorTransactionResult> forOperationsInForeground(final CuratorMultiTransactionRecord record)
194196
throws Exception {
195-
TimeTrace trace = client.getZookeeperClient().startTracer("CuratorMultiTransactionImpl-Foreground");
197+
OperationTrace trace =
198+
client.getZookeeperClient().startAdvancedTracer("CuratorMultiTransactionImpl-Foreground");
196199
List<OpResult> responseData =
197200
RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable<List<OpResult>>() {
198201
@Override
199202
public List<OpResult> call() throws Exception {
200203
return client.getZooKeeper().multi(record);
201204
}
202205
});
203-
trace.commit();
206+
trace.setRequestTransactionCount(record.size()).commit();
204207

205208
return CuratorTransactionImpl.wrapResults(client, responseData, record);
206209
}

curator-framework/src/main/java/org/apache/curator/framework/imps/GetChildrenBuilderImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,15 @@ public void performBackgroundOperation(final OperationAndData<String> operationA
165165
@Override
166166
public void processResult(int rc, String path, Object o, List<String> strings, Stat stat) {
167167
watching.commitWatcher(rc, false);
168+
if (strings == null) {
169+
strings = Lists.newArrayList();
170+
}
168171
trace.setReturnCode(rc)
169172
.setPath(path)
170173
.setWithWatcher(watching.hasWatcher())
171174
.setStat(stat)
175+
.setResponseChildrenCount(strings.size())
172176
.commit();
173-
if (strings == null) {
174-
strings = Lists.newArrayList();
175-
}
176177
CuratorEventImpl event = new CuratorEventImpl(
177178
client,
178179
CuratorEventType.CHILDREN,
@@ -241,6 +242,7 @@ public List<String> call() throws Exception {
241242
trace.setPath(path)
242243
.setWithWatcher(watching.hasWatcher())
243244
.setStat(responseStat)
245+
.setResponseChildrenCount(children != null ? children.size() : 0)
244246
.commit();
245247
return children;
246248
}

0 commit comments

Comments
 (0)