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 @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
Expand Down Expand Up @@ -402,15 +403,17 @@ public static class ValueHider {
private static final String PLACEHOLDER = "******";

static {
KEYS.add("ssl.key-store-pwd");
KEYS.add("ssl.trust-store-pwd");
KEYS.add("password");
}

public static boolean isHiddenKey(final String key) {
return Objects.nonNull(key) && KEYS.contains(KeyReducer.reduce(key).toLowerCase(Locale.ROOT));
}

static String hide(final String key, final String value) {
if (Objects.isNull(key)) {
return value;
}
if (KEYS.contains(KeyReducer.reduce(key))) {
if (isHiddenKey(key)) {
return PLACEHOLDER;
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,27 @@
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;

public class PipeSinkSubtask extends PipeAbstractSinkSubtask {

private static final Logger LOGGER = LoggerFactory.getLogger(PipeSinkSubtask.class);
public static final String SINK_METRIC_NAME = "sink";
public static final String METRIC_TAG_NO_PIPE = "none";
public static final String METRIC_TAG_SHARED_REGION = "shared";
private static final AtomicLong NEXT_DISPLAY_ID = new AtomicLong();

// For input
protected final UnboundedBlockingPendingQueue<Event> inputPendingQueue;

// Record these variables to provide corresponding value to tag key of monitoring metrics
private final String pipeName;
private final String attributeSortedString;
private final String attributeDisplayString;
private final String metricName;
private final Integer metricRegionId;
private final long displayId;
private final int connectorIndex;
private final boolean isExternalSink;

Expand All @@ -92,6 +100,9 @@ public PipeSinkSubtask(
taskID,
creationTime,
attributeSortedString,
SINK_METRIC_NAME,
SINK_METRIC_NAME,
null,
connectorIndex,
inputPendingQueue,
outputPipeConnector,
Expand All @@ -111,6 +122,54 @@ public PipeSinkSubtask(
taskID,
creationTime,
attributeSortedString,
SINK_METRIC_NAME,
SINK_METRIC_NAME,
null,
connectorIndex,
inputPendingQueue,
outputPipeConnector,
true);
}

public PipeSinkSubtask(
final String taskID,
final long creationTime,
final String attributeSortedString,
final String attributeDisplayString,
final int connectorIndex,
final UnboundedBlockingPendingQueue<Event> inputPendingQueue,
final PipeConnector outputPipeConnector) {
this(
null,
taskID,
creationTime,
attributeSortedString,
attributeDisplayString,
SINK_METRIC_NAME,
null,
connectorIndex,
inputPendingQueue,
outputPipeConnector,
true);
}

public PipeSinkSubtask(
final String pipeName,
final String taskID,
final long creationTime,
final String attributeSortedString,
final String attributeDisplayString,
final int connectorIndex,
final UnboundedBlockingPendingQueue<Event> inputPendingQueue,
final PipeConnector outputPipeConnector) {
this(
pipeName,
taskID,
creationTime,
attributeSortedString,
attributeDisplayString,
SINK_METRIC_NAME,
null,
connectorIndex,
inputPendingQueue,
outputPipeConnector,
Expand All @@ -126,9 +185,39 @@ public PipeSinkSubtask(
final UnboundedBlockingPendingQueue<Event> inputPendingQueue,
final PipeConnector outputPipeConnector,
final boolean isExternalSink) {
this(
pipeName,
taskID,
creationTime,
attributeSortedString,
SINK_METRIC_NAME,
SINK_METRIC_NAME,
null,
connectorIndex,
inputPendingQueue,
outputPipeConnector,
isExternalSink);
}

protected PipeSinkSubtask(
final String pipeName,
final String taskID,
final long creationTime,
final String attributeSortedString,
final String attributeDisplayString,
final String metricName,
final Integer metricRegionId,
final int connectorIndex,
final UnboundedBlockingPendingQueue<Event> inputPendingQueue,
final PipeConnector outputPipeConnector,
final boolean isExternalSink) {
super(taskID, creationTime, outputPipeConnector);
this.pipeName = pipeName;
this.attributeSortedString = attributeSortedString;
this.attributeDisplayString = attributeDisplayString;
this.metricName = metricName;
this.metricRegionId = metricRegionId;
this.displayId = NEXT_DISPLAY_ID.getAndIncrement();
this.connectorIndex = connectorIndex;
this.isExternalSink = isExternalSink;
this.inputPendingQueue = inputPendingQueue;
Expand Down Expand Up @@ -222,7 +311,7 @@ private void transferHeartbeatEvent(final PipeHeartbeatEvent event) {
"PipeConnector: "
+ outputPipeConnector.getClass().getName()
+ "(id: "
+ taskID
+ getDisplayTaskID()
+ ")"
+ " heartbeat failed, or encountered failure when transferring generic event. Failure: "
+ e.getMessage(),
Expand Down Expand Up @@ -269,7 +358,7 @@ private void discardPendingEventsOfPipeUnderLock() {
LOGGER.warn(
"Failed to discard events of pipe {} in connector subtask {}.",
committerKey.getPipeName(),
taskID,
getDisplayTaskID(),
e);
}
}
Expand All @@ -295,14 +384,14 @@ public void close() {
if (closeOutputPipeConnector()) {
LOGGER.info(
"Pipe: connector subtask {} ({}) was closed within {} ms",
taskID,
getDisplayTaskID(),
outputPipeConnector,
System.currentTimeMillis() - startTime);
}
} catch (final Exception e) {
LOGGER.info(
"Exception occurred when closing pipe connector subtask {}, root cause: {}",
taskID,
getDisplayTaskID(),
ErrorHandlingCommonUtils.getRootCause(e).getMessage(),
e);
} finally {
Expand Down Expand Up @@ -341,7 +430,7 @@ private boolean closeOutputPipeConnector() throws Exception {
outputPipeConnectorOperationLock.unlock();
}
},
"PipeSinkSubtaskClose-" + taskID);
"PipeSinkSubtaskClose-" + getDisplayTaskID());
closeThread.setDaemon(true);
closeThread.start();

Expand All @@ -362,7 +451,7 @@ private boolean closeOutputPipeConnector() throws Exception {
LOGGER.warn(
"Pipe sink subtask close timed out after {} ms for {}, close operation {}.",
timeoutInMs,
taskID,
getDisplayTaskID(),
closeStarted.get() ? "is still running" : "will run after current connector operation");
return false;
}
Expand Down Expand Up @@ -463,6 +552,18 @@ public String getAttributeSortedString() {
return attributeSortedString;
}

public String getAttributeDisplayString() {
return attributeDisplayString;
}

public String getMetricName() {
return metricName;
}

public Integer getMetricRegionId() {
return metricRegionId;
}

public int getConnectorIndex() {
return connectorIndex;
}
Expand Down Expand Up @@ -583,4 +684,17 @@ protected void reportResourceFailure(
PipeDataNodeAgent.task()
.recordPipeResourceFailure(event.getPipeName(), event.getCreationTime(), failureType);
}

@Override
public String getDisplayTaskID() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/sink/PipeSinkSubtask.java:688 — getDisplayTaskID() is never wired into error output; new test fails and raw taskID still leaks attributes

PipeSinkSubtask.getDisplayTaskID() is dead code: PipeAbstractSinkSubtask.handleException (line 370) and transferHeartbeatEvent still format the raw taskID, which embeds attributeSortedString (e.g. sink.password=..., sink.token=...). testTransferExceptionUsesDisplayTaskID (PipeSinkSubtaskTest:187) asserts the message contains "Exception in pipe transfer, subtask: sink_", so it fails at head while credentials remain in pipe exception messages.

Fix: Backport the node-commons part: add an overridable getDisplayTaskID() on PipeAbstractSinkSubtask and use it in handleException and transferHeartbeatEvent instead of taskID.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed. PipeAbstractSinkSubtask.handleException() uses getDisplayTaskID(), and heartbeat connector failures now use the same sanitized ID. Added testHeartbeatTransferExceptionUsesDisplayTaskID, which checks the exception cause chain; the focused suite passes (23 tests).

final String displayName = pipeName == null ? metricName : pipeName;
final String region = metricRegionId == null ? "" : "_region_" + metricRegionId;
return generateDisplayTaskID(
displayName + region + "_" + displayId, creationTime, connectorIndex);
}

static String generateDisplayTaskID(
final String attributeDisplayString, final long creationTime, final int connectorIndex) {
return String.format("%s_%s_%s", attributeDisplayString, creationTime, connectorIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public synchronized String register(
boolean realTimeFirst = false;
final String attributeSortedString =
generateAttributeSortedString(pipeSinkParameters, environment.getRegionId());
final String attributeDisplayStringWithPrefix =
generateAttributeDisplayString(pipeSinkParameters, environment.getRegionId());
final Integer metricRegionId =
isDataRegionSink && PipeSinkConstant.isSerializeByRegionEnabled(pipeSinkParameters)
? environment.getRegionId()
: null;
if (isDataRegionSink) {
realTimeFirst =
pipeSinkParameters.getBooleanOrDefault(
Expand Down Expand Up @@ -152,6 +158,9 @@ public synchronized String register(
taskID,
environment.getCreationTime(),
attributeSortedString,
attributeDisplayStringWithPrefix,
PipeSinkSubtask.SINK_METRIC_NAME,
metricRegionId,
connectorIndex,
pendingQueue,
pipeConnector,
Expand All @@ -162,8 +171,8 @@ public synchronized String register(
}

LOGGER.info(
"Pipe connector subtasks with attributes {} is bounded with connectorExecutor {} and callbackExecutor {}.",
attributeSortedString,
"Pipe sink subtasks of type {} are bounded with sinkExecutor {} and callbackExecutor {}.",
PipeSinkSubtask.SINK_METRIC_NAME,
executor.getWorkingThreadName(),
executor.getCallbackThreadName());
pipeSinkSubtaskKey2SubtaskLifeCycleMap.put(pipeSinkSubtaskKey, pipeSinkSubtaskLifeCycleList);
Expand Down Expand Up @@ -281,7 +290,7 @@ public synchronized UnboundedBlockingPendingQueue<Event> getPipeSinkPendingQueue
new PipeSinkSubtaskKey(pipeName, creationTime, attributeSortedString);
if (!pipeSinkSubtaskKey2SubtaskLifeCycleMap.containsKey(pipeSinkSubtaskKey)) {
throw new PipeException(
"Failed to get PendingQueue. No such subtask: " + attributeSortedString);
"Failed to get PendingQueue. No such subtask: " + PipeSinkSubtask.SINK_METRIC_NAME);
}

return pipeSinkSubtaskKey2SubtaskLifeCycleMap.get(pipeSinkSubtaskKey).get(0).getPendingQueue();
Expand All @@ -298,7 +307,7 @@ public UnboundedBlockingPendingQueue<Event> getPipeSinkPendingQueue(
getUniquePipeSinkSubtaskKey(attributeSortedString);
if (pipeSinkSubtaskKey == null) {
throw new PipeException(
"Failed to get PendingQueue. No such subtask: " + attributeSortedString);
"Failed to get PendingQueue. No such subtask: " + PipeSinkSubtask.SINK_METRIC_NAME);
}

// All subtasks share the same pending queue
Expand Down Expand Up @@ -381,9 +390,28 @@ private static String generateAttributeSortedString(
return sortedStringSourceMap.toString();
}

static String generateAttributeDisplayString(final PipeParameters pipeConnectorParameters) {
final TreeMap<String, String> filteredAttributes =
new TreeMap<>(pipeConnectorParameters.getAttribute());
filteredAttributes.remove(SystemConstant.RESTART_OR_NEWLY_ADDED_KEY);
filteredAttributes.keySet().removeIf(PipeParameters.ValueHider::isHiddenKey);
return filteredAttributes.toString();
}

private static String generateAttributeDisplayString(
final PipeParameters pipeConnectorParameters, final int regionId) {
final String attributeDisplayString = generateAttributeDisplayString(pipeConnectorParameters);
if (!isDataRegionSink(regionId)) {
return "schema_" + attributeDisplayString;
}
return PipeSinkConstant.isSerializeByRegionEnabled(pipeConnectorParameters)
? "data_region_" + regionId + "_" + attributeDisplayString
: "data_" + attributeDisplayString;
}

private void throwNoSuchSubtaskException(final PipeSinkSubtaskKey pipeSinkSubtaskKey) {
throw new PipeException(
FAILED_TO_DEREGISTER_EXCEPTION_MESSAGE + pipeSinkSubtaskKey.attributeSortedString);
FAILED_TO_DEREGISTER_EXCEPTION_MESSAGE + PipeSinkSubtask.SINK_METRIC_NAME);
}

private PipeSinkSubtaskKey getUniquePipeSinkSubtaskKey(final String attributeSortedString) {
Expand Down
Loading
Loading