Skip to content
Draft
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 @@ -661,6 +661,78 @@ public void testHistoryAndRealtime() throws Exception {
}
}

@Test
public void testSkipOnFailedCloseParameterForTsFileEvents() throws Exception {
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);
final String database = "root.pipe_skip_on_failed_close";
final String pipeName = "pipe_skip_on_failed_close";

TestUtils.executeNonQueries(
senderEnv,
Arrays.asList(
"create database " + database,
"create timeseries " + database + ".d1.s1 with datatype=INT64,encoding=PLAIN",
"insert into " + database + ".d1 (time, s1) values (1, 10)",
"flush"),
null);

final Map<String, String> sourceAttributes = new HashMap<>();
final Map<String, String> processorAttributes = new HashMap<>();
final Map<String, String> sinkAttributes = new HashMap<>();

sourceAttributes.put("source.inclusion", "data.insert");
sourceAttributes.put("source.pattern", database + ".**");
sourceAttributes.put("source.history.enable", "true");
sourceAttributes.put("source.realtime.enable", "true");
sourceAttributes.put("source.realtime.mode", "batch");
sourceAttributes.put("source.skip-on-failed-close", "true");
sourceAttributes.put("user", "root");

sinkAttributes.put("sink", "iotdb-thrift-sink");
sinkAttributes.put("sink.batch.enable", "false");
sinkAttributes.put("sink.ip", receiverDataNode.getIp());
sinkAttributes.put("sink.port", Integer.toString(receiverDataNode.getPort()));

try (final SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
final TSStatus status =
client.createPipe(
new TCreatePipeReq(pipeName, sinkAttributes)
.setExtractorAttributes(sourceAttributes)
.setProcessorAttributes(processorAttributes));
Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
Assert.assertEquals(
TSStatusCode.SUCCESS_STATUS.getStatusCode(), client.startPipe(pipeName).getCode());

final TShowPipeInfo pipeInfo =
client
.showPipe(new TShowPipeReq().setUserName(SessionConfig.DEFAULT_USER))
.pipeInfoList
.stream()
.filter(info -> pipeName.equals(info.getId()))
.findFirst()
.orElseThrow();
Assert.assertTrue(pipeInfo.getPipeExtractor().contains("source.skip-on-failed-close=true"));

TestUtils.assertDataEventuallyOnEnv(
receiverEnv,
"select * from " + database + ".d1",
"Time,s1,",
Collections.singleton("1,10,"));

TestUtils.executeNonQueries(
senderEnv,
Arrays.asList("insert into " + database + ".d1 (time, s1) values (2, 20)", "flush"),
null);

TestUtils.assertDataEventuallyOnEnv(
receiverEnv,
"select * from " + database + ".d1",
"Time,s1,",
new HashSet<>(Arrays.asList("1,10,", "2,20,")));
}
}

