Skip to content

Commit 2fedd8a

Browse files
authored
Add degraded status to show pipes (#18047)
* Add degraded status to show pipes * Update PipeRealtimeExtractTest.java
1 parent b35a575 commit 2fedd8a

27 files changed

Lines changed: 728 additions & 37 deletions

File tree

‎integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ public void testInformationSchema() throws SQLException {
551551
"pipe_sink,STRING,ATTRIBUTE,",
552552
"exception_message,STRING,ATTRIBUTE,",
553553
"remaining_event_count,INT64,ATTRIBUTE,",
554-
"estimated_remaining_seconds,DOUBLE,ATTRIBUTE,")));
554+
"estimated_remaining_seconds,DOUBLE,ATTRIBUTE,",
555+
"is_degraded,BOOLEAN,ATTRIBUTE,")));
555556
TestUtils.assertResultSetEqual(
556557
statement.executeQuery("desc pipe_plugins"),
557558
"ColumnName,DataType,Category,",
@@ -673,7 +674,7 @@ public void testInformationSchema() throws SQLException {
673674
// Filter out not self-created pipes
674675
TestUtils.assertResultSetEqual(
675676
statement.executeQuery("select * from pipes"),
676-
"id,creation_time,state,pipe_source,pipe_processor,pipe_sink,exception_message,remaining_event_count,estimated_remaining_seconds,",
677+
"id,creation_time,state,pipe_source,pipe_processor,pipe_sink,exception_message,remaining_event_count,estimated_remaining_seconds,is_degraded,",
677678
Collections.emptySet());
678679

679680
// No auth needed

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/handlers/heartbeat/DataNodeHeartbeatHandler.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ private void cachePipeHeartbeat(TDataNodeHeartbeatResp heartbeatResp) {
184184
heartbeatResp.getPipeMetaList(),
185185
heartbeatResp.getPipeCompletedList(),
186186
heartbeatResp.getPipeRemainingEventCountList(),
187-
heartbeatResp.getPipeRemainingTimeList());
187+
heartbeatResp.getPipeRemainingTimeList(),
188+
heartbeatResp.getPipeDegradedStatusList());
188189
}
189190
}
190191

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/pipe/task/PipeTableResp.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ public TShowPipeResp convertToTShowPipeResp() {
283283
canCalculateOnLocal ? -1 : temporaryMeta.getGlobalRemainingEvents());
284284
showPipeInfo.setEstimatedRemainingTime(
285285
canCalculateOnLocal ? -1 : temporaryMeta.getGlobalRemainingTime());
286+
final Boolean isDegraded = temporaryMeta.getGlobalDegraded();
287+
if (Objects.nonNull(isDegraded)) {
288+
showPipeInfo.setIsDegraded(isDegraded);
289+
}
286290
showPipeInfoList.add(showPipeInfo);
287291
}
288292

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3178,7 +3178,8 @@ public TSStatus pushHeartbeat(final int dataNodeId, final TPipeHeartbeatResp res
31783178
resp.getPipeMetaList(),
31793179
resp.getPipeCompletedList(),
31803180
resp.getPipeRemainingEventCountList(),
3181-
resp.getPipeRemainingTimeList());
3181+
resp.getPipeRemainingTimeList(),
3182+
resp.getPipeDegradedStatusList());
31823183
return StatusUtils.OK;
31833184
}
31843185

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/agent/task/PipeConfigNodeTaskAgent.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeMeta;
2929
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeStaticMeta;
3030
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeTaskMeta;
31+
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeTemporaryMeta;
3132
import org.apache.iotdb.commons.pipe.config.PipeConfig;
3233
import org.apache.iotdb.confignode.conf.ConfigNodeDescriptor;
3334
import org.apache.iotdb.confignode.i18n.ManagerMessages;
@@ -219,6 +220,7 @@ protected void collectPipeMetaListInternal(
219220
final List<ByteBuffer> pipeMetaBinaryList = new ArrayList<>();
220221
final List<Long> pipeRemainingEventCountList = new ArrayList<>();
221222
final List<Double> pipeRemainingTimeList = new ArrayList<>();
223+
final List<Integer> pipeDegradedStatusList = new ArrayList<>();
222224
try {
223225
for (final PipeMeta pipeMeta : pipeMetaKeeper.getPipeMetaList()) {
224226
pipeMetaBinaryList.add(pipeMeta.serialize());
@@ -233,6 +235,7 @@ protected void collectPipeMetaListInternal(
233235

234236
pipeRemainingEventCountList.add(remainingEventCount);
235237
pipeRemainingTimeList.add(estimatedRemainingTime);
238+
pipeDegradedStatusList.add(PipeTemporaryMeta.TS_FILE_EPOCH_DEGRADED_STATUS_UNKNOWN);
236239

237240
logger.ifPresent(
238241
l ->
@@ -249,6 +252,7 @@ protected void collectPipeMetaListInternal(
249252
resp.setPipeMetaList(pipeMetaBinaryList);
250253
resp.setPipeRemainingEventCountList(pipeRemainingEventCountList);
251254
resp.setPipeRemainingTimeList(pipeRemainingTimeList);
255+
resp.setPipeDegradedStatusList(pipeDegradedStatusList);
252256
}
253257

254258
@Override

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/runtime/PipeRuntimeCoordinator.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ public void parseHeartbeat(
9595
final List<ByteBuffer> pipeMetaByteBufferListFromDataNode,
9696
/* @Nullable */ final List<Boolean> pipeCompletedListFromAgent,
9797
/* @Nullable */ final List<Long> pipeRemainingEventCountListFromAgent,
98-
/* @Nullable */ final List<Double> pipeRemainingTimeListFromAgent) {
98+
/* @Nullable */ final List<Double> pipeRemainingTimeListFromAgent,
99+
/* @Nullable */ final List<Integer> pipeDegradedStatusListFromAgent) {
99100
pipeHeartbeatScheduler.parseHeartbeat(
100101
dataNodeId,
101102
new PipeHeartbeat(
102103
pipeMetaByteBufferListFromDataNode,
103104
pipeCompletedListFromAgent,
104105
pipeRemainingEventCountListFromAgent,
105-
pipeRemainingTimeListFromAgent));
106+
pipeRemainingTimeListFromAgent,
107+
pipeDegradedStatusListFromAgent));
106108
}
107109
}

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/runtime/heartbeat/PipeHeartbeat.java‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeMeta;
2323
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeStaticMeta;
24+
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeTemporaryMeta;
2425

2526
import java.nio.ByteBuffer;
2627
import java.util.HashMap;
@@ -33,12 +34,14 @@ public class PipeHeartbeat {
3334
private final Map<PipeStaticMeta, Boolean> isCompletedMap = new HashMap<>();
3435
private final Map<PipeStaticMeta, Long> remainingEventCountMap = new HashMap<>();
3536
private final Map<PipeStaticMeta, Double> remainingTimeMap = new HashMap<>();
37+
private final Map<PipeStaticMeta, Boolean> isDegradedMap = new HashMap<>();
3638

3739
public PipeHeartbeat(
3840
final List<ByteBuffer> pipeMetaByteBufferListFromAgent,
3941
/* @Nullable */ final List<Boolean> pipeCompletedListFromAgent,
4042
/* @Nullable */ final List<Long> pipeRemainingEventCountListFromAgent,
41-
/* @Nullable */ final List<Double> pipeRemainingTimeListFromAgent) {
43+
/* @Nullable */ final List<Double> pipeRemainingTimeListFromAgent,
44+
/* @Nullable */ final List<Integer> pipeDegradedStatusListFromAgent) {
4245
// Shall not reach here, just in case
4346
if (Objects.isNull(pipeMetaByteBufferListFromAgent)) {
4447
return;
@@ -49,20 +52,31 @@ public PipeHeartbeat(
4952
pipeMetaMap.put(pipeMeta.getStaticMeta(), pipeMeta);
5053
isCompletedMap.put(
5154
pipeMeta.getStaticMeta(),
52-
Objects.nonNull(pipeCompletedListFromAgent) && pipeCompletedListFromAgent.get(i));
55+
Objects.nonNull(pipeCompletedListFromAgent)
56+
&& i < pipeCompletedListFromAgent.size()
57+
&& pipeCompletedListFromAgent.get(i));
5358
// If remaining event count & remaining time can not be got, it implies that the heartbeat is
5459
// from an ancient version of DataNode. Here we guarantee that "0" will not affect both of
5560
// the final results and namely these dataNodes are omitted in calculation.
5661
remainingEventCountMap.put(
5762
pipeMeta.getStaticMeta(),
5863
Objects.nonNull(pipeRemainingEventCountListFromAgent)
64+
&& i < pipeRemainingEventCountListFromAgent.size()
5965
? pipeRemainingEventCountListFromAgent.get(i)
6066
: 0L);
6167
remainingTimeMap.put(
6268
pipeMeta.getStaticMeta(),
6369
Objects.nonNull(pipeRemainingTimeListFromAgent)
70+
&& i < pipeRemainingTimeListFromAgent.size()
6471
? pipeRemainingTimeListFromAgent.get(i)
6572
: 0d);
73+
isDegradedMap.put(
74+
pipeMeta.getStaticMeta(),
75+
PipeTemporaryMeta.decodeTsFileEpochDegradedStatus(
76+
Objects.nonNull(pipeDegradedStatusListFromAgent)
77+
&& i < pipeDegradedStatusListFromAgent.size()
78+
? pipeDegradedStatusListFromAgent.get(i)
79+
: null));
6680
}
6781
}
6882

@@ -86,6 +100,10 @@ public Double getRemainingTime(final PipeStaticMeta pipeStaticMeta) {
86100
return remainingTimeMap.get(pipeStaticMeta);
87101
}
88102

103+
public Boolean getDegraded(final PipeStaticMeta pipeStaticMeta) {
104+
return isDegradedMap.get(pipeStaticMeta);
105+
}
106+
89107
public boolean isEmpty() {
90108
return pipeMetaMap.isEmpty();
91109
}

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/runtime/heartbeat/PipeHeartbeatParser.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ private void parseHeartbeatAndSaveMetaChangeLocally(
191191
// Record statistics
192192
temporaryMeta.setRemainingEvent(nodeId, pipeHeartbeat.getRemainingEventCount(staticMeta));
193193
temporaryMeta.setRemainingTime(nodeId, pipeHeartbeat.getRemainingTime(staticMeta));
194+
temporaryMeta.setDegraded(nodeId, pipeHeartbeat.getDegraded(staticMeta));
194195

195196
final Map<Integer, PipeTaskMeta> pipeTaskMetaMapFromCoordinator =
196197
pipeMetaFromCoordinator.getRuntimeMeta().getConsensusGroupId2TaskMetaMap();

‎iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/runtime/heartbeat/PipeHeartbeatScheduler.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ private synchronized void heartbeat() {
115115
resp.getPipeMetaList(),
116116
resp.getPipeCompletedList(),
117117
resp.getPipeRemainingEventCountList(),
118-
resp.getPipeRemainingTimeList())));
118+
resp.getPipeRemainingTimeList(),
119+
resp.getPipeDegradedStatusList())));
119120

