Enable command timeout mechanisms on top of storage interrupt
@@ -130,13 +130,19 @@ public class ODatabaseDocumentEmbedded extends ODatabaseDocumentAbstract
private OrientDBConfig config;
private OStorage storage;
- boolean interruptingCommand = false;
- InterruptTimerTask commandInterruptTimer = new InterruptTimerTask();
+ InterruptTimerTask commandInterruptTimer;
class InterruptTimerTask extends TimerTask {
+
+ Thread executionThread;
+
+ InterruptTimerTask(Thread executionThread) {
+ this.executionThread = executionThread;
+ }
+
@Override
public void run() {
- ODatabaseDocumentEmbedded.this.interruptingCommand = true;
+ interruptExecution(executionThread);
}
}
@@ -657,6 +663,14 @@ public class ODatabaseDocumentEmbedded extends ODatabaseDocumentAbstract
checkSecurity(ORule.ResourceGeneric.COMMAND, ORole.PERMISSION_EXECUTE, language);
}
+ if (OGlobalConfiguration.COMMAND_TIMEOUT.getValueAsInteger() > 0) {
+ commandInterruptTimer = new InterruptTimerTask(Thread.currentThread());
+ getSharedContext()
+ .getOrientDB()
+ .scheduleOnce(
+ commandInterruptTimer, OGlobalConfiguration.COMMAND_TIMEOUT.getValueAsInteger());
+ }
+ try {
OScriptExecutor executor =
getSharedContext()
.getOrientDB()
@@ -677,6 +691,11 @@ public class ODatabaseDocumentEmbedded extends ODatabaseDocumentAbstract
this.queryStarted(result.getQueryId(), result);
result.addLifecycleListener(this);
return result;
+ } finally {
+ if (commandInterruptTimer != null) {
+ commandInterruptTimer.cancel();
+ }
+ }
}
@Override
@@ -687,6 +706,14 @@ public class ODatabaseDocumentEmbedded extends ODatabaseDocumentAbstract
checkSecurity(ORule.ResourceGeneric.COMMAND, ORole.PERMISSION_EXECUTE, language);
}
+ if (OGlobalConfiguration.COMMAND_TIMEOUT.getValueAsInteger() > 0) {
+ commandInterruptTimer = new InterruptTimerTask(Thread.currentThread());
+ getSharedContext()
+ .getOrientDB()
+ .scheduleOnce(
+ commandInterruptTimer, OGlobalConfiguration.COMMAND_TIMEOUT.getValueAsInteger());
+ }
+ try {
OScriptExecutor executor =
sharedContext
.getOrientDB()
@@ -708,6 +735,11 @@ public class ODatabaseDocumentEmbedded extends ODatabaseDocumentAbstract
this.queryStarted(result.getQueryId(), result);
result.addLifecycleListener(this);
return result;
+ } finally {
+ if (commandInterruptTimer != null) {
+ commandInterruptTimer.cancel();
+ }
+ }
}
public OLocalResultSetLifecycleDecorator query(OExecutionPlan plan, Map<Object, Object> params) {
