@@ -215,16 +215,8 @@ 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-
221- pipePluginMetaKeeper .addPipePluginMeta (pluginName , pipePluginMeta );
222- pipePluginMetaKeeper .addJarNameAndMd5 (jarName , pipePluginMeta .getJarMD5 ());
223-
224218 if (createPipePluginPlan .getJarFile () != null ) {
225- pipePluginExecutableManager .savePluginToInstallDir (
226- ByteBuffer .wrap (createPipePluginPlan .getJarFile ().getValues ()), pluginName , jarName );
227- computeFromPluginClass (pluginName , className );
219+ savePipePluginWithRollback (createPipePluginPlan );
228220 } else {
229221 final String existed = pipePluginMetaKeeper .getPluginNameByJarName (jarName );
230222 if (Objects .nonNull (existed )) {
@@ -238,6 +230,12 @@ public TSStatus createPipePlugin(final CreatePipePluginPlan createPipePluginPlan
238230 }
239231 }
240232
233+ // try to drop the old pipe plugin if exists to reduce the effect of the inconsistency
234+ dropPipePlugin (new DropPipePluginPlan (pluginName ));
235+
236+ pipePluginMetaKeeper .addPipePluginMeta (pluginName , pipePluginMeta );
237+ pipePluginMetaKeeper .addJarNameAndMd5 (jarName , pipePluginMeta .getJarMD5 ());
238+
241239 return new TSStatus (TSStatusCode .SUCCESS_STATUS .getStatusCode ());
242240 } catch (final Exception e ) {
243241 final String errorMessage =
@@ -250,6 +248,23 @@ public TSStatus createPipePlugin(final CreatePipePluginPlan createPipePluginPlan
250248 }
251249 }
252250
251+ private void savePipePluginWithRollback (final CreatePipePluginPlan createPipePluginPlan )
252+ throws Exception {
253+ final PipePluginMeta pipePluginMeta = createPipePluginPlan .getPipePluginMeta ();
254+ final String pluginName = pipePluginMeta .getPluginName ();
255+ final String className = pipePluginMeta .getClassName ();
256+ final String jarName = pipePluginMeta .getJarName ();
257+ try {
258+ pipePluginExecutableManager .savePluginToInstallDir (
259+ ByteBuffer .wrap (createPipePluginPlan .getJarFile ().getValues ()), pluginName , jarName );
260+ computeFromPluginClass (pluginName , className );
261+ } catch (final Exception e ) {
262+ // We need to rollback if the creation has failed
263+ pipePluginExecutableManager .removePluginFileUnderLibRoot (pluginName , jarName );
264+ throw e ;
265+ }
266+ }
267+
253268 private void computeFromPluginClass (final String pluginName , final String className )
254269 throws Exception {
255270 final String pluginDirPath = pipePluginExecutableManager .getPluginsDirPath (pluginName );
0 commit comments