120121
// config node heartbeat
121122
try {
@@ -127,7 +128,8 @@ private synchronized void heartbeat() {
127128
configNodeResp.getPipeMetaList(),
128129
null,
129130
configNodeResp.getPipeRemainingEventCountList(),
130-
configNodeResp.getPipeRemainingTimeList()));
131+
configNodeResp.getPipeRemainingTimeList(),
132+
configNodeResp.getPipeDegradedStatusList()));
131133
} catch (final Exception e) {
132134
PipeLogger.log(
133135
LOGGER::warn, e, ManagerMessages.FAILED_TO_COLLECT_PIPE_META_LIST_FROM_CONFIG_NODE_TASK);

‎iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/consensus/response/pipe/PipeTableRespTest.java‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@
2424
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeRuntimeMeta;
2525
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeStaticMeta;
2626
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeTaskMeta;
27+
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeTemporaryMetaInCoordinator;
2728
import org.apache.iotdb.commons.pipe.config.constant.SystemConstant;
2829
import org.apache.iotdb.confignode.consensus.response.pipe.task.PipeTableResp;
30+
import org.apache.iotdb.confignode.manager.ConfigManager;
31+
import org.apache.iotdb.confignode.manager.node.NodeManager;
32+
import org.apache.iotdb.confignode.rpc.thrift.TShowPipeInfo;
33+
import org.apache.iotdb.confignode.service.ConfigNode;
2934
import org.apache.iotdb.rpc.TSStatusCode;
3035

36+
import org.junit.After;
3137
import org.junit.Assert;
38+
import org.junit.Before;
3239
import org.junit.Test;
40+
import org.mockito.Mockito;
3341

3442
import java.util.ArrayList;
3543
import java.util.HashMap;
@@ -40,6 +48,26 @@
4048

4149
public class PipeTableRespTest {
4250

51+
private ConfigNode oldInstance;
52+
53+
@Before
54+
public void setUp() {
55+
oldInstance = ConfigNode.getInstance();
56+
final ConfigNode configNode = Mockito.mock(ConfigNode.class);
57+
final ConfigManager configManager = Mockito.mock(ConfigManager.class);
58+
final NodeManager nodeManager = Mockito.mock(NodeManager.class);
59+
60+
Mockito.when(configNode.getConfigManager()).thenReturn(configManager);
61+
Mockito.when(configManager.getNodeManager()).thenReturn(nodeManager);
62+
Mockito.when(nodeManager.getRegisteredDataNodeCount()).thenReturn(2);
63+
ConfigNode.setInstance(configNode);
64+
}
65+
66+
@After
67+
public void tearDown() {
68+
ConfigNode.setInstance(oldInstance);
69+
}
70+
4371
public PipeTableResp constructPipeTableResp() {
4472
TSStatus status = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
4573
List<PipeMeta> pipeMetaList = new ArrayList<>();
@@ -120,6 +148,26 @@ public void testFilter() {
120148
Assert.assertEquals(3, allPipeTableResp.getAllPipeMeta().size());
121149
}
122150

151+
@Test
152+
public void testConvertToTShowPipeRespIncludesDegradedStatus() {
153+
final PipeTableResp pipeTableResp = constructPipeTableResp();
154+
((PipeTemporaryMetaInCoordinator) pipeTableResp.getAllPipeMeta().get(0).getTemporaryMeta())
155+
.setDegraded(1, true);
156+
((PipeTemporaryMetaInCoordinator) pipeTableResp.getAllPipeMeta().get(1).getTemporaryMeta())
157+
.setDegraded(1, false);
158+
159+
final List<TShowPipeInfo> showPipeResult =
160+
pipeTableResp.convertToTShowPipeResp().getPipeInfoList();
161+
162+
Assert.assertEquals(3, showPipeResult.size());
163+
Assert.assertEquals("testPipe", showPipeResult.get(0).getId());
164+
Assert.assertTrue(showPipeResult.get(0).isSetIsDegraded());
165+
Assert.assertTrue(showPipeResult.get(0).isIsDegraded());
166+
Assert.assertTrue(showPipeResult.get(1).isSetIsDegraded());
167+
Assert.assertFalse(showPipeResult.get(1).isIsDegraded());
168+
Assert.assertFalse(showPipeResult.get(2).isSetIsDegraded());
169+
}
170+
123171
@Test
124172
public void testFilterByModelBeforeWhereClause() {
125173
TSStatus status = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());

0 commit comments

Comments
 (0)