Skip to content

Commit 689fc36

Browse files
committed
ifx
1 parent f818e4b commit 689fc36

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/pipe/PipePluginInfo.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,16 @@ public TSStatus createPipePlugin(final CreatePipePluginPlan createPipePluginPlan
215215
final String className = pipePluginMeta.getClassName();
216216
final String jarName = pipePluginMeta.getJarName();
217217

218-
// try to drop the old pipe plugin if exists to reduce the effect of the inconsistency
219-
dropPipePlugin(new DropPipePluginPlan(pluginName));
220-
221218
if (createPipePluginPlan.getJarFile() != null) {
222-
pipePluginExecutableManager.savePluginToInstallDir(
223-
ByteBuffer.wrap(createPipePluginPlan.getJarFile().getValues()), pluginName, jarName);
224-
computeFromPluginClass(pluginName, className);
219+
try {
220+
pipePluginExecutableManager.savePluginToInstallDir(
221+
ByteBuffer.wrap(createPipePluginPlan.getJarFile().getValues()), pluginName, jarName);
222+
computeFromPluginClass(pluginName, className);
223+
} catch (final Exception e) {
224+
// We need to rollback if the creation has failed
225+
pipePluginExecutableManager.removePluginFileUnderLibRoot(pluginName, jarName);
226+
throw e;
227+
}
225228
} else {
226229
final String existed = pipePluginMetaKeeper.getPluginNameByJarName(jarName);
227230
if (Objects.nonNull(existed)) {
@@ -235,6 +238,9 @@ public TSStatus createPipePlugin(final CreatePipePluginPlan createPipePluginPlan
235238
}
236239
}
237240

241+
// try to drop the old pipe plugin if exists to reduce the effect of the inconsistency
242+
dropPipePlugin(new DropPipePluginPlan(pluginName));
243+
238244
pipePluginMetaKeeper.addPipePluginMeta(pluginName, pipePluginMeta);
239245
pipePluginMetaKeeper.addJarNameAndMd5(jarName, pipePluginMeta.getJarMD5());
240246

iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/PipeInfoTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.apache.iotdb.confignode.consensus.request.write.pipe.task.DropPipePlanV2;
3232
import org.apache.iotdb.confignode.consensus.request.write.pipe.task.SetPipeStatusPlanV2;
3333
import org.apache.iotdb.confignode.persistence.pipe.PipeInfo;
34+
import org.apache.iotdb.pipe.api.exception.PipeException;
35+
import org.apache.iotdb.rpc.TSStatusCode;
3436

3537
import org.apache.thrift.TException;
3638
import org.apache.tsfile.common.conf.TSFileConfig;
@@ -149,10 +151,18 @@ public void testManagement() {
149151
new CreatePipePluginPlan(
150152
new PipePluginMeta(pluginName, "org.apache.iotdb.TestJar", false, "test.jar", "???"),
151153
new Binary("123", TSFileConfig.STRING_CHARSET));
152-
pipeInfo.getPipePluginInfo().createPipePlugin(createPipePluginPlan);
153154

154-
// Drop pipe plugin test plugin
155-
pipeInfo.getPipePluginInfo().validateBeforeDroppingPipePlugin(pluginName, false);
155+
// Shall fail due to validation
156+
Assert.assertEquals(
157+
TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode(),
158+
pipeInfo.getPipePluginInfo().createPipePlugin(createPipePluginPlan).getCode());
159+
160+
// Drop pipe plugin test plugin, validation failure
161+
Assert.assertThrows(
162+
PipeException.class,
163+
() -> pipeInfo.getPipePluginInfo().validateBeforeDroppingPipePlugin(pluginName, false));
164+
165+
// Idempotent
156166
DropPipePluginPlan dropPipePluginPlan = new DropPipePluginPlan(pluginName);
157167
pipeInfo.getPipePluginInfo().dropPipePlugin(dropPipePluginPlan);
158168
}

0 commit comments

Comments
 (0)