@Test
public void testHistoryStartTimeAndEndTimeWorkingWithOrWithoutPattern() throws Exception {
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3204,6 +3204,15 @@ private DataNodePipeMessages() {}
"Deletion resource manager for DataRegion %s is closed or deleted.";
public static final String LOG_DELETION_PERSIST_ARG_TIMED_OUT_WAITING_FOR_ARG_DELETIONS_TO_FLUSH_BEFORE_SHUTDOWN_52469B0D =
"Deletion persist-{}: timed out waiting for {} deletions to flush before shutdown.";
public static final String
LOG_TSFILE_CLOSE_FAILED_RETAINING_PIPE_HARDLINK_FOR_MANUAL_INTERVENTION_ARG_3196C2CC =
"TsFile close failed; retaining pipe hardlink for manual intervention: {}";
public static final String
LOG_FAILED_TO_CREATE_THE_MANUAL_INTERVENTION_MARKER_FOR_PIPE_TSFILE_HARDLINK_ARG_636392CC =
"Failed to create the manual-intervention marker for pipe TsFile hardlink: {}";
public static final String
EXCEPTION_FAILED_TO_SYNC_DIRECTORY_METADATA_FOR_ARG_WINDOWS_ERROR_ARG_9BBEA82F =
"Failed to sync directory metadata for %s (Windows error %d).";

public static final String
LOG_TABLET_OF_TABLE_ARG_ESTIMATED_ARG_ROWS_ARG_BYTES_FILLED_ARG_ROWS_ARG_BYTES_B6C86C00 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2975,6 +2975,15 @@ private DataNodePipeMessages() {}
"通过创建硬链接固化 TsFile %s 失败,且该 TsFile 尚未关闭,无法改为拷贝";
public static final String EXCEPTION_DELETION_RESOURCE_MANAGER_FOR_DATAREGION_ARG_IS_CLOSED_OR_DELETED_951C0622 =
"DataRegion %s 的删除资源管理器已关闭或已删除。";
public static final String
LOG_TSFILE_CLOSE_FAILED_RETAINING_PIPE_HARDLINK_FOR_MANUAL_INTERVENTION_ARG_3196C2CC =
"TsFile 封口失败,已保留 Pipe 硬链接文件以供人工处理:{}";
public static final String
LOG_FAILED_TO_CREATE_THE_MANUAL_INTERVENTION_MARKER_FOR_PIPE_TSFILE_HARDLINK_ARG_636392CC =
"创建 Pipe TsFile 硬链接的人工处理标记失败:{}";
public static final String
EXCEPTION_FAILED_TO_SYNC_DIRECTORY_METADATA_FOR_ARG_WINDOWS_ERROR_ARG_9BBEA82F =
"同步目录 %s 的元数据失败(Windows 错误代码 %d)。";
public static final String LOG_DELETION_PERSIST_ARG_TIMED_OUT_WAITING_FOR_ARG_DELETIONS_TO_FLUSH_BEFORE_SHUTDOWN_52469B0D =
"Deletion persist-{}:关闭前等待 {} 条删除记录持久化超时。";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
public class PipeTsFileInsertionEvent extends PipeInsertionEvent
implements TsFileInsertionEvent, ReferenceTrackableEvent {

private static final long INITIAL_MANUAL_INTERVENTION_MARKER_RETRY_INTERVAL_MILLIS = 1_000;
private static final long MAX_MANUAL_INTERVENTION_MARKER_RETRY_INTERVAL_MILLIS = 60_000;

private static final Logger LOGGER = LoggerFactory.getLogger(PipeTsFileInsertionEvent.class);

private final TsFileResource resource;
Expand Down Expand Up @@ -142,6 +145,11 @@ public class PipeTsFileInsertionEvent extends PipeInsertionEvent
private final AtomicBoolean isTsFileEventCommitted = new AtomicBoolean(false);
private final AtomicBoolean isTransferred = new AtomicBoolean(false);
private final AtomicBoolean isDiscarded = new AtomicBoolean(false);
private final AtomicBoolean hasLoggedManualInterventionMarkerCreationFailure =
new AtomicBoolean(false);
private final AtomicLong nextManualInterventionMarkerCreationAttemptTime = new AtomicLong();
private final AtomicLong manualInterventionMarkerCreationRetryIntervalMillis =
new AtomicLong(INITIAL_MANUAL_INTERVENTION_MARKER_RETRY_INTERVAL_MILLIS);
private final List<Runnable> onTransferredHooks = new ArrayList<>();
private final List<Runnable> onDiscardedHooks = new ArrayList<>();

Expand All @@ -153,6 +161,7 @@ public class PipeTsFileInsertionEvent extends PipeInsertionEvent
private Set<String> tableNames;
private String tsFileDedupScopeID;
private String tsFileParser;
private volatile boolean skipOnFailedClose;
// The memory that the parser of this pipe pre-allocates for the chunks of a chunk group, carried
// by the event so that the parse, which may start long after the source customized the pipe,
// still reserves what the pipe asked for
Expand Down Expand Up @@ -379,33 +388,43 @@ public boolean waitForTsFileClose(
return true;
}

if (isTsFileSealed && !resource.isEmpty()) {
if (isTsFileSealed && !resource.isEmpty() && (!skipOnFailedClose || resource.isClosed())) {
return true;
}

if (!isClosed.get()) {
isClosed.set(resource.isClosed());

synchronized (isClosed) {
while (!isClosed.get()) {
processorExecutionGuard.check();
isClosed.wait(100);
processorExecutionGuard.check();

final boolean isClosedNow = resource.isClosed();
if (isClosedNow) {
isClosed.set(true);
isClosed.notifyAll();

// Update flushPointCount after TsFile is closed
final TsFileProcessor processor = resource.getProcessor();
if (processor != null) {
flushPointCount = processor.getMemTableFlushPointCount();
while (!isClosed.get()) {
processorExecutionGuard.check();
if (resource.isClosed()) {
synchronized (isClosed) {
if (!isClosed.get()) {
isClosed.set(true);
isClosed.notifyAll();

// Update flushPointCount after TsFile is closed
final TsFileProcessor processor = resource.getProcessor();
if (processor != null) {
flushPointCount = processor.getMemTableFlushPointCount();
}
}
}
continue;
}

break;
if (skipOnFailedClose
&& shouldAttemptManualInterventionMarkerCreation()
&& retainTsFileAfterCloseFailure()) {
return false;
}

synchronized (isClosed) {
if (!isClosed.get()) {
isClosed.wait(100);
}
}
processorExecutionGuard.check();
}
}

Expand All @@ -415,6 +434,61 @@ public boolean waitForTsFileClose(
return !resource.isEmpty();
}

private boolean shouldAttemptManualInterventionMarkerCreation() {
if (resource.getCloseFailure() == null || resource.isClosed()) {
return false;
}

final long now = System.currentTimeMillis();
final long nextAttemptTime = nextManualInterventionMarkerCreationAttemptTime.get();
if (now < nextAttemptTime) {
return false;
}

final long retryInterval = manualInterventionMarkerCreationRetryIntervalMillis.get();
if (!nextManualInterventionMarkerCreationAttemptTime.compareAndSet(
nextAttemptTime, now + retryInterval)) {
return false;
}
manualInterventionMarkerCreationRetryIntervalMillis.updateAndGet(
currentInterval ->
Math.min(currentInterval * 2, MAX_MANUAL_INTERVENTION_MARKER_RETRY_INTERVAL_MILLIS));
return true;
}

private boolean retainTsFileAfterCloseFailure() {
final Throwable closeFailure = resource.getCloseFailure();
if (closeFailure == null || resource.isClosed()) {
return false;
}

final String pipeTsFileResourcePipeName =
PipeTsFileResourceManager.getPipeTsFileResourcePipeName(pipeName, creationTime);
final File pipeTsFile = tsFile;
try {
if (!PipeDataNodeResourceManager.tsfile()
.retainTsFileForManualIntervention(pipeTsFile, pipeTsFileResourcePipeName)) {
return false;
}
} catch (final IOException | SecurityException | UnsupportedOperationException e) {
if (hasLoggedManualInterventionMarkerCreationFailure.compareAndSet(false, true)) {
LOGGER.error(
DataNodePipeMessages
.LOG_FAILED_TO_CREATE_THE_MANUAL_INTERVENTION_MARKER_FOR_PIPE_TSFILE_HARDLINK_ARG_636392CC,
pipeTsFile,
e);
}
return false;
}

LOGGER.error(
DataNodePipeMessages
.LOG_TSFILE_CLOSE_FAILED_RETAINING_PIPE_HARDLINK_FOR_MANUAL_INTERVENTION_ARG_3196C2CC,
pipeTsFile,
closeFailure);
return true;
}

@Override
public File getTsFile() {
return tsFile;
Expand Down Expand Up @@ -816,6 +890,15 @@ public void setTsFileParser(final String tsFileParser) {
this.tsFileParser = tsFileParser;
}

public PipeTsFileInsertionEvent setSkipOnFailedClose(final boolean skipOnFailedClose) {
this.skipOnFailedClose = skipOnFailedClose;
return this;
}

public boolean isSkipOnFailedClose() {
return skipOnFailedClose;
}

public long getTsFileParserPreAllocatedMemorySizeInBytes() {
return tsFileParserPreAllocatedMemorySizeInBytes;
}
Expand Down Expand Up @@ -861,7 +944,8 @@ public PipeTsFileInsertionEvent shallowCopySelfAndBindPipeTaskMetaForProgressRep
endTime,
isTsFileSealed)
.bindTsFileDedupScopeID(tsFileDedupScopeID)
.setShouldReportGeneratedEventsOnCommit(shouldReportGeneratedEventsOnCommit);
.setShouldReportGeneratedEventsOnCommit(shouldReportGeneratedEventsOnCommit)
.setSkipOnFailedClose(skipOnFailedClose);
copiedEvent.setTsFileParser(tsFileParser);
copiedEvent.setTsFileParserPreAllocatedMemorySizeInBytes(
tsFileParserPreAllocatedMemorySizeInBytes);
Expand Down
Loading
Loading