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 @@ -236,18 +236,12 @@ private void parseHeartbeatAndSaveMetaChangeLocally(
}

// Update progress index
if (!(runtimeMetaFromCoordinator
.getValue()
.getProgressIndex()
.isAfter(runtimeMetaFromAgent.getProgressIndex())
|| runtimeMetaFromCoordinator
.getValue()
.getProgressIndex()
.equals(runtimeMetaFromAgent.getProgressIndex()))) {
final ProgressIndex coordinatorProgressIndex =
runtimeMetaFromCoordinator.getValue().getProgressIndex();
final ProgressIndex agentProgressIndex = runtimeMetaFromAgent.getProgressIndex();
if (!coordinatorProgressIndex.isEqualOrAfter(agentProgressIndex)) {
final ProgressIndex updatedProgressIndex =
runtimeMetaFromCoordinator
.getValue()
.updateProgressIndex(runtimeMetaFromAgent.getProgressIndex());
runtimeMetaFromCoordinator.getValue().updateProgressIndex(agentProgressIndex);
PipeConfigNodeResourceManager.log()
.schedule(
PipeHeartbeatParser.class,
Expand All @@ -263,8 +257,8 @@ private void parseHeartbeatAndSaveMetaChangeLocally(
.LOG_PROGRESS_INDEX_COORDINATOR_ARG_PROGRESS_INDEX_AGENT_ARG_UPDATED_PROGRESSINDEX_1A22ABC5,
pipeMetaFromCoordinator.getStaticMeta().getPipeName(),
runtimeMetaFromCoordinator.getKey(),
runtimeMetaFromCoordinator.getValue().getProgressIndex(),
runtimeMetaFromAgent.getProgressIndex(),
coordinatorProgressIndex,
agentProgressIndex,
updatedProgressIndex));

needWriteConsensusOnConfigNodes.set(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.apache.iotdb.common.rpc.thrift.TPipeCompletedDataRegion;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.consensus.index.impl.MinimumProgressIndex;
import org.apache.iotdb.commons.consensus.index.impl.RecoverProgressIndex;
import org.apache.iotdb.commons.consensus.index.impl.SimpleProgressIndex;
import org.apache.iotdb.commons.exception.pipe.PipeRuntimeCriticalException;
import org.apache.iotdb.commons.exception.pipe.PipeRuntimeSinkCriticalException;
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeMeta;
Expand Down Expand Up @@ -141,6 +143,82 @@ public void testParseHeartbeatKeepsPendingFlagsWhenProcedureSubmissionFails() th
verify(context.procedureManager, times(2)).pipeHandleMetaChange(true, false);
}

@Test
public void testParseHeartbeatSkipsConsensusWriteWhenCoordinatorProgressCoversAgent()
throws Exception {
CommonDescriptor.getInstance().getConfig().setSeperatedPipeHeartbeatEnabled(false);

final PipeTaskInfo pipeTaskInfo = new PipeTaskInfo();
final PipeMeta coordinatorPipeMeta = createPipeMeta();
final RecoverProgressIndex coordinatorProgressIndex = createRecoverProgressIndex(10, 10);
coordinatorPipeMeta
.getRuntimeMeta()
.getConsensusGroupId2TaskMetaMap()
.get(DATA_NODE_ID)
.updateProgressIndex(coordinatorProgressIndex);
pipeTaskInfo.createPipe(
new CreatePipePlanV2(
coordinatorPipeMeta.getStaticMeta(), coordinatorPipeMeta.getRuntimeMeta()));

final PipeMeta agentPipeMeta = createPipeMeta();
agentPipeMeta
.getRuntimeMeta()
.getConsensusGroupId2TaskMetaMap()
.get(DATA_NODE_ID)
.updateProgressIndex(createRecoverProgressIndex(10, 5));

final ParserTestContext context = createParserTestContext(1, pipeTaskInfo);
context.parser.parseHeartbeat(DATA_NODE_ID, createPipeHeartbeat(agentPipeMeta, false));

assertEquals(
coordinatorProgressIndex,
pipeTaskInfo
.getPipeMetaByPipeName("test_pipe")
.getRuntimeMeta()
.getConsensusGroupId2TaskMetaMap()
.get(DATA_NODE_ID)
.getProgressIndex());
verify(context.procedureManager, never()).pipeHandleMetaChange(anyBoolean(), anyBoolean());
}

@Test
public void testParseHeartbeatWritesConsensusWhenAgentProgressAdvancesCoordinator()
throws Exception {
CommonDescriptor.getInstance().getConfig().setSeperatedPipeHeartbeatEnabled(false);

final PipeTaskInfo pipeTaskInfo = new PipeTaskInfo();
final PipeMeta coordinatorPipeMeta = createPipeMeta();
coordinatorPipeMeta
.getRuntimeMeta()
.getConsensusGroupId2TaskMetaMap()
.get(DATA_NODE_ID)
.updateProgressIndex(createRecoverProgressIndex(10, 10));
pipeTaskInfo.createPipe(
new CreatePipePlanV2(
coordinatorPipeMeta.getStaticMeta(), coordinatorPipeMeta.getRuntimeMeta()));

final PipeMeta agentPipeMeta = createPipeMeta();
final RecoverProgressIndex agentProgressIndex = createRecoverProgressIndex(10, 11);
agentPipeMeta
.getRuntimeMeta()
.getConsensusGroupId2TaskMetaMap()
.get(DATA_NODE_ID)
.updateProgressIndex(agentProgressIndex);

final ParserTestContext context = createParserTestContext(1, pipeTaskInfo);
context.parser.parseHeartbeat(DATA_NODE_ID, createPipeHeartbeat(agentPipeMeta, false));

assertEquals(
agentProgressIndex,
pipeTaskInfo
.getPipeMetaByPipeName("test_pipe")
.getRuntimeMeta()
.getConsensusGroupId2TaskMetaMap()
.get(DATA_NODE_ID)
.getProgressIndex());
verify(context.procedureManager, times(1)).pipeHandleMetaChange(true, false);
}

@Test
public void testParseHeartbeatIgnoresExceptionsBeforeClearTime() throws Exception {
CommonDescriptor.getInstance().getConfig().setSeperatedPipeHeartbeatEnabled(false);
Expand Down Expand Up @@ -683,6 +761,14 @@ private PipeMeta createHistoryOnlyPipeMeta(final int... regionIds) {
return createPipeMeta(sourceAttributes, regionIds);
}

private RecoverProgressIndex createRecoverProgressIndex(
final long firstDataNodeIndex, final long secondDataNodeIndex) {
final Map<Integer, SimpleProgressIndex> dataNodeId2LocalIndex = new HashMap<>();
dataNodeId2LocalIndex.put(1, new SimpleProgressIndex(0, firstDataNodeIndex));
dataNodeId2LocalIndex.put(2, new SimpleProgressIndex(0, secondDataNodeIndex));
return new RecoverProgressIndex(dataNodeId2LocalIndex);
}

private PipeMeta createPipeMeta(
final Map<String, String> sourceAttributes, final int... regionIds) {
final PipeRuntimeMeta pipeRuntimeMeta = new PipeRuntimeMeta();
Expand Down
Loading