Re: [PR] Pipe: support alter pipe functionality [iotdb]

2024-01-30 Thread via GitHub


SteveYurongSu commented on code in PR #11963:
URL: https://github.com/apache/iotdb/pull/11963#discussion_r1470996152


##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java:
##
@@ -0,0 +1,299 @@
+/*
+ * 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.confignode.procedure.impl.pipe.task;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.consensus.index.impl.MinimumProgressIndex;
+import org.apache.iotdb.commons.pipe.task.meta.PipeRuntimeMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStaticMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStatus;
+import org.apache.iotdb.commons.pipe.task.meta.PipeTaskMeta;
+import org.apache.iotdb.commons.schema.SchemaConstant;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.AlterPipePlanV2;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.DropPipePlanV2;
+import org.apache.iotdb.confignode.manager.pipe.coordinator.PipeManager;
+import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
+import 
org.apache.iotdb.confignode.procedure.impl.pipe.AbstractOperatePipeProcedureV2;
+import org.apache.iotdb.confignode.procedure.impl.pipe.PipeTaskOperation;
+import org.apache.iotdb.confignode.procedure.store.ProcedureType;
+import org.apache.iotdb.confignode.rpc.thrift.TAlterPipeReq;
+import org.apache.iotdb.consensus.exception.ConsensusException;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class AlterPipeProcedureV2 extends AbstractOperatePipeProcedureV2 {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(AlterPipeProcedureV2.class);
+
+  private TAlterPipeReq alterPipeRequest;
+
+  private PipeStaticMeta pipeStaticMeta;
+  private PipeRuntimeMeta pipeRuntimeMeta;
+
+  public AlterPipeProcedureV2() {
+super();
+  }
+
+  public AlterPipeProcedureV2(TAlterPipeReq alterPipeRequest) throws 
PipeException {
+super();
+this.alterPipeRequest = alterPipeRequest;
+  }
+
+  @Override
+  protected PipeTaskOperation getOperation() {
+return PipeTaskOperation.ALTER_PIPE;
+  }
+
+  @Override
+  protected boolean executeFromValidateTask(ConfigNodeProcedureEnv env) throws 
PipeException {
+LOGGER.info(
+"AlterPipeProcedureV2: executeFromValidateTask({})", 
alterPipeRequest.getPipeName());
+
+final PipeManager pipeManager = env.getConfigManager().getPipeManager();
+pipeManager
+.getPipePluginCoordinator()
+.getPipePluginInfo()
+.checkPipePluginExistence(
+alterPipeRequest.getExtractorAttributes(),
+alterPipeRequest.getProcessorAttributes(),
+alterPipeRequest.getConnectorAttributes());
+pipeTaskInfo.get().checkBeforeAlterPipe(alterPipeRequest);
+
+return false;
+  }
+
+  @Override
+  protected void executeFromCalculateInfoForTask(ConfigNodeProcedureEnv env) {
+LOGGER.info(
+"AlterPipeProcedureV2: executeFromCalculateInfoForTask({})",
+alterPipeRequest.getPipeName());
+
+pipeStaticMeta =
+new PipeStaticMeta(
+alterPipeRequest.getPipeName(),
+System.currentTimeMillis(),
+alterPipeRequest.getExtractorAttributes(),
+alterPipeRequest.getProcessorAttributes(),
+alterPipeRequest.getConnectorAttributes());
+
+final Map consensusGroupIdToTaskMetaMap = 
new HashMap<>();
+env.getConfigManager()
+.getLoadManager()
+.getRegionLeaderMap()
+.forEach(
+(regionGroupId, regionLeaderNodeId) -> {
+  if 
(regionGroupId.getType().equals(TConsensusGroupType.DataRegion)) {
+final String databa

Re: [PR] Pipe: support alter pipe functionality [iotdb]

2024-01-30 Thread via GitHub


SteveYurongSu commented on code in PR #11963:
URL: https://github.com/apache/iotdb/pull/11963#discussion_r1470982135


##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java:
##
@@ -0,0 +1,299 @@
+/*
+ * 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.confignode.procedure.impl.pipe.task;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.consensus.index.impl.MinimumProgressIndex;
+import org.apache.iotdb.commons.pipe.task.meta.PipeRuntimeMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStaticMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStatus;
+import org.apache.iotdb.commons.pipe.task.meta.PipeTaskMeta;
+import org.apache.iotdb.commons.schema.SchemaConstant;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.AlterPipePlanV2;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.DropPipePlanV2;
+import org.apache.iotdb.confignode.manager.pipe.coordinator.PipeManager;
+import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
+import 
org.apache.iotdb.confignode.procedure.impl.pipe.AbstractOperatePipeProcedureV2;
+import org.apache.iotdb.confignode.procedure.impl.pipe.PipeTaskOperation;
+import org.apache.iotdb.confignode.procedure.store.ProcedureType;
+import org.apache.iotdb.confignode.rpc.thrift.TAlterPipeReq;
+import org.apache.iotdb.consensus.exception.ConsensusException;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class AlterPipeProcedureV2 extends AbstractOperatePipeProcedureV2 {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(AlterPipeProcedureV2.class);
+
+  private TAlterPipeReq alterPipeRequest;
+
+  private PipeStaticMeta pipeStaticMeta;
+  private PipeRuntimeMeta pipeRuntimeMeta;
+
+  public AlterPipeProcedureV2() {
+super();
+  }
+
+  public AlterPipeProcedureV2(TAlterPipeReq alterPipeRequest) throws 
PipeException {
+super();
+this.alterPipeRequest = alterPipeRequest;
+  }
+
+  @Override
+  protected PipeTaskOperation getOperation() {
+return PipeTaskOperation.ALTER_PIPE;
+  }
+
+  @Override
+  protected boolean executeFromValidateTask(ConfigNodeProcedureEnv env) throws 
PipeException {
+LOGGER.info(
+"AlterPipeProcedureV2: executeFromValidateTask({})", 
alterPipeRequest.getPipeName());
+
+final PipeManager pipeManager = env.getConfigManager().getPipeManager();
+pipeManager
+.getPipePluginCoordinator()
+.getPipePluginInfo()
+.checkPipePluginExistence(
+alterPipeRequest.getExtractorAttributes(),
+alterPipeRequest.getProcessorAttributes(),
+alterPipeRequest.getConnectorAttributes());
+pipeTaskInfo.get().checkBeforeAlterPipe(alterPipeRequest);
+
+return false;
+  }
+
+  @Override
+  protected void executeFromCalculateInfoForTask(ConfigNodeProcedureEnv env) {
+LOGGER.info(
+"AlterPipeProcedureV2: executeFromCalculateInfoForTask({})",
+alterPipeRequest.getPipeName());
+
+pipeStaticMeta =
+new PipeStaticMeta(
+alterPipeRequest.getPipeName(),
+System.currentTimeMillis(),
+alterPipeRequest.getExtractorAttributes(),
+alterPipeRequest.getProcessorAttributes(),
+alterPipeRequest.getConnectorAttributes());
+
+final Map consensusGroupIdToTaskMetaMap = 
new HashMap<>();
+env.getConfigManager()
+.getLoadManager()
+.getRegionLeaderMap()
+.forEach(
+(regionGroupId, regionLeaderNodeId) -> {
+  if 
(regionGroupId.getType().equals(TConsensusGroupType.DataRegion)) {
+final String databa

Re: [PR] Pipe: support alter pipe functionality [iotdb]

2024-01-30 Thread via GitHub


SteveYurongSu commented on code in PR #11963:
URL: https://github.com/apache/iotdb/pull/11963#discussion_r1470954954


##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java:
##
@@ -0,0 +1,299 @@
+/*
+ * 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.confignode.procedure.impl.pipe.task;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.consensus.index.impl.MinimumProgressIndex;
+import org.apache.iotdb.commons.pipe.task.meta.PipeRuntimeMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStaticMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStatus;
+import org.apache.iotdb.commons.pipe.task.meta.PipeTaskMeta;
+import org.apache.iotdb.commons.schema.SchemaConstant;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.AlterPipePlanV2;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.DropPipePlanV2;
+import org.apache.iotdb.confignode.manager.pipe.coordinator.PipeManager;
+import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
+import 
org.apache.iotdb.confignode.procedure.impl.pipe.AbstractOperatePipeProcedureV2;
+import org.apache.iotdb.confignode.procedure.impl.pipe.PipeTaskOperation;
+import org.apache.iotdb.confignode.procedure.store.ProcedureType;
+import org.apache.iotdb.confignode.rpc.thrift.TAlterPipeReq;
+import org.apache.iotdb.consensus.exception.ConsensusException;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class AlterPipeProcedureV2 extends AbstractOperatePipeProcedureV2 {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(AlterPipeProcedureV2.class);
+
+  private TAlterPipeReq alterPipeRequest;
+
+  private PipeStaticMeta pipeStaticMeta;
+  private PipeRuntimeMeta pipeRuntimeMeta;
+
+  public AlterPipeProcedureV2() {
+super();
+  }
+
+  public AlterPipeProcedureV2(TAlterPipeReq alterPipeRequest) throws 
PipeException {
+super();
+this.alterPipeRequest = alterPipeRequest;
+  }
+
+  @Override
+  protected PipeTaskOperation getOperation() {
+return PipeTaskOperation.ALTER_PIPE;
+  }
+
+  @Override
+  protected boolean executeFromValidateTask(ConfigNodeProcedureEnv env) throws 
PipeException {
+LOGGER.info(
+"AlterPipeProcedureV2: executeFromValidateTask({})", 
alterPipeRequest.getPipeName());
+
+final PipeManager pipeManager = env.getConfigManager().getPipeManager();
+pipeManager
+.getPipePluginCoordinator()
+.getPipePluginInfo()
+.checkPipePluginExistence(
+alterPipeRequest.getExtractorAttributes(),
+alterPipeRequest.getProcessorAttributes(),
+alterPipeRequest.getConnectorAttributes());
+pipeTaskInfo.get().checkBeforeAlterPipe(alterPipeRequest);
+
+return false;
+  }
+
+  @Override
+  protected void executeFromCalculateInfoForTask(ConfigNodeProcedureEnv env) {
+LOGGER.info(
+"AlterPipeProcedureV2: executeFromCalculateInfoForTask({})",
+alterPipeRequest.getPipeName());
+
+pipeStaticMeta =
+new PipeStaticMeta(
+alterPipeRequest.getPipeName(),
+System.currentTimeMillis(),
+alterPipeRequest.getExtractorAttributes(),
+alterPipeRequest.getProcessorAttributes(),
+alterPipeRequest.getConnectorAttributes());
+
+final Map consensusGroupIdToTaskMetaMap = 
new HashMap<>();
+env.getConfigManager()
+.getLoadManager()
+.getRegionLeaderMap()
+.forEach(
+(regionGroupId, regionLeaderNodeId) -> {
+  if 
(regionGroupId.getType().equals(TConsensusGroupType.DataRegion)) {
+final String databa

Re: [PR] Pipe: support alter pipe functionality [iotdb]

2024-01-30 Thread via GitHub


Caideyipi commented on code in PR #11963:
URL: https://github.com/apache/iotdb/pull/11963#discussion_r1470885629


##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/AbstractOperatePipeProcedureV2.java:
##
@@ -50,9 +50,9 @@
 import java.util.concurrent.atomic.AtomicReference;
 
 /**
- * This procedure manages 4 kinds of PIPE operations: {@link 
PipeTaskOperation#CREATE_PIPE}, {@link
- * PipeTaskOperation#START_PIPE}, {@link PipeTaskOperation#STOP_PIPE} and 
{@link
- * PipeTaskOperation#DROP_PIPE}.
+ * This procedure manages 5 kinds of PIPE operations: {@link 
PipeTaskOperation#CREATE_PIPE}, {@link
+ * PipeTaskOperation#START_PIPE}, {@link PipeTaskOperation#STOP_PIPE}, {@link
+ * PipeTaskOperation#DROP_PIPE} and {@link PipeTaskOperation#ALTER_PIPE}.

Review Comment:
   Maybe separately explain user operation like "CREATE PIPE" and runtime 
operation like "SYNC_PIPE_META" is better.



##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/pipe/PipeTaskInfo.java:
##
@@ -158,6 +162,60 @@ private void checkBeforeCreatePipeInternal(TCreatePipeReq 
createPipeRequest)
 throw new PipeException(exceptionMessage);
   }
 
+  public void checkBeforeAlterPipe(TAlterPipeReq alterPipeRequest) throws 
PipeException {
+acquireReadLock();
+try {
+  checkBeforeAlterPipeInternal(alterPipeRequest);
+} finally {
+  releaseReadLock();
+}
+  }
+
+  private void checkBeforeAlterPipeInternal(TAlterPipeReq alterPipeRequest) 
throws PipeException {
+if (!isPipeExisted(alterPipeRequest.getPipeName())) {
+  final String exceptionMessage =
+  String.format(
+  "Failed to alter pipe %s, the pipe does not exist", 
alterPipeRequest.getPipeName());
+  LOGGER.info(exceptionMessage);
+  throw new PipeException(exceptionMessage);
+}
+
+PipeMeta pipeMetaFromCoordinator = 
getPipeMetaByPipeName(alterPipeRequest.getPipeName());
+PipeStaticMeta pipeStaticMetaFromCoordinator = 
pipeMetaFromCoordinator.getStaticMeta();
+// check unexpected pipe source plugin alter
+if (!(new 
TreeMap<>(pipeStaticMetaFromCoordinator.getExtractorParameters().getAttribute())
+.toString())
+.equals(new 
TreeMap<>(alterPipeRequest.getExtractorAttributes()).toString())) {
+  final String exceptionMessage =
+  String.format(
+  "Failed to alter pipe %s, unexpected pipe source plugin alter, 
source plugin from CN: %s, source plugin from DN: %s",

Review Comment:
   This error message can be slightly clearer



##
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java:
##
@@ -1655,6 +1660,91 @@ public SettableFuture 
createPipe(CreatePipeStatement createPip
 return future;
   }
 
+  @Override
+  public SettableFuture alterPipe(AlterPipeStatement 
alterPipeStatement) {
+SettableFuture future = SettableFuture.create();
+
+// Get pipe static meta
+final String pipeName = alterPipeStatement.getPipeName();
+final PipeStaticMeta pipeStaticMeta = 
PipeAgent.task().getPipeStaticMeta(pipeName);
+if (Objects.isNull(pipeStaticMeta)) {
+  future.setException(
+  new IoTDBException(
+  String.format("Failed to alter pipe %s, the pipe does not 
exist", pipeName),
+  TSStatusCode.PIPE_ERROR.getStatusCode()));
+  return future;
+}
+
+// We do not support alter source plugin of pipe, so the previous 
configuration will be reused.
+alterPipeStatement.setExtractorAttributes(

Review Comment:
   I suggest pass the order directly to configNode here without checking logic 
other than the checks in PipePluginAgent.



##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/pipe/PipeTaskInfo.java:
##
@@ -283,6 +341,19 @@ public TSStatus createPipe(CreatePipePlanV2 plan) {
 }
   }
 
+  public TSStatus alterPipe(AlterPipePlanV2 plan) {
+acquireWriteLock();
+try {
+  pipeMetaKeeper.removePipeMeta(plan.getPipeStaticMeta().getPipeName());
+  pipeMetaKeeper.addPipeMeta(
+  plan.getPipeStaticMeta().getPipeName(),
+  new PipeMeta(plan.getPipeStaticMeta(), plan.getPipeRuntimeMeta()));

Review Comment:
   I strongly suggest that updating progressIndex also here... What about DNs 
are crushed? Then they restart and fetch only a MinimumProgressIndex at 
configNode...



##
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java:
##
@@ -1655,6 +1660,91 @@ public SettableFuture 
createPipe(CreatePipeStatement createPip
 return future;
   }
 
+  @Override
+  public SettableFuture alterPipe(AlterPipeStatement 
alterPipeStatement) {
+SettableFuture future = SettableFuture.create();
+
+// Get pipe static meta
+final String pipeName = alterPipeStatement.getPipeN

Re: [PR] Pipe: support alter pipe functionality [iotdb]

2024-01-30 Thread via GitHub


SteveYurongSu commented on code in PR #11963:
URL: https://github.com/apache/iotdb/pull/11963#discussion_r1470947900


##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java:
##
@@ -0,0 +1,299 @@
+/*
+ * 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.confignode.procedure.impl.pipe.task;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.consensus.index.impl.MinimumProgressIndex;
+import org.apache.iotdb.commons.pipe.task.meta.PipeRuntimeMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStaticMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStatus;
+import org.apache.iotdb.commons.pipe.task.meta.PipeTaskMeta;
+import org.apache.iotdb.commons.schema.SchemaConstant;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.AlterPipePlanV2;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.DropPipePlanV2;
+import org.apache.iotdb.confignode.manager.pipe.coordinator.PipeManager;
+import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
+import 
org.apache.iotdb.confignode.procedure.impl.pipe.AbstractOperatePipeProcedureV2;
+import org.apache.iotdb.confignode.procedure.impl.pipe.PipeTaskOperation;
+import org.apache.iotdb.confignode.procedure.store.ProcedureType;
+import org.apache.iotdb.confignode.rpc.thrift.TAlterPipeReq;
+import org.apache.iotdb.consensus.exception.ConsensusException;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class AlterPipeProcedureV2 extends AbstractOperatePipeProcedureV2 {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(AlterPipeProcedureV2.class);
+
+  private TAlterPipeReq alterPipeRequest;
+
+  private PipeStaticMeta pipeStaticMeta;
+  private PipeRuntimeMeta pipeRuntimeMeta;
+
+  public AlterPipeProcedureV2() {
+super();
+  }
+
+  public AlterPipeProcedureV2(TAlterPipeReq alterPipeRequest) throws 
PipeException {
+super();
+this.alterPipeRequest = alterPipeRequest;
+  }
+
+  @Override
+  protected PipeTaskOperation getOperation() {
+return PipeTaskOperation.ALTER_PIPE;
+  }
+
+  @Override
+  protected boolean executeFromValidateTask(ConfigNodeProcedureEnv env) throws 
PipeException {
+LOGGER.info(
+"AlterPipeProcedureV2: executeFromValidateTask({})", 
alterPipeRequest.getPipeName());
+
+final PipeManager pipeManager = env.getConfigManager().getPipeManager();
+pipeManager
+.getPipePluginCoordinator()
+.getPipePluginInfo()
+.checkPipePluginExistence(
+alterPipeRequest.getExtractorAttributes(),
+alterPipeRequest.getProcessorAttributes(),
+alterPipeRequest.getConnectorAttributes());
+pipeTaskInfo.get().checkBeforeAlterPipe(alterPipeRequest);
+
+return false;
+  }
+
+  @Override
+  protected void executeFromCalculateInfoForTask(ConfigNodeProcedureEnv env) {
+LOGGER.info(
+"AlterPipeProcedureV2: executeFromCalculateInfoForTask({})",
+alterPipeRequest.getPipeName());
+
+pipeStaticMeta =
+new PipeStaticMeta(
+alterPipeRequest.getPipeName(),
+System.currentTimeMillis(),
+alterPipeRequest.getExtractorAttributes(),
+alterPipeRequest.getProcessorAttributes(),
+alterPipeRequest.getConnectorAttributes());
+
+final Map consensusGroupIdToTaskMetaMap = 
new HashMap<>();
+env.getConfigManager()
+.getLoadManager()
+.getRegionLeaderMap()
+.forEach(
+(regionGroupId, regionLeaderNodeId) -> {
+  if 
(regionGroupId.getType().equals(TConsensusGroupType.DataRegion)) {
+final String databa

Re: [PR] Pipe: support alter pipe functionality [iotdb]

2024-01-30 Thread via GitHub


SteveYurongSu commented on code in PR #11963:
URL: https://github.com/apache/iotdb/pull/11963#discussion_r1470799589


##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/pipe/task/AlterPipeProcedureV2.java:
##
@@ -0,0 +1,299 @@
+/*
+ * 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.confignode.procedure.impl.pipe.task;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.consensus.index.impl.MinimumProgressIndex;
+import org.apache.iotdb.commons.pipe.task.meta.PipeRuntimeMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStaticMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStatus;
+import org.apache.iotdb.commons.pipe.task.meta.PipeTaskMeta;
+import org.apache.iotdb.commons.schema.SchemaConstant;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.AlterPipePlanV2;
+import 
org.apache.iotdb.confignode.consensus.request.write.pipe.task.DropPipePlanV2;
+import org.apache.iotdb.confignode.manager.pipe.coordinator.PipeManager;
+import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
+import 
org.apache.iotdb.confignode.procedure.impl.pipe.AbstractOperatePipeProcedureV2;
+import org.apache.iotdb.confignode.procedure.impl.pipe.PipeTaskOperation;
+import org.apache.iotdb.confignode.procedure.store.ProcedureType;
+import org.apache.iotdb.confignode.rpc.thrift.TAlterPipeReq;
+import org.apache.iotdb.consensus.exception.ConsensusException;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class AlterPipeProcedureV2 extends AbstractOperatePipeProcedureV2 {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(AlterPipeProcedureV2.class);
+
+  private TAlterPipeReq alterPipeRequest;
+
+  private PipeStaticMeta pipeStaticMeta;
+  private PipeRuntimeMeta pipeRuntimeMeta;
+
+  public AlterPipeProcedureV2() {
+super();
+  }
+
+  public AlterPipeProcedureV2(TAlterPipeReq alterPipeRequest) throws 
PipeException {
+super();
+this.alterPipeRequest = alterPipeRequest;
+  }
+
+  @Override
+  protected PipeTaskOperation getOperation() {
+return PipeTaskOperation.CREATE_PIPE;

Review Comment:
   ```suggestion
   return PipeTaskOperation.ALTER_PIPE;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Pipe: support alter pipe functionality [iotdb]

2024-01-30 Thread via GitHub


SteveYurongSu commented on code in PR #11963:
URL: https://github.com/apache/iotdb/pull/11963#discussion_r1470791857


##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/pipe/PipeTaskInfo.java:
##
@@ -158,6 +162,61 @@ private void checkBeforeCreatePipeInternal(TCreatePipeReq 
createPipeRequest)
 throw new PipeException(exceptionMessage);
   }
 
+  public void checkBeforeAlterPipe(TAlterPipeReq alterPipeRequest) throws 
PipeException {
+acquireReadLock();
+try {
+  checkBeforeAlterPipeInternal(alterPipeRequest);
+} finally {
+  releaseReadLock();
+}
+  }
+
+  private void checkBeforeAlterPipeInternal(TAlterPipeReq alterPipeRequest) 
throws PipeException {
+if (isPipeExisted(alterPipeRequest.getPipeName())) {

Review Comment:
   fast failing here should be better



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Pipe: support alter pipe functionality [iotdb]

2024-01-29 Thread via GitHub


Caideyipi commented on code in PR #11963:
URL: https://github.com/apache/iotdb/pull/11963#discussion_r1470501885


##
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/pipe/task/AlterPipePlanV2.java:
##
@@ -0,0 +1,66 @@
+/*
+ * 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.confignode.consensus.request.write.pipe.task;
+
+import org.apache.iotdb.commons.pipe.task.meta.PipeRuntimeMeta;
+import org.apache.iotdb.commons.pipe.task.meta.PipeStaticMeta;
+import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
+import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+public class AlterPipePlanV2 extends ConfigPhysicalPlan {

Review Comment:
   Add a ser/de test in the "ConfigPhysicalPlanSerDeTest"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org