Skip to content

Commit cf23bde

Browse files
committed
Merge branch 'master' of https://github.com/apache/iotdb into fix/clear-pipe-runtime-error-message
# Conflicts: # iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/pipe/PipeTaskInfo.java # iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/StartPipeProcedureV2.java # iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/pipe/PipeTaskInfoAutoRestartTest.java
2 parents 4227fb5 + 186ce36 commit cf23bde

135 files changed

Lines changed: 5967 additions & 853 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/basic/IoTDBPipeDataSinkIT.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.iotdb.common.rpc.thrift.TSStatus;
2323
import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
2424
import org.apache.iotdb.confignode.rpc.thrift.TCreatePipeReq;
25+
import org.apache.iotdb.confignode.rpc.thrift.TDropPipeReq;
2526
import org.apache.iotdb.db.it.utils.TestUtils;
2627
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
2728
import org.apache.iotdb.it.framework.IoTDBTestRunner;
@@ -88,7 +89,9 @@ public void testThriftConnectorWithRealtimeFirstDisabled() throws Exception {
8889

8990
sourceAttributes.put("source.realtime.mode", "log");
9091
sourceAttributes.put("capture.table", "true");
92+
sourceAttributes.put("__system.sql-dialect", "table");
9193
sourceAttributes.put("capture.tree", "true");
94+
sourceAttributes.put("mode.double-living", "true");
9295
sourceAttributes.put("user", "root");
9396

9497
sinkAttributes.put("sink", "iotdb-thrift-sink");
@@ -173,7 +176,9 @@ private void testSinkFormat(final String format, final boolean isAsyncLoad) thro
173176
final Map<String, String> sinkAttributes = new HashMap<>();
174177

175178
sourceAttributes.put("capture.table", "true");
179+
sourceAttributes.put("__system.sql-dialect", "table");
176180
sourceAttributes.put("capture.tree", "true");
181+
sourceAttributes.put("mode.double-living", "true");
177182
sourceAttributes.put("user", "root");
178183

179184
sinkAttributes.put("sink", "iotdb-thrift-sink");
@@ -213,7 +218,11 @@ private void testSinkFormat(final String format, final boolean isAsyncLoad) thro
213218
handleFailure);
214219

215220
Assert.assertEquals(
216-
TSStatusCode.SUCCESS_STATUS.getStatusCode(), client.dropPipe("testPipe").getCode());
221+
TSStatusCode.SUCCESS_STATUS.getStatusCode(),
222+
client.dropPipeExtended(new TDropPipeReq("testPipe").setIsTableModel(false)).getCode());
223+
Assert.assertEquals(
224+
TSStatusCode.SUCCESS_STATUS.getStatusCode(),
225+
client.dropPipeExtended(new TDropPipeReq("testPipe").setIsTableModel(true)).getCode());
217226

