Skip to content

Commit 5ad4a94

Browse files
Remove all kinds of ProcedureException's subclass & Fix a security problem (apache#15563)
1 parent 95648df commit 5ad4a94

Some content is hidden

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

43 files changed

+51
-304
lines changed

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/InternalProcedure.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package org.apache.iotdb.confignode.procedure;
2121

22-
import org.apache.iotdb.confignode.procedure.exception.ProcedureSuspendedException;
23-
import org.apache.iotdb.confignode.procedure.exception.ProcedureYieldException;
24-
2522
import java.io.IOException;
2623
import java.nio.ByteBuffer;
2724

@@ -38,8 +35,7 @@ protected InternalProcedure(long toMillis) {
3835
protected abstract void periodicExecute(final Env env);
3936

4037
@Override
41-
protected Procedure<Env>[] execute(Env env)
42-
throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException {
38+
protected Procedure<Env>[] execute(Env env) throws InterruptedException {
4339
throw new UnsupportedOperationException();
4440
}
4541

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/Procedure.java

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
package org.apache.iotdb.confignode.procedure;
2121

2222
import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
23-
import org.apache.iotdb.confignode.procedure.exception.ProcedureAbortedException;
2423
import org.apache.iotdb.confignode.procedure.exception.ProcedureException;
25-
import org.apache.iotdb.confignode.procedure.exception.ProcedureSuspendedException;
26-
import org.apache.iotdb.confignode.procedure.exception.ProcedureTimeoutException;
27-
import org.apache.iotdb.confignode.procedure.exception.ProcedureYieldException;
2824
import org.apache.iotdb.confignode.procedure.state.ProcedureLockState;
2925
import org.apache.iotdb.confignode.procedure.state.ProcedureState;
3026
import org.apache.iotdb.confignode.procedure.store.IProcedureStore;
@@ -34,7 +30,6 @@
3430

3531
import java.io.DataOutputStream;
3632
import java.io.IOException;
37-
import java.lang.reflect.InvocationTargetException;
3833
import java.nio.ByteBuffer;
3934
import java.nio.charset.StandardCharsets;
4035
import java.util.ArrayList;
@@ -83,14 +78,9 @@ public final boolean hasLock() {
8378
* @param env the environment passed to the ProcedureExecutor
8479
* @return a set of sub-procedures to run or ourselves if there is more work to do or null if the
8580
* procedure is done.
86-
* @throws ProcedureYieldException the procedure will be added back to the queue and retried
87-
* later.
8881
* @throws InterruptedException the procedure will be added back to the queue and retried later.
89-
* @throws ProcedureSuspendedException Signal to the executor that Procedure has suspended itself
90-
* and has set itself up waiting for an external event to wake it back up again.
9182
*/
92-
protected abstract Procedure<Env>[] execute(Env env)
93-
throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException;
83+
protected abstract Procedure<Env>[] execute(Env env) throws InterruptedException;
9484

9585
/**
9686
* The code to undo what was done by the execute() code. It is called when the procedure or one of
@@ -130,11 +120,14 @@ public void serialize(DataOutputStream stream) throws IOException {
130120

131121
// exceptions
132122
if (hasException()) {
123+
// symbol of exception
133124
stream.write((byte) 1);
125+
// exception's name
134126
String exceptionClassName = exception.getClass().getName();
135127
byte[] exceptionClassNameBytes = exceptionClassName.getBytes(StandardCharsets.UTF_8);
136128
stream.writeInt(exceptionClassNameBytes.length);
137129
stream.write(exceptionClassNameBytes);
130+
// exception's message
138131
String message = this.exception.getMessage();
139132
if (message != null) {
140133
byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
@@ -144,6 +137,7 @@ public void serialize(DataOutputStream stream) throws IOException {
144137
stream.writeInt(-1);
145138
}
146139
} else {
140+
// symbol of no exception
147141
stream.write((byte) 0);
148142
}
149143

@@ -181,29 +175,18 @@ public void deserialize(ByteBuffer byteBuffer) {
181175
}
182176
this.setStackIndexes(indexList);
183177
}
184-
// exceptions
178+
179+
// exception
185180
if (byteBuffer.get() == 1) {
186-
Class<?> exceptionClass = deserializeTypeInfo(byteBuffer);
181+
deserializeTypeInfoForCompatibility(byteBuffer);
187182
int messageBytesLength = byteBuffer.getInt();
188183
String errMsg = null;
189184
if (messageBytesLength > 0) {
190185
byte[] messageBytes = new byte[messageBytesLength];
191186
byteBuffer.get(messageBytes);
192187
errMsg = new String(messageBytes, StandardCharsets.UTF_8);
193188
}
194-
ProcedureException exception;
195-
try {
196-
exception =
197-
(ProcedureException) exceptionClass.getConstructor(String.class).newInstance(errMsg);
198-
} catch (InstantiationException
199-
| IllegalAccessException
200-
| InvocationTargetException
201-
| NoSuchMethodException e) {
202-
LOG.warn("Instantiation exception class failed", e);
203-
exception = new ProcedureException(errMsg);
204-
}
205-
206-
setFailure(exception);
189+
setFailure(new ProcedureException(errMsg));
207190
}
208191

209192
// result
@@ -224,18 +207,11 @@ public void deserialize(ByteBuffer byteBuffer) {
224207
* @param byteBuffer bytebuffer
225208
* @return Procedure
226209
*/
227-
public static Class<?> deserializeTypeInfo(ByteBuffer byteBuffer) {
210+
@Deprecated
211+
public static void deserializeTypeInfoForCompatibility(ByteBuffer byteBuffer) {
228212
int classNameBytesLen = byteBuffer.getInt();
229213
byte[] classNameBytes = new byte[classNameBytesLen];
230214
byteBuffer.get(classNameBytes);
231-
String className = new String(classNameBytes, StandardCharsets.UTF_8);
232-
Class<?> clazz;
233-
try {
234-
clazz = Class.forName(className);
235-
} catch (ClassNotFoundException e) {
236-
throw new RuntimeException("Invalid procedure class", e);
237-
}
238-
return clazz;
239215
}
240216

241217
/**
@@ -284,8 +260,7 @@ protected boolean isYieldAfterExecution(Env env) {
284260
* @param env execute environment
285261
* @return sub procedures
286262
*/
287-
protected Procedure<Env>[] doExecute(Env env)
288-
throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException {
263+
protected Procedure<Env>[] doExecute(Env env) throws InterruptedException {
289264
try {
290265
updateTimestamp();
291266
return execute(env);
@@ -676,20 +651,9 @@ protected synchronized void setFailure(final ProcedureException exception) {
676651
}
677652
}
678653

679-
protected void setAbortFailure(final String source, final String msg) {
680-
setFailure(source, new ProcedureAbortedException(msg));
681-
}
682-
683654
/**
684655
* Called by the ProcedureExecutor when the timeout set by setTimeout() is expired.
685656
*
686-
* <p>Another usage for this method is to implement retrying. A procedure can set the state to
687-
* {@code WAITING_TIMEOUT} by calling {@code setState} method, and throw a {@link
688-
* ProcedureSuspendedException} to halt the execution of the procedure, and do not forget a call
689-
* {@link #setTimeout(long)} method to set the timeout. And you should also override this method
690-
* to wake up the procedure, and also return false to tell the ProcedureExecutor that the timeout
691-
* event has been handled.
692-
*
693657
* @return true to let the framework handle the timeout as abort, false in case the procedure
694658
* handled the timeout itself.
695659
*/
@@ -698,7 +662,7 @@ protected synchronized boolean setTimeoutFailure(Env env) {
698662
long timeDiff = System.currentTimeMillis() - lastUpdate;
699663
setFailure(
700664
"ProcedureExecutor",
701-
new ProcedureTimeoutException("Operation timed out after " + timeDiff + " ms."));
665+
new ProcedureException("Operation timed out after " + timeDiff + " ms."));
702666
return true;
703667
}
704668
return false;

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/ProcedureExecutor.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.iotdb.commons.utils.TestOnly;
2424
import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
2525
import org.apache.iotdb.confignode.procedure.exception.ProcedureException;
26-
import org.apache.iotdb.confignode.procedure.exception.ProcedureYieldException;
2726
import org.apache.iotdb.confignode.procedure.scheduler.ProcedureScheduler;
2827
import org.apache.iotdb.confignode.procedure.scheduler.SimpleProcedureScheduler;
2928
import org.apache.iotdb.confignode.procedure.state.ProcedureLockState;
@@ -417,9 +416,6 @@ private void executeProcedure(RootProcedureStack rootProcStack, Procedure<Env> p
417416
if (subprocs != null && subprocs.length == 0) {
418417
subprocs = null;
419418
}
420-
} catch (ProcedureYieldException e) {
421-
LOG.debug("Yield {}", proc);
422-
yieldProcedure(proc);
423419
} catch (InterruptedException e) {
424420
LOG.warn("Interrupt during execution, suspend or retry it later.", e);
425421
yieldProcedure(proc);

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/exception/ProcedureAbortedException.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/exception/ProcedureSuspendedException.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/exception/ProcedureTimeoutException.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/exception/ProcedureYieldException.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/StateMachineProcedure.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import org.apache.iotdb.confignode.procedure.Procedure;
2323
import org.apache.iotdb.confignode.procedure.exception.ProcedureException;
24-
import org.apache.iotdb.confignode.procedure.exception.ProcedureSuspendedException;
25-
import org.apache.iotdb.confignode.procedure.exception.ProcedureYieldException;
2624

2725
import org.apache.thrift.annotation.Nullable;
2826
import org.slf4j.Logger;
@@ -90,8 +88,7 @@ protected final int getCycles() {
9088
* @return Flow.NO_MORE_STATE if the procedure is completed, Flow.HAS_MORE_STATE if there is
9189
* another step.
9290
*/
93-
protected abstract Flow executeFromState(Env env, TState state)
94-
throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException;
91+
protected abstract Flow executeFromState(Env env, TState state) throws InterruptedException;
9592

9693
/**
9794
* Called to perform the rollback of the specified state.
@@ -144,8 +141,7 @@ protected void addChildProcedure(Procedure<Env> childProcedure) {
144141
}
145142

146143
@Override
147-
protected Procedure<Env>[] execute(final Env env)
148-
throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
144+
protected Procedure<Env>[] execute(final Env env) throws InterruptedException {
149145
updateTimestamp();
150146
try {
151147
if (noMoreState() || isFailed()) {

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/cq/CreateCQProcedure.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import org.apache.iotdb.confignode.manager.cq.CQScheduleTask;
2929
import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
3030
import org.apache.iotdb.confignode.procedure.exception.ProcedureException;
31-
import org.apache.iotdb.confignode.procedure.exception.ProcedureSuspendedException;
32-
import org.apache.iotdb.confignode.procedure.exception.ProcedureYieldException;
3331
import org.apache.iotdb.confignode.procedure.impl.node.AbstractNodeProcedure;
3432
import org.apache.iotdb.confignode.procedure.state.cq.CreateCQState;
3533
import org.apache.iotdb.confignode.procedure.store.ProcedureType;
@@ -84,7 +82,7 @@ public CreateCQProcedure(TCreateCQReq req, ScheduledExecutorService executor) {
8482

8583
@Override
8684
protected Flow executeFromState(ConfigNodeProcedureEnv env, CreateCQState state)
87-
throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
85+
throws InterruptedException {
8886

8987
try {
9088
switch (state) {

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/node/RemoveAINodeProcedure.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import org.apache.iotdb.confignode.consensus.request.write.model.DropModelInNodePlan;
2727
import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
2828
import org.apache.iotdb.confignode.procedure.exception.ProcedureException;
29-
import org.apache.iotdb.confignode.procedure.exception.ProcedureSuspendedException;
30-
import org.apache.iotdb.confignode.procedure.exception.ProcedureYieldException;
3129
import org.apache.iotdb.confignode.procedure.state.RemoveAINodeState;
3230
import org.apache.iotdb.confignode.procedure.store.ProcedureType;
3331
import org.apache.iotdb.rpc.TSStatusCode;
@@ -58,7 +56,7 @@ public RemoveAINodeProcedure() {
5856

5957
@Override
6058
protected Flow executeFromState(ConfigNodeProcedureEnv env, RemoveAINodeState state)
61-
throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
59+
throws InterruptedException {
6260
if (removedAINode == null) {
6361
return Flow.NO_MORE_STATE;
6462
}

0 commit comments

Comments
 (0)