use of org.apache.beam.sdk.io.gcp.spanner.changestreams.ChangeStreamMetrics.PARTITION_ID_ATTRIBUTE_LABEL in project beam by apache.
the class ChildPartitionsRecordAction method processChildPartition.
// Unboxing of runInTransaction result will not produce a null value, we can ignore it
@SuppressWarnings("nullness")
private void processChildPartition(PartitionMetadata partition, ChildPartitionsRecord record, ChildPartition childPartition) {
try (Scope scope = TRACER.spanBuilder("ChildPartitionsRecordAction.processChildPartition").setRecordEvents(true).startScopedSpan()) {
TRACER.getCurrentSpan().putAttribute(PARTITION_ID_ATTRIBUTE_LABEL, AttributeValue.stringAttributeValue(partition.getPartitionToken()));
final String partitionToken = partition.getPartitionToken();
final String childPartitionToken = childPartition.getToken();
final boolean isSplit = isSplit(childPartition);
LOG.debug("[" + partitionToken + "] Processing child partition" + (isSplit ? " split" : " merge") + " event");
final PartitionMetadata row = toPartitionMetadata(record.getStartTimestamp(), partition.getEndTimestamp(), partition.getHeartbeatMillis(), childPartition);
LOG.debug("[" + partitionToken + "] Inserting child partition token " + childPartitionToken);
final Boolean insertedRow = partitionMetadataDao.runInTransaction(transaction -> {
if (transaction.getPartition(childPartitionToken) == null) {
transaction.insert(row);
return true;
} else {
return false;
}
}).getResult();
if (insertedRow && isSplit) {
metrics.incPartitionRecordSplitCount();
} else if (insertedRow) {
metrics.incPartitionRecordMergeCount();
} else {
LOG.debug("[" + partitionToken + "] Child token " + childPartitionToken + " already exists, skipping...");
}
}
}
Aggregations