Skip to content

Commit

Permalink
Check that jdbc connection autocommit is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
gmokki committed Jan 14, 2020
1 parent 13106cc commit 09bc2bc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

**Details**
- `nflow-engine`
- Verify on startup that connections returned by `DataSource` used by nFlow have auto commit enabled.
- Throw `StateVariableValueTooLongException` if a state variable value that does not fit into the database column is detected. Checked in `StateExecution.setVariable`, `StateExecution.addWorkflows`, `StateExecution.addChildWorkflows`, `WorkflowInstanceService.insertWorkflowInstance` and when creating a new or updating an existing instance via REST API.
If the exception is thrown during state processing and not handled by the state implementation, nFlow engine will catch the exception and retry state processing after delay configured by property `nflow.executor.stateVariableValueTooLongRetryDelay.minutes` (default is 60).
- Fix honoring of `includeCurrentStateVariables` flag in `WorkflowInstanceService.listWorkflowInstances`. This caused major slowness when using bulk workflows.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public boolean isTransactionSupportEnabled() {
return isActualTransactionActive();
}

public boolean isAutoCommitEnabled() {
return jdbc.execute(Connection::getAutoCommit);
}

@SuppressFBWarnings(value = { "MDM_INETADDRESS_GETLOCALHOST", "WEM_WEAK_EXCEPTION_MESSAGING" }, //
justification = "localhost is used for getting host name only, exception message is fine")
private int allocateExecutorId(int hostNameMaxLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public WorkflowDispatcher(WorkflowInstanceExecutor executor, WorkflowInstanceDao
if (!executorDao.isTransactionSupportEnabled()) {
throw new BeanCreationException("Transaction support must be enabled");
}
if (!executorDao.isAutoCommitEnabled()) {
throw new BeanCreationException("DataSource must have auto commit enabled");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void setup() {
env.setProperty("nflow.executor.stateSaveRetryDelay.seconds", "60");
env.setProperty("nflow.executor.stateVariableValueTooLongRetryDelay.minutes", "60");
when(executorDao.isTransactionSupportEnabled()).thenReturn(true);
when(executorDao.isAutoCommitEnabled()).thenReturn(true);
executor = new WorkflowInstanceExecutor(3, 2, 0, 10, 0, new CustomizableThreadFactory("nflow-executor-"));
dispatcher = new WorkflowDispatcher(executor, workflowInstances, executorFactory, workflowDefinitions, executorDao, env);
Logger logger = (Logger) getLogger(ROOT_LOGGER_NAME);
Expand All @@ -100,6 +101,12 @@ public void workflowDispatcherCreationFailsWithoutTransactionSupport() {
assertThrows(BeanCreationException.class, () -> new WorkflowDispatcher(executor, workflowInstances, executorFactory, workflowDefinitions, executorDao, env));
}

@Test
public void workflowDispatcherCreationFailsWithAutoCommitDisabled() {
when(executorDao.isAutoCommitEnabled()).thenReturn(false);
assertThrows(BeanCreationException.class, () -> new WorkflowDispatcher(executor, workflowInstances, executorFactory, workflowDefinitions, executorDao, env));
}

@Test
public void exceptionDuringDispatcherExecutionCausesRetry() throws Throwable {
// TODO MultithreadedTestCase depends on junit4
Expand Down

0 comments on commit 09bc2bc

Please sign in to comment.