Commit Graph

8835 Commits

Author SHA1 Message Date
Dan Newton
efd633c7b9 CORDA-3722 withEntityManager can rollback its session (#6187)
* CORDA-3722 withEntityManager can rollback its session

Improve the handling of database transactions when using
`withEntityManager` inside a flow.

Extra changes have been included to improve the safety and
correctness of Corda around handling database transactions.

This focuses on allowing flows to catch errors that occur inside an
entity manager and handle them accordingly.

Errors can be caught in two places:

- Inside `withEntityManager`
- Outside `withEntityManager`

Further changes have been included to ensure that transactions are
rolled back correctly.

Errors caught inside `withEntityManager` require the flow to manually
`flush` the current session (the entity manager's individual session).
By manually flushing the session, a `try-catch` block can be placed
around the `flush` call, allowing possible exceptions to be caught.

Once an error is thrown from a call to `flush`, it is no longer possible
to use the same entity manager to trigger any database operations. The
only possible option is to rollback the changes from that session.
The flow can continue executing updates within the same session but they
will never be committed. What happens in this situation should be handled
by the flow. Explicitly restricting the scenario requires a lot of effort
and code. Instead, we should rely on the developer to control complex
workflows.

To continue updating the database after an error like this occurs, a new
`withEntityManager` block should be used (after catching the previous
error).

Exceptions can be caught around `withEntityManager` blocks. This allows
errors to be handled in the same way as stated above, except the need to
manually `flush` the session is removed. `withEntityManager` will
automatically `flush` a session if it has not been marked for rollback
due to an earlier error.

A `try-catch` can then be placed around the whole of the
`withEntityManager` block, allowing the error to be caught while not
committing any changes to the underlying database transaction.

To make `withEntityManager` blocks work like mini database transactions,
save points have been utilised. A new savepoint is created when opening
a `withEntityManager` block (along with a new session). It is then used
as a reference point to rollback to if the session errors and needs to
roll back. The savepoint is then released (independently from
completing successfully or failing).

Using save points means, that either all the statements inside the
entity manager are executed, or none of them are.

- A new session is created every time an entity manager is requested,
but this does not replace the flow's main underlying database session.
- `CordaPersistence.transaction` can now determine whether it needs
to execute its extra error handling code. This is needed to allow errors
escape `withEntityManager` blocks while allowing some of our exception
handling around subscribers (in `NodeVaultService`) to continue to work.
2020-06-30 11:54:16 +01:00
Dan Newton
f6b5737277
ENT-5196 handle errors during flow initialisation (#6378)
## Summary

This change deals with multiple issues:

* Errors that occur during flow initialisation.

* Errors that occur when handling the outcome of an existing flow error.

* Failures to rollback and close a database transaction when an error
occurs in `TransitionExecutorImpl`.

* Removal of create and commit transaction actions around retrying a flow.

## Errors that occur during flow initialisation

Flow initialisation has been moved into the try/catch that exists inside
`FlowStateMachineImpl.run`. This means if an error is thrown all the way
out of `initialiseFlow` (which should rarely happen) it will be caught 
and move into a flow's standard error handling path. The flow should 
then properly terminate.

`Event.Error` was changed to make the choice to rollback be optional. 
Errors during flow initialisation cause the flow to not have a open 
database transaction. Therefore there is no need to rollback.

## Errors that occur when handling the outcome of an existing flow error

When an error occurs a flow goes to the flow hospital and is given an 
outcome event to address the original error. If the transition that was 
processing the error outcome event (`StartErrorPropagation` and
`RetryFlowFromSafePoint`) has an error then the flow aborts and
nothing happens. This means that the flow is left in a runnable state.

To resolve this, we now retry the original error outcome event whenever 
another error occurs doing so.

This is done by adding a new staff member that looks for 
`ErrorStateTransitionException` thrown in the error code path of 
`TransitionExecutorImpl`. It then takes the last outcome for that flow 
and schedules it to run again. This scheduling runs with a backoff.

This means that a flow will continually retry the original error outcome
event until it completes it successfully.

## Failures to rollback and close a database transaction when an error occurs in `TransitionExecutorImpl`
   
Rolling back and closing the database transaction inside of 
`TransitionExecutorImpl` is now done inside individual try/catch blocks
as this should not prevent the flow from continuing.

## Removal of create and commit transaction actions around retrying a flow

The database commit that occurs after retrying a flow can fail which 
required some custom code just for that event to prevent inconsistent 
behaviour. The transaction was only needed for reading checkpoints from 
the database, therefore the transaction was moved into 
`retryFlowFromSafePoint` instead and the commit removed.

If we need to commit data inside of `retryFlowFromSafePoint` in the 
future, a commit should be added directly to `retryFlowFromSafePoint`. 
The commit should occur before the flow is started on a new fiber.
2020-06-30 11:50:42 +01:00
Tamas Veingartner
18cd24c2b4
NOTICK Ignore pagination large volume test as its completion is environment dependent and might cause issues in slower environments (#6420) 2020-06-30 10:12:31 +01:00
Chris Rankin
0ddc430b4d
INRFA-415: Publish empty source and JavaDoc for deterministic modules (#6406)
Create empty source and javadoc artifacts for the deterministic modules so that they can be published to Maven Central.
2020-06-29 20:38:51 +01:00
Denis Rekalov
650a66b053
Merge pull request #6412 from corda/denis/CORDA-3856-amqp-header-os-4.6
NOTICK: OS 4.5 to 4.6 merge
2020-06-29 16:35:47 +01:00
Yash Nabar
eba7fabe5e
EG-2647: Add persistent Artemis volume (#6389) 2020-06-29 14:34:53 +01:00
Denis Rekalov
e75dc9e415 Merge branch 'release/os/4.5' into denis/CORDA-3856-amqp-header-os-4.6 2020-06-29 13:13:48 +01:00
Denis Rekalov
5228817fb4
Merge pull request #6410 from corda/denis/CORDA-3856-amqp-header-os-4.5
OS 4.4 to 4.5 merge
2020-06-29 13:10:36 +01:00
Denis Rekalov
7686ca2944 Merge branch 'release/os/4.4' into denis/CORDA-3856-amqp-header-os-4.5 2020-06-29 12:35:05 +01:00
Viktor Kolomeyko
4391585fa9
CORDA-3868: Use specific exception to determine SSL handshake timeout (#6409) 2020-06-29 12:24:03 +01:00
pnemeth
6fc9f2eacf
EG-2854 Failing Test: net.corda.node.internal.NodeStartupCliTest.--nodeconf using absolute path will not be changed (#6393)
* EG-2854

Failing Test: net.corda.node.internal.NodeStartupCliTest.--nodeconf using absolute path will not be changed

* fix bug EG-2854

* PR comment
2020-06-29 09:40:12 +01:00
Denis Rekalov
3f03de6fbd
CORDA-3856: Add Artemis plugin for validating AMQP message header and type (#6407) 2020-06-29 09:23:29 +01:00
Dan Newton
516a4bf3a1
Merge pull request #6403 from corda/NOTICK-rfowler-merge-OS4.5-OS4.6-20200626
NOTICK rfowler merge os4.5 os4.6 20200626
2020-06-29 08:40:48 +01:00
Dan Newton
796e92b512
CORDA-3720 Extract locking of InnerState out of SMM (#6289)
The state machines state is held within `InnerState` which lived inside
the SMM. `InnerState` has been extracted out of the SMM to allow the SMM
to be refactored in the future. Smaller classes can now be made that
focus on a single goal as the locking of the state can be accessed from
external classes. To achieve this, pass the `InnerState` into the class
and request a lock if needed.

The locking of `InnerState` has been made a property of the `InnerState`
itself. It has a `lock` field that allows locks to be taken out when
needed.

An inline `withLock` function has been added to tidy up the code and not
harm performance.

Some classes have been made internal to prevent invalid usage of purely
node internal classes.

As part of this change, flow timeouts have been extracted out into
`FlowTimeoutScheduler`.
2020-06-26 12:48:15 +01:00
Ryan Fowler
31a1ee8803 Merge branch 'release/os/4.5' into NOTICK-rfowler-merge-OS4.5-OS4.6-20200626 2020-06-26 12:14:56 +01:00
Dan Newton
619a2c9af3
Merge pull request #6402 from corda/NOTICK-rfowler-merge-OS4.4-OS4.5-20200626
NOTICK rfowler merge os4.4 os4.5 20200626
2020-06-26 12:12:51 +01:00
Waldemar Żurowski
b21a3c33cd
Added Sonatype check for regression builds (#6401) 2020-06-26 10:48:47 +01:00
Ryan Fowler
881d8d687c Merge branch 'release/os/4.4' into NOTICK-rfowler-merge-OS4.4-OS4.5-20200626 2020-06-26 09:52:16 +01:00
Ryan Fowler
ef582900cf
NOTICK Expand the regex to match what we already do in ENT (#6400) 2020-06-25 17:26:55 +01:00
Ryan Fowler
d720c86fc7
CORDA-3714: Update commons-beanutils for security (#6391) 2020-06-25 11:23:18 +01:00
Kyriakos Tharrouniatis
6ec2910f15
NOTICK Revert node_flow_exceptions type length back to 256 (#6395) 2020-06-25 09:40:58 +01:00
Chris Rankin
6485a025c7
ENT-5430: Increase test coverage when serializing Optional fields. (#6387) 2020-06-22 16:51:40 +01:00
Waldemar Zurowski
3377df2212 Switched to CMD for Windows Server
* when using shell there are huge performance penalty
2020-06-20 17:26:57 +01:00
Waldemar Żurowski
1a7e302d5f
Merge pull request #6385 from corda/release/os/4.5
NOTICK Merge OS 4.5 -> OS 4.6
2020-06-20 16:44:14 +01:00
Waldemar Żurowski
5bfc693a71
Merge pull request #6384 from corda/INFRA-357
INFRA-357 4.4 to 4.5 merge + JDK 11 regression build changes for tag publishing
2020-06-20 14:33:24 +01:00
Schife
84583d2a1c INFRA-357 Re adding JDK 11 regression build file that was removed in the 4.4 to 4.5 merge 2020-06-20 11:25:20 +01:00
Schife
6a12cf34ad Merge branch 'release/os/4.4' of https://github.com/corda/corda into INFRA-357
 Conflicts:
	testing/DockerfileJDK11Azul
2020-06-20 11:22:30 +01:00
Razvan Codreanu
e021022d0d
INFRA-357 Publish build tag (#6375) 2020-06-20 11:08:52 +01:00
Waldemar Zurowski
a7644dab8b Cosmetic change for Windows Server builds 2020-06-19 22:09:02 +01:00
Waldemar Żurowski
ac0e35c854
Trying to ignore push events for Windows Server builds (#6383) 2020-06-19 22:03:09 +01:00
Waldemar Żurowski
967de2f0ba
Merge pull request #6382 from corda/merge-45-to-46
NOTICK: Merge Corda OS 4.5 to 4.6
2020-06-19 19:49:44 +01:00
Waldemar Zurowski
1a4efbac7f Merge branch 'release/os/4.5' into merge-45-to-46 2020-06-19 19:48:08 +01:00
Waldemar Żurowski
99b761e0e2
Merge pull request #6381 from corda/merge-44-to-45
NOTICK: merge Corda OS 4.4 to 4.5
2020-06-19 19:44:13 +01:00
Waldemar Zurowski
f1fcce4247 Merge branch 'release/os/4.4' into merge-44-to-45 2020-06-19 19:42:19 +01:00
Waldemar Żurowski
8a601e6d62
Merge pull request #6380 from corda/merge-43-to-44
NOTICK: forward merge from Corda OS 4.3 to 4.4
2020-06-19 19:35:19 +01:00
Waldemar Zurowski
f7b38f0b6d Merge branch 'release/os/4.3' into merge-43-to-44 2020-06-19 19:32:55 +01:00
Waldemar Żurowski
23f81e73a6
Remove obsolete Jenkins configration for smoke tests (#6379) 2020-06-19 19:30:11 +01:00
Razvan Codreanu
618f7211bb
NOTICK fix regression jenkinsfile typo (#6376) 2020-06-19 18:25:08 +01:00
Razvan Codreanu
ad21e381dc
INFRA-357 Adding JDK 11 Regression and Build tag jenkinsfile (#6374) 2020-06-19 14:10:31 +01:00
Waldemar Żurowski
f7f2b0cea4
Merge pull request #6373 from corda/merge-44-45
NOTICK: merging OS 4.4 with OS 4.5
2020-06-19 11:34:39 +01:00
Waldemar Zurowski
68771cf430 Merge branch 'release/os/4.4' into merge-44-45 2020-06-19 11:02:34 +01:00
pnemeth
d6cab0e131
EG-1557 - Configuration data from "include" section ignored while command line contains the path to config file without leading ./ (#6354)
Configuration data from "include" section ignored while command line contains the path to config file without leading ./
2020-06-19 10:32:55 +01:00
alicer3
e77f7a7546
center console message for registration (#6191) 2020-06-19 09:49:07 +01:00
Euan Cairncross
4bfb595e57
INFRA-357 - Add release tag Jenkins build for OS 4.4 (#6362) 2020-06-18 23:46:29 +01:00
Waldemar Żurowski
494073590b
INFRA-347: Corda builds for Windows Servers (#6356) 2020-06-18 23:19:06 +01:00
Dan Newton
71b2a43221
Merge pull request #6372 from corda/dan/os-4.5-to-4.6-merge-2020-06-18
NOTICK OS 4.5 to 4.6 merge 2020-06-18
2020-06-18 17:04:42 +01:00
LankyDan
56d0bbc036 CORDA-3841 Check isAnyCheckpointPersisted in startFlowInternal (#6351)
Only hit the database if `StateMachineState.isAnyCheckpointPersisted`
returns true. Otherwise, there will be no checkpoint to retrieve from the
database anyway. This can prevent errors due to a transient loss of
connection to the database.

Update tests after merging to 4.6
2020-06-18 16:15:15 +01:00
LankyDan
e8b17ff7b9 Merge branch 'release/os/4.5' into dan/os-4.5-to-4.6-merge-2020-06-18
# Conflicts:
#	node/src/main/kotlin/net/corda/node/services/persistence/DBCheckpointStorage.kt
#	node/src/main/kotlin/net/corda/node/services/statemachine/SingleThreadedStateMachineManager.kt
2020-06-18 15:50:46 +01:00
Razvan Codreanu
813e9dd242
INFRA-394 enable full junit log to avoid truncation (#6368) 2020-06-18 12:52:33 +01:00
Matthew Nesbit
5b3ca5f112
Merge pull request #6367 from corda/chrisr3-os44-merge
NOTICK: Merge from OS 4.4 -> OS 4.5 up to fe61781
2020-06-18 12:03:21 +01:00