-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Pipe/Subscription: Add 'Create If Not Exists' and 'Drop If Exists' Support for Pipes, Plugins, and Topics #12969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SteveYurongSu
merged 34 commits into
apache:master
from
luoluoyuyu:if-not-exists-support
Aug 1, 2024
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
9f6e108
Support for Create Pipe If Not Exists Semantics
luoluoyuyu b5ff79e
Support for Drop Pipe If Exists Semantics
luoluoyuyu d0f6bd6
Support for Create PipePlugin If Not Exists and Drop PipePlugin If Ex…
luoluoyuyu 14b98fc
Support for Create PipePlugin If Not Exists and Drop PipePlugin If Ex…
luoluoyuyu 4f06652
Add Create Pipe If Not Exists And Drop Pipe If Exists Integration Tests
luoluoyuyu 2ab70f2
Modify the code format
luoluoyuyu e37b3a9
Modify IoTDBPipeCreateAndDrop Integration Test
luoluoyuyu 8aa7b86
Modify IoTDBPipeCreateAndDrop Integration Test
luoluoyuyu c26560d
Supports Create Topic IF NOT EXISTS and Drop Topic IF EXISTS semantics.
luoluoyuyu 953c5ea
Supports Alter Pipe IF EXISTS semantics.
luoluoyuyu 9f677a8
pass the CI test
luoluoyuyu 2ba5fe8
Reimplement Drop Topic semantics
luoluoyuyu 51ceb74
fix code
luoluoyuyu 894873a
Modify the code
luoluoyuyu 30a2caf
Modify the code
luoluoyuyu 1c53165
Modify code comments
luoluoyuyu 7e5289a
Modify code comments
luoluoyuyu 152679e
Modify code comments
luoluoyuyu f096590
Modify code comments
luoluoyuyu 32b87e3
Merge branch 'apache:master' into if-not-exists-support
luoluoyuyu 49cdf1b
Fix Drop If Exits Topic
luoluoyuyu e818ab8
Merge branch 'master' of https://github.com/apache/iotdb into pr/12969
SteveYurongSu 9e856c7
refactor
SteveYurongSu 4a1b799
refactor
SteveYurongSu 5a2dcbf
Update PipeTaskCoordinator.java
SteveYurongSu 99f0c68
Update SubscriptionCoordinator.java
SteveYurongSu 60aa892
refactor
SteveYurongSu ff66c0b
Update ASTVisitor.java
SteveYurongSu 14d7300
refactor
SteveYurongSu e7678d2
Update ClusterConfigTaskExecutor.java
SteveYurongSu f515702
Update ClusterConfigTaskExecutor.java
SteveYurongSu 9d284b4
refactor
SteveYurongSu 437e709
Update SubscriptionInfo.java
SteveYurongSu 2f2796d
Update PipeTaskInfo.java
SteveYurongSu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
228 changes: 228 additions & 0 deletions
228
...t/src/test/java/org/apache/iotdb/pipe/it/autocreate/IoTDBPipeConditionalOperationsIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,228 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iotdb.pipe.it.autocreate; | ||
|
|
||
| import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient; | ||
| import org.apache.iotdb.confignode.rpc.thrift.TShowPipeInfo; | ||
| import org.apache.iotdb.confignode.rpc.thrift.TShowPipeReq; | ||
| import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; | ||
| import org.apache.iotdb.it.framework.IoTDBTestRunner; | ||
| import org.apache.iotdb.itbase.category.MultiClusterIT2AutoCreateSchema; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
| import java.sql.Statement; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.Assert.fail; | ||
|
|
||
| @RunWith(IoTDBTestRunner.class) | ||
| @Category({MultiClusterIT2AutoCreateSchema.class}) | ||
| public class IoTDBPipeConditionalOperationsIT extends AbstractPipeDualAutoIT { | ||
|
|
||
| @Test | ||
| public void testBasicCreatePipeIfNotExists() throws Exception { | ||
| final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0); | ||
|
|
||
| // Create pipe | ||
| String sql = | ||
| String.format( | ||
| "create pipe If Not Exists a2b with source ('source'='iotdb-source', 'source.pattern'='root.test1', 'source.realtime.mode'='stream') with processor ('processor'='do-nothing-processor') with sink ('node-urls'='%s')", | ||
| receiverDataNode.getIpAndPortString()); | ||
| try (final Connection connection = senderEnv.getConnection(); | ||
| final Statement statement = connection.createStatement()) { | ||
| statement.execute(sql); | ||
| } catch (SQLException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
|
|
||
| // show pipe | ||
| long creationTime; | ||
| try (final SyncConfigNodeIServiceClient client = | ||
| (SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) { | ||
| final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList; | ||
| Assert.assertEquals(1, showPipeResult.size()); | ||
| // Check status | ||
| Assert.assertEquals("RUNNING", showPipeResult.get(0).state); | ||
| // Check configurations | ||
| Assert.assertTrue(showPipeResult.get(0).pipeExtractor.contains("source=iotdb-source")); | ||
| Assert.assertTrue(showPipeResult.get(0).pipeExtractor.contains("source.pattern=root.test1")); | ||
| Assert.assertTrue( | ||
| showPipeResult.get(0).pipeExtractor.contains("source.realtime.mode=stream")); | ||
| Assert.assertTrue( | ||
| showPipeResult.get(0).pipeProcessor.contains("processor=do-nothing-processor")); | ||
| Assert.assertTrue( | ||
| showPipeResult | ||
| .get(0) | ||
| .pipeConnector | ||
| .contains(String.format("node-urls=%s", receiverDataNode.getIpAndPortString()))); | ||
| // Record last creation time | ||
| creationTime = showPipeResult.get(0).creationTime; | ||
| } | ||
|
|
||
| // Create pipe If Not Exists | ||
| sql = | ||
| String.format( | ||
| "create pipe If Not Exists a2b with source ('source'='iotdb-source', 'source.path'='root.test2.**') with sink ('node-urls'='%s')", | ||
| receiverDataNode.getIpAndPortString()); | ||
| try (final Connection connection = senderEnv.getConnection(); | ||
| final Statement statement = connection.createStatement()) { | ||
| statement.execute(sql); | ||
| } catch (SQLException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
|
|
||
| // show pipe | ||
| try (final SyncConfigNodeIServiceClient client = | ||
| (SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) { | ||
| final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList; | ||
| Assert.assertEquals(1, showPipeResult.size()); | ||
| // Check status | ||
| Assert.assertEquals("RUNNING", showPipeResult.get(0).state); | ||
| // Check configurations | ||
| Assert.assertTrue(showPipeResult.get(0).pipeExtractor.contains("source=iotdb-source")); | ||
| Assert.assertTrue(showPipeResult.get(0).pipeExtractor.contains("source.pattern=root.test1")); | ||
| Assert.assertTrue( | ||
| showPipeResult.get(0).pipeExtractor.contains("source.realtime.mode=stream")); | ||
| Assert.assertTrue( | ||
| showPipeResult.get(0).pipeProcessor.contains("processor=do-nothing-processor")); | ||
| Assert.assertTrue( | ||
| showPipeResult | ||
| .get(0) | ||
| .pipeConnector | ||
| .contains(String.format("node-urls=%s", receiverDataNode.getIpAndPortString()))); | ||
| Assert.assertFalse(showPipeResult.get(0).pipeExtractor.contains("source.path=root.test2.**")); | ||
| Assert.assertEquals(creationTime, showPipeResult.get(0).creationTime); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testBasicDropPipeIfExists() throws Exception { | ||
| final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0); | ||
|
|
||
| // Create pipe | ||
| final String sql = | ||
| String.format( | ||
| "create pipe If Not Exists a2b with source ('source'='iotdb-source', 'source.path'='root.test1.**') with processor ('processor'='do-nothing-processor') with sink ('node-urls'='%s')", | ||
| receiverDataNode.getIpAndPortString()); | ||
| try (final Connection connection = senderEnv.getConnection(); | ||
| final Statement statement = connection.createStatement()) { | ||
| statement.execute(sql); | ||
| } catch (SQLException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
|
|
||
| // Drop pipe If Exists | ||
| try (final Connection connection = senderEnv.getConnection(); | ||
| final Statement statement = connection.createStatement()) { | ||
| statement.execute("Drop pipe If Exists a2b"); | ||
| } catch (SQLException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
|
|
||
| // show pipe | ||
| try (final SyncConfigNodeIServiceClient client = | ||
| (SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) { | ||
| final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList; | ||
| Assert.assertEquals(0, showPipeResult.size()); | ||
| } | ||
|
|
||
| // Drop pipe If Exists | ||
| try (final Connection connection = senderEnv.getConnection(); | ||
| final Statement statement = connection.createStatement()) { | ||
| statement.execute("Drop pipe If Exists a2b"); | ||
| } catch (SQLException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public void testBasicAlterPipeIfExists() throws Exception { | ||
| final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0); | ||
|
|
||
| // Alter pipe If Exists | ||
| String sql = | ||
| String.format( | ||
| "Alter pipe If Exists a2b replace sink ('node-urls'='%s')", | ||
| receiverDataNode.getIpAndPortString()); | ||
| try (final Connection connection = senderEnv.getConnection(); | ||
| final Statement statement = connection.createStatement()) { | ||
| statement.execute(sql); | ||
| } catch (SQLException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
|
|
||
| // show pipe | ||
| try (final SyncConfigNodeIServiceClient client = | ||
| (SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) { | ||
| final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList; | ||
| Assert.assertEquals(0, showPipeResult.size()); | ||
| } | ||
|
|
||
| // Create pipe | ||
| sql = | ||
| String.format( | ||
| "create pipe If Not Exists a2b with source ('source'='iotdb-source', 'source.pattern'='root.test1', 'source.realtime.mode'='stream') with processor ('processor'='do-nothing-processor') with sink ('node-urls'='%s')", | ||
| receiverDataNode.getIpAndPortString()); | ||
| try (final Connection connection = senderEnv.getConnection(); | ||
| final Statement statement = connection.createStatement()) { | ||
| statement.execute(sql); | ||
| } catch (SQLException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
|
|
||
| // Alter pipe If Exists | ||
| sql = | ||
| String.format( | ||
| "Alter pipe If Exists a2b replace source () replace processor () replace sink ('node-urls'='%s')", | ||
| receiverDataNode.getIpAndPortString()); | ||
| try (final Connection connection = senderEnv.getConnection(); | ||
| final Statement statement = connection.createStatement()) { | ||
| statement.execute(sql); | ||
| } catch (SQLException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
|
|
||
| // show pipe | ||
| try (final SyncConfigNodeIServiceClient client = | ||
| (SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) { | ||
| final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList; | ||
| Assert.assertEquals(1, showPipeResult.size()); | ||
| // Check status | ||
| Assert.assertEquals("RUNNING", showPipeResult.get(0).state); | ||
| // Check configurations | ||
| Assert.assertFalse(showPipeResult.get(0).pipeExtractor.contains("source=iotdb-source")); | ||
| Assert.assertFalse(showPipeResult.get(0).pipeExtractor.contains("source.pattern=root.test1")); | ||
| Assert.assertFalse( | ||
| showPipeResult.get(0).pipeExtractor.contains("source.realtime.mode=stream")); | ||
| Assert.assertFalse( | ||
| showPipeResult.get(0).pipeProcessor.contains("processor=do-nothing-processor")); | ||
| Assert.assertTrue( | ||
| showPipeResult | ||
| .get(0) | ||
| .pipeConnector | ||
| .contains(String.format("node-urls=%s", receiverDataNode.getIpAndPortString()))); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.