218227
Assert.assertEquals(
219228
TSStatusCode.SUCCESS_STATUS.getStatusCode(),
@@ -260,7 +269,9 @@ public void testWriteBackSink() throws Exception {
260269
final Map<String, String> sinkAttributes = new HashMap<>();
261270

262271
sourceAttributes.put("capture.table", "true");
272+
sourceAttributes.put("__system.sql-dialect", "table");
263273
sourceAttributes.put("capture.tree", "true");
274+
sourceAttributes.put("mode.double-living", "true");
264275
sourceAttributes.put("forwarding-pipe-requests", "false");
265276
sourceAttributes.put("source.database-name", "test.*");
266277
sourceAttributes.put("source.table-name", "test.*");
@@ -377,7 +388,9 @@ private void doTest(BiConsumer<Map<String, List<Tablet>>, Map<String, List<Table
377388
final Map<String, String> sinkAttributes = new HashMap<>();
378389

379390
sourceAttributes.put("capture.table", "true");
391+
sourceAttributes.put("__system.sql-dialect", "table");
380392
sourceAttributes.put("capture.tree", "true");
393+
sourceAttributes.put("mode.double-living", "true");
381394
sourceAttributes.put("source.database-name", "test.*");
382395
sourceAttributes.put("source.table-name", "test.*");
383396
sourceAttributes.put("user", "root");
@@ -734,7 +747,9 @@ public void testLoadTsFileWithoutVerify() throws Exception {
734747

735748
sourceAttributes.put("source.realtime.mode", "batch");
736749
sourceAttributes.put("capture.table", "true");
750+
sourceAttributes.put("__system.sql-dialect", "table");
737751
sourceAttributes.put("capture.tree", "true");
752+
sourceAttributes.put("mode.double-living", "true");
738753
sourceAttributes.put("user", "root");
739754

740755
sinkAttributes.put("sink", "iotdb-thrift-sink");

integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/basic/IoTDBPipeIsolationIT.java

Lines changed: 199 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020
package org.apache.iotdb.pipe.it.dual.tablemodel.manual.basic;
2121

2222
import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
23+
import org.apache.iotdb.commons.pipe.config.constant.SystemConstant;
2324
import org.apache.iotdb.confignode.rpc.thrift.TAlterPipeReq;
25+
import org.apache.iotdb.confignode.rpc.thrift.TCreatePipeReq;
2426
import org.apache.iotdb.confignode.rpc.thrift.TDropPipeReq;
27+
import org.apache.iotdb.confignode.rpc.thrift.TShowPipeInfo;
28+
import org.apache.iotdb.confignode.rpc.thrift.TShowPipeReq;
2529
import org.apache.iotdb.confignode.rpc.thrift.TStartPipeReq;
2630
import org.apache.iotdb.confignode.rpc.thrift.TStopPipeReq;
31+
import org.apache.iotdb.isession.SessionConfig;
2732
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
2833
import org.apache.iotdb.it.framework.IoTDBTestRunner;
2934
import org.apache.iotdb.itbase.category.MultiClusterIT2DualTableManualBasic;
@@ -42,6 +47,9 @@
4247
import java.sql.SQLException;
4348
import java.sql.Statement;
4449
import java.util.Collections;
50+
import java.util.HashMap;
51+
import java.util.List;
52+
import java.util.Map;
4553

4654
import static org.junit.Assert.fail;
4755

@@ -245,7 +253,7 @@ public void testReadPipeIsolation() {
245253
}
246254

247255
@Test
248-
public void testCaptureTreeAndTableIsolation() throws Exception {
256+
public void testCaptureTreeAndTableIgnoredByDialectIsolation() throws Exception {
249257
final String treePipeName = "tree_a2b";
250258
final String tablePipeName = "table_a2b";
251259

@@ -272,7 +280,7 @@ public void testCaptureTreeAndTableIsolation() throws Exception {
272280
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
273281

274282
// Show table pipe by table session
275-
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
283+
Assert.assertEquals(0, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
276284

277285
// 2. Create table pipe by table session
278286
try (final Connection connection = senderEnv.getConnection(BaseEnv.TABLE_SQL_DIALECT);
@@ -292,30 +300,105 @@ public void testCaptureTreeAndTableIsolation() throws Exception {
292300
}
293301

294302
// Show tree pipe by tree session
295-
Assert.assertEquals(2, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
303+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
296304

297305
// Show table pipe by table session
298-
Assert.assertEquals(2, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
306+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
299307

300308
// 3. Drop pipe
301309
try (final SyncConfigNodeIServiceClient client =
302310
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
303311
Assert.assertEquals(
304312
TSStatusCode.SUCCESS_STATUS.getStatusCode(),
305-
client.dropPipeExtended(new TDropPipeReq(treePipeName).setIsTableModel(true)).getCode());
313+
client.dropPipeExtended(new TDropPipeReq(treePipeName).setIsTableModel(false)).getCode());
306314
Assert.assertEquals(
307315
TSStatusCode.SUCCESS_STATUS.getStatusCode(),
308-
client
309-
.dropPipeExtended(new TDropPipeReq(tablePipeName).setIsTableModel(false))
310-
.getCode());
316+
client.dropPipeExtended(new TDropPipeReq(tablePipeName).setIsTableModel(true)).getCode());
317+
}
318+
}
319+
320+
@Test
321+
public void testSameNameTreeOnlyAndTableOnlyPipeIsolation() throws Exception {
322+
final String pipeName = "same_name_pipe";
323+
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);
324+
325+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TREE_SQL_DIALECT);
326+
final Statement statement = connection.createStatement()) {
327+
statement.execute(
328+
String.format(
329+
"create pipe %s with sink ('node-urls'='%s')",
330+
pipeName, receiverDataNode.getIpAndPortString()));
331+
}
332+
333+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TABLE_SQL_DIALECT);
334+
final Statement statement = connection.createStatement()) {
335+
statement.execute(
336+
String.format(
337+
"create pipe %s with sink ('node-urls'='%s')",
338+
pipeName, receiverDataNode.getIpAndPortString()));
339+
}
340+
341+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
342+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
343+
344+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TABLE_SQL_DIALECT);
345+
final Statement statement = connection.createStatement()) {
346+
statement.execute("stop pipe " + pipeName);
347+
}
348+
349+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
350+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
351+
352+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TREE_SQL_DIALECT);
353+
final Statement statement = connection.createStatement()) {
354+
statement.execute("drop pipe " + pipeName);
355+
}
356+
357+
Assert.assertEquals(0, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
358+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
359+
360+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TABLE_SQL_DIALECT);
361+
final Statement statement = connection.createStatement()) {
362+
statement.execute("start pipe " + pipeName);
363+
statement.execute("drop pipe " + pipeName);
311364
}
365+
366+
Assert.assertEquals(0, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
367+
Assert.assertEquals(0, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
312368
}
313369

314370
@Test
315-
public void testCaptureCornerCases() {
371+
public void testSameNamePipeWithCaptureAttributesStillIsolated() throws Exception {
372+
final String pipeName = "same_name_conflict_pipe";
316373
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);
317374

318-
// 1. Create tree pipe but capture table data
375+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TREE_SQL_DIALECT);
376+
final Statement statement = connection.createStatement()) {
377+
statement.execute(
378+
String.format(
379+
"create pipe %s with sink ('node-urls'='%s')",
380+
pipeName, receiverDataNode.getIpAndPortString()));
381+
}
382+
383+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TABLE_SQL_DIALECT);
384+
final Statement statement = connection.createStatement()) {
385+
statement.execute(
386+
String.format(
387+
"create pipe %s"
388+
+ " with source ('capture.tree'='true','capture.table'='true')"
389+
+ " with sink ('node-urls'='%s')",
390+
pipeName, receiverDataNode.getIpAndPortString()));
391+
}
392+
393+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
394+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
395+
}
396+
397+
@Test
398+
public void testCaptureAttributesAreIgnoredByDialect() {
399+
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);
400+
401+
// 1. Create tree pipe with capture attributes pointing to table data
319402
try (final Connection connection = senderEnv.getConnection(BaseEnv.TREE_SQL_DIALECT);
320403
final Statement statement = connection.createStatement()) {
321404
statement.execute(
@@ -333,12 +416,12 @@ public void testCaptureCornerCases() {
333416
}
334417

335418
// Show tree pipe by tree session
336-
Assert.assertEquals(0, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
419+
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
337420

338421
// Show table pipe by table session
339-
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
422+
Assert.assertEquals(0, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
340423

341-
// 2. Create table pipe but capture tree data
424+
// 2. Create table pipe with capture attributes pointing to tree data
342425
try (final Connection connection = senderEnv.getConnection(BaseEnv.TABLE_SQL_DIALECT);
343426
final Statement statement = connection.createStatement()) {
344427
statement.execute(
@@ -373,14 +456,114 @@ public void testCaptureCornerCases() {
373456
+ " with sink ("
374457
+ "'node-urls'='%s')",
375458
"p3", receiverDataNode.getIpAndPortString()));
376-
fail();
377-
} catch (final SQLException ignored) {
459+
} catch (final SQLException e) {
460+
e.printStackTrace();
461+
fail(e.getMessage());
378462
}
379463

380464
// Show tree pipe by tree session
381-
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
465+
Assert.assertEquals(2, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TREE_SQL_DIALECT));
382466

383467
// Show table pipe by table session
384468
Assert.assertEquals(1, TableModelUtils.showPipesCount(senderEnv, BaseEnv.TABLE_SQL_DIALECT));
385469
}
470+
471+
@Test
472+
public void testDirectRpcCreationDialectCompatibility() throws Exception {
473+
final String pipeName = "rpc_same_name_pipe";
474+
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);
475+
final Map<String, String> sinkAttributes = new HashMap<>();
476+
sinkAttributes.put("sink", "iotdb-thrift-sink");
477+
sinkAttributes.put("sink.ip", receiverDataNode.getIp());
478+
sinkAttributes.put("sink.port", String.valueOf(receiverDataNode.getPort()));
479+
480+
try (final SyncConfigNodeIServiceClient client =
481+
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
482+
Assert.assertEquals(
483+
TSStatusCode.SUCCESS_STATUS.getStatusCode(),
484+
client.createPipe(new TCreatePipeReq(pipeName, sinkAttributes)).getCode());
485+
486+
Assert.assertEquals(1, showPipes(client, false).size());
487+
Assert.assertEquals(0, showPipes(client, true).size());
488+
Assert.assertTrue(
489+
showPipes(client, false)
490+
.get(0)
491+
.pipeExtractor
492+
.contains(
493+
SystemConstant.SQL_DIALECT_KEY + "=" + SystemConstant.SQL_DIALECT_TREE_VALUE));
494+
495+
final Map<String, String> tableSourceAttributes = new HashMap<>();
496+
tableSourceAttributes.put(
497+
SystemConstant.SQL_DIALECT_KEY, SystemConstant.SQL_DIALECT_TABLE_VALUE);
498+
Assert.assertEquals(
499+
TSStatusCode.SUCCESS_STATUS.getStatusCode(),
500+
client
501+
.createPipe(
502+
new TCreatePipeReq(pipeName, sinkAttributes)
503+
.setExtractorAttributes(tableSourceAttributes))
504+
.getCode());
505+
506+
Assert.assertEquals(1, showPipes(client, false).size());
507+
Assert.assertEquals(1, showPipes(client, true).size());
508+
Assert.assertTrue(
509+
showPipes(client, true)
510+
.get(0)
511+
.pipeExtractor
512+
.contains(
513+
SystemConstant.SQL_DIALECT_KEY + "=" + SystemConstant.SQL_DIALECT_TABLE_VALUE));
514+
515+
Assert.assertNotEquals(
516+
TSStatusCode.SUCCESS_STATUS.getStatusCode(),
517+
client.createPipe(new TCreatePipeReq(pipeName, sinkAttributes)).getCode());
518+
}
519+
}
520+
521+
@Test
522+
public void testLegacyLifecycleRpcPrefersTreePipeThenTablePipe() throws Exception {
523+
final String pipeName = "legacy_same_name_pipe";
524+
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);
525+
526+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TREE_SQL_DIALECT);
527+
final Statement statement = connection.createStatement()) {
528+
statement.execute(
529+
String.format(
530+
"create pipe %s with sink ('node-urls'='%s')",
531+
pipeName, receiverDataNode.getIpAndPortString()));
532+
}
533+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TABLE_SQL_DIALECT);
534+
final Statement statement = connection.createStatement()) {
535+
statement.execute(
536+
String.format(
537+
"create pipe %s with sink ('node-urls'='%s')",
538+
pipeName, receiverDataNode.getIpAndPortString()));
539+
}
540+
541+
try (final SyncConfigNodeIServiceClient client =
542+
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
543+
Assert.assertEquals(1, showPipes(client, false).size());
544+
Assert.assertEquals(1, showPipes(client, true).size());
545+
546+
Assert.assertEquals(
547+
TSStatusCode.SUCCESS_STATUS.getStatusCode(), client.dropPipe(pipeName).getCode());
548+
Assert.assertEquals(0, showPipes(client, false).size());
549+
Assert.assertEquals(1, showPipes(client, true).size());
550+
551+
Assert.assertEquals(
552+
TSStatusCode.SUCCESS_STATUS.getStatusCode(), client.dropPipe(pipeName).getCode());
553+
Assert.assertEquals(0, showPipes(client, false).size());
554+
Assert.assertEquals(0, showPipes(client, true).size());
555+
}
556+
}
557+
558+
private List<TShowPipeInfo> showPipes(
559+
final SyncConfigNodeIServiceClient client, final boolean isTableModel) throws Exception {
560+
final List<TShowPipeInfo> showPipeResult =
561+
client.showPipe(
562+
new TShowPipeReq()
563+
.setIsTableModel(isTableModel)
564+
.setUserName(SessionConfig.DEFAULT_USER))
565+
.pipeInfoList;
566+
showPipeResult.removeIf(i -> i.getId().startsWith("__consensus"));
567+
return showPipeResult;
568+
}
386569
}

0 commit comments

Comments
 (0)