Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ public static MutationMetricQueue.MutationMetric updateMutationBatchFailureMetri
numUpsertMutationsInBatch,
allUpsertsMutations ? 1 : 0,
numDeleteMutationsInBatch,
allDeletesMutations ? 1 : 0, 0);
allDeletesMutations ? 1 : 0, 0, 0, 0, 0, 0, 0, 0);
}

/**
Expand Down Expand Up @@ -1807,7 +1807,7 @@ static MutationMetric getCommittedMutationsMetric(
committedDeleteMutationCounter,
committedTotalMutationBytes,
numFailedPhase3Mutations,
0, 0, 0, 0, mutationBatchCounter);
0, 0, 0, 0, mutationBatchCounter, 0, 0, 0, 0, 0, 0);
}

private void filterIndexCheckerMutations(Map<TableInfo, List<Mutation>> mutationMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.apache.phoenix.monitoring.MetricType.UPSERT_SQL_COUNTER;
import static org.apache.phoenix.monitoring.MetricType.UPSERT_SQL_QUERY_TIME;
import static org.apache.phoenix.monitoring.MetricType.UPSERT_SUCCESS_SQL_COUNTER;
import static org.apache.phoenix.monitoring.MutationMetricQueue.MutationMetric;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -221,6 +222,7 @@
import org.apache.phoenix.util.ClientUtil;
import org.apache.phoenix.util.CDCUtil;
import org.apache.phoenix.util.CursorUtil;
import org.apache.phoenix.util.EnvironmentEdge;
import org.apache.phoenix.util.PhoenixKeyValueUtil;
import org.apache.phoenix.util.EnvironmentEdgeManager;
import org.apache.phoenix.util.LogUtil;
Expand Down Expand Up @@ -606,15 +608,17 @@ private Pair<Integer, ResultSet> executeMutation(final CompilableStatement stmt,
new CallRunner.CallableThrowable<Pair<Integer, ResultSet>, SQLException>() {
@Override
public Pair<Integer, ResultSet> call() throws SQLException {
final long startExecuteMutationTime = EnvironmentEdgeManager.timeMarkerInNanos();
boolean success = false;
String tableName = null;
boolean isUpsert = false;
boolean isAtomicUpsert = false;
boolean isDelete = false;
MutationState state = null;
MutationPlan plan = null;
final long startExecuteMutationTime = EnvironmentEdgeManager.currentTimeMillis();
clearResultSet();
long mutationPlanCreationTimeInNs = 0;
long mutationPlanExecutionTimeInNs = 0;
try {
PhoenixConnection conn = getConnection();
if (conn.getQueryServices().isUpgradeRequired() && !conn.isRunningUpgrade()
Expand All @@ -624,6 +628,7 @@ public Pair<Integer, ResultSet> call() throws SQLException {
state = connection.getMutationState();
isUpsert = stmt instanceof ExecutableUpsertStatement;
isDelete = stmt instanceof ExecutableDeleteStatement;
long mutationPlanCreationStartTimeMarker = EnvironmentEdgeManager.timeMarkerInNanos();
if (isDelete && connection.getAutoCommit() &&
returnResult == ReturnResult.ROW) {
// used only if single row deletion needs to atomically
Expand All @@ -635,6 +640,8 @@ public Pair<Integer, ResultSet> call() throws SQLException {
plan = stmt.compilePlan(PhoenixStatement.this,
Sequence.ValueOp.VALIDATE_SEQUENCE);
}
mutationPlanCreationTimeInNs = EnvironmentEdgeManager.timeMarkerInNanos() -
mutationPlanCreationStartTimeMarker;
isAtomicUpsert = isUpsert && ((ExecutableUpsertStatement)stmt).getOnDupKeyPairs() != null;
if (plan.getTargetRef() != null && plan.getTargetRef().getTable() != null) {
if (!Strings.isNullOrEmpty(plan.getTargetRef().getTable().getPhysicalName().toString())) {
Expand All @@ -648,7 +655,10 @@ public Pair<Integer, ResultSet> call() throws SQLException {
state.sendUncommitted(tableRefs);
state.checkpointIfNeccessary(plan);
checkIfDDLStatementandMutationState(stmt, state);
long mutationPlanExecutionStartTimeMarker = EnvironmentEdgeManager.timeMarkerInNanos();
MutationState lastState = plan.execute();
mutationPlanExecutionTimeInNs = EnvironmentEdgeManager.timeMarkerInNanos() -
mutationPlanExecutionStartTimeMarker;
state.join(lastState);
// Unfortunately, JDBC uses an int for update count, so we
// just max out at Integer.MAX_VALUE
Expand Down Expand Up @@ -718,8 +728,10 @@ public Pair<Integer, ResultSet> call() throws SQLException {
MUTATION_SQL_COUNTER, 1);
// Only count dml operations
if (isUpsert || isDelete) {
long executeMutationTimeSpent =
EnvironmentEdgeManager.currentTimeMillis() - startExecuteMutationTime;
long executeMutationTimeSpentInNs =
EnvironmentEdgeManager.timeMarkerInNanos() - startExecuteMutationTime;
// This will ensure existing use cases of metrics are not broken.
long executeMutationTimeSpent = EnvironmentEdge.convertTimeInNsToMs(executeMutationTimeSpentInNs);

TableMetricsManager.updateMetricsMethod(tableName, isUpsert ?
UPSERT_SQL_COUNTER : DELETE_SQL_COUNTER, 1);
Expand All @@ -731,6 +743,22 @@ public Pair<Integer, ResultSet> call() throws SQLException {
TableMetricsManager.updateMetricsMethod(tableName,
ATOMIC_UPSERT_SQL_QUERY_TIME, executeMutationTimeSpent);
}
MutationMetric stagedMutationMetric;
if (isUpsert) {
stagedMutationMetric = getUncommittedMutationMetric(
mutationPlanCreationTimeInNs,
mutationPlanExecutionTimeInNs, 0, 0,
executeMutationTimeSpentInNs, 0);
}
else {
stagedMutationMetric = getUncommittedMutationMetric(
0, 0,
mutationPlanCreationTimeInNs,
mutationPlanExecutionTimeInNs, 0,
executeMutationTimeSpentInNs);
}
state.getMutationMetricQueue().addMetricsForTable(
tableName, stagedMutationMetric);

if (success) {
TableMetricsManager.updateMetricsMethod(tableName, isUpsert ?
Expand All @@ -753,6 +781,7 @@ public Pair<Integer, ResultSet> call() throws SQLException {
state.addExecuteMutationTime(
executeMutationTimeSpent, tableName);
}

}
}

Expand All @@ -773,6 +802,26 @@ public Pair<Integer, ResultSet> call() throws SQLException {
}
}

/**
* Get mutation metrics for executeMutation call i.e. before the mutation are committed.
* All the times are in nano seconds.
* @param upsertMutationPlanCreationTime Time taken to create the upsert mutation plan.
* @param upsertMutationPlanExecutionTime Time taken to execute the upsert mutation plan.
* @param deleteMutationPlanCreationTime Time taken to create the delete mutation plan.
* @param deleteMutationPlanExecutionTime Time taken to execute the delete mutation plan.
* @param upsertExecuteMutationTime Time taken by upsert in executeMutation call.
* @param deleteExecuteMutationTime Time taken by delete in executeMutation call.
* @return MutationMetric object.
*/
private MutationMetric getUncommittedMutationMetric(long upsertMutationPlanCreationTime, long upsertMutationPlanExecutionTime,
long deleteMutationPlanCreationTime, long deleteMutationPlanExecutionTime,
long upsertExecuteMutationTime, long deleteExecuteMutationTime) {
return new MutationMetric(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
upsertMutationPlanCreationTime, upsertMutationPlanExecutionTime,
deleteMutationPlanCreationTime, deleteMutationPlanExecutionTime,
upsertExecuteMutationTime, deleteExecuteMutationTime);
}

