Skip to content

Commit

Permalink
Add TransactionStatus to Latency samples
Browse files Browse the repository at this point in the history
  • Loading branch information
poojanilangekar committed Aug 14, 2024
1 parent a90e943 commit 75801ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
17 changes: 12 additions & 5 deletions src/main/java/com/oltpbenchmark/LatencyRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public LatencyRecord(long startNanosecond) {

}

public void addLatency(int transType, long startNanosecond, long endNanosecond, int workerId, int phaseId) {

public void addLatency(int transType, long startNanosecond, long endNanosecond, int workerId, int phaseId,
int transactionStatus) {

if (nextIndex == ALLOC_SIZE) {
allocateChunk();
Expand All @@ -61,8 +61,8 @@ public void addLatency(int transType, long startNanosecond, long endNanosecond,

int latencyMicroseconds = (int) ((endNanosecond - startNanosecond + 500) / 1000);


chunk[nextIndex] = new Sample(transType, startOffsetNanosecond, latencyMicroseconds, workerId, phaseId);
chunk[nextIndex] = new Sample(transType, startOffsetNanosecond, latencyMicroseconds, workerId, phaseId,
transactionStatus);
++nextIndex;

lastNanosecond += startOffsetNanosecond;
Expand Down Expand Up @@ -94,13 +94,16 @@ public static final class Sample implements Comparable<Sample> {
private final int latencyMicrosecond;
private final int workerId;
private final int phaseId;
private final int transactionStatus;

public Sample(int transactionType, long startNanosecond, int latencyMicrosecond, int workerId, int phaseId) {
public Sample(int transactionType, long startNanosecond, int latencyMicrosecond, int workerId, int phaseId,
int transactionStatus) {
this.transactionType = transactionType;
this.startNanosecond = startNanosecond;
this.latencyMicrosecond = latencyMicrosecond;
this.workerId = workerId;
this.phaseId = phaseId;
this.transactionStatus = transactionStatus;
}

public int getTransactionType() {
Expand All @@ -123,6 +126,10 @@ public int getPhaseId() {
return phaseId;
}

public int getTransactionStatus() {
return transactionStatus;
}

@Override
public int compareTo(Sample other) {
long diff = this.startNanosecond - other.startNanosecond;
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/oltpbenchmark/api/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ public final void run() {
break;
}
if (preState == MEASURE && postPhase.getId() == prePhase.getId()) {
latencies.addLatency(transactionType.getId(), start, end, this.id, prePhase.getId());
latencies.addLatency(transactionType.getId(), start, end, this.id, prePhase.getId(),
status.ordinal());
intervalRequests.incrementAndGet();

PrometheusMetrics.TXN_DURATION.labels(this.benchmark.getBenchmarkName(),
Expand Down Expand Up @@ -476,7 +477,7 @@ protected final TransactionStatus doWork(DatabaseType databaseType, TransactionT
String message = String.format(
"Retryable SQLException occurred during [%s]... current retry attempt [%d], max retry attempts [%d], sql state [%s], error code [%d].",
transactionType, retryCount, maxRetryCount, ex.getSQLState(), ex.getErrorCode());

if (logRetries) {
LOG.warn(message + " " + ex.getMessage());
} else {
Expand All @@ -485,17 +486,18 @@ protected final TransactionStatus doWork(DatabaseType databaseType, TransactionT

status = TransactionStatus.RETRY;
retryCount++;

if (this.workloadState.getGlobalState() == State.MEASURE) {
errors.addError(ex.getMessage(), parseError(transactionType, ex, retryCount < maxRetryCount));
errors.addError(ex.getMessage(),
parseError(transactionType, ex, retryCount < maxRetryCount));
}
} else {
LOG.warn(
"SQLException occurred during [{}] and will not be retried. sql state [{}], error code [{}]. {}",
transactionType, ex.getSQLState(), ex.getErrorCode(), ex.getMessage());

status = TransactionStatus.ERROR;

if (this.workloadState.getGlobalState() == State.MEASURE) {
errors.addError(ex.getMessage(), parseError(transactionType, ex, false));
}
Expand All @@ -513,7 +515,7 @@ protected final TransactionStatus doWork(DatabaseType databaseType, TransactionT
}
}

if (this.workloadState.getGlobalState() == State.MEASURE) {
if (this.workloadState.getGlobalState() == State.MEASURE) {
switch (status) {
case UNKNOWN -> this.txnUnknown.put(transactionType);
case SUCCESS -> this.txnSuccess.put(transactionType);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/oltpbenchmark/util/ResultWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.oltpbenchmark.api.collectors.DBParameterCollector;
import com.oltpbenchmark.api.collectors.DBParameterCollectorGen;
import com.oltpbenchmark.types.DatabaseType;
import com.oltpbenchmark.types.TransactionStatus;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.configuration2.XMLConfiguration;
import org.apache.commons.configuration2.ex.ConfigurationException;
Expand Down Expand Up @@ -212,7 +214,8 @@ public void writeRaw(List<TransactionType> activeTXTypes, PrintStream out) {
"Start Time (microseconds)",
"Latency (microseconds)",
"Worker Id (start number)",
"Phase Id (index in config file)"
"Phase Id (index in config file)",
"Transaction Status"
};
out.println(StringUtil.join(",", header));
for (LatencyRecord.Sample s : results.getLatencySamples()) {
Expand All @@ -226,6 +229,7 @@ public void writeRaw(List<TransactionType> activeTXTypes, PrintStream out) {
Integer.toString(s.getLatencyMicrosecond()),
Integer.toString(s.getWorkerId()),
Integer.toString(s.getPhaseId()),
TransactionStatus.values()[s.getTransactionStatus()].toString(),
};
out.println(StringUtil.join(",", row));
}
Expand Down

0 comments on commit 75801ac

Please sign in to comment.