/**
* Get different Result if the row is atomically deleted.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public enum MetricType {
DELETE_BATCH_FAILED_COUNTER("dbfc", "Number of delete mutation batches that failed to be committed",
LogLevel.OFF, PLong.INSTANCE),

UPSERT_PLAN_CREATION_TIME("upct", "Time taken to create the upsert mutation plan in ns",
LogLevel.OFF, PLong.INSTANCE),
UPSERT_PLAN_EXECUTION_TIME("upet", "Time taken to execute the upsert mutation plan in ns",
LogLevel.OFF, PLong.INSTANCE),
UPSERT_EXECUTE_MUTATION_TIME("uemt", "Time taken by upsert in executeMutation in ns",
LogLevel.OFF, PLong.INSTANCE),
DELETE_PLAN_CREATION_TIME("dpct", "Time taken to create the delete mutation plan in ns",
LogLevel.OFF, PLong.INSTANCE),
DELETE_PLAN_EXECUTION_TIME("dpet", "Time taken to execute the delete mutation plan in ns",
LogLevel.OFF, PLong.INSTANCE),
DELETE_EXECUTE_MUTATION_TIME("demt", "Time taken by delete in executeMutation in ns",
LogLevel.OFF, PLong.INSTANCE),
MUTATION_BATCH_COUNTER("mbc", "Number of mutation batches committed "
+ "in a commit call", LogLevel.OFF, PLong.INSTANCE),

Expand Down
Loading