Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make UncommittedHistory remember only successfully applied events #1439

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
99581e8
Add missed copyright note
yevhenii-nadtochii Jan 4, 2022
ad2284f
Implement `given` types for tests
yevhenii-nadtochii Jan 4, 2022
2b88574
Create `package-info.java`
yevhenii-nadtochii Jan 4, 2022
fb33a1b
Implement tests
yevhenii-nadtochii Jan 5, 2022
32d872a
Place a temporary logging
yevhenii-nadtochii Jan 5, 2022
66d246c
Prototype more tests
yevhenii-nadtochii Jan 6, 2022
cfed5da
Drop redundant tests
yevhenii-nadtochii Jan 6, 2022
6eadede
Refactor the test with commands in a banch
yevhenii-nadtochii Jan 6, 2022
1efbae3
Extract the test into a separate test class
yevhenii-nadtochii Jan 6, 2022
c3d0b0a
Prototype proof of concept
yevhenii-nadtochii Jan 10, 2022
d86e192
Rollback `ServerEnvironment` and `Aggregate`
yevhenii-nadtochii Jan 10, 2022
8989ddf
Comment out loggers and update the copyright year
yevhenii-nadtochii Jan 10, 2022
fb6d1f9
Comment out `Delivery` set-up in `ServerEnvironment.reset()`
yevhenii-nadtochii Jan 10, 2022
12d73cb
Enable `AggregateCachingTest`
yevhenii-nadtochii Jan 10, 2022
4463c3b
Drop loggers
yevhenii-nadtochii Jan 10, 2022
1e655f5
Add one more test
yevhenii-nadtochii Jan 10, 2022
6d80980
Make `UncommittedHistory` use primitive tracking sessions
yevhenii-nadtochii Jan 11, 2022
2ac008b
Drop tracking session from `UncommittedHistory`
yevhenii-nadtochii Jan 11, 2022
14b900f
Drop unused declarations
yevhenii-nadtochii Jan 11, 2022
b334bcf
Update javadoc
yevhenii-nadtochii Jan 11, 2022
17e7973
Polish the tests
yevhenii-nadtochii Jan 11, 2022
16d64ab
Document some test utilities
yevhenii-nadtochii Jan 11, 2022
c9b6f16
Extract utility methods to TestEnv
yevhenii-nadtochii Jan 12, 2022
b4dd9e4
Make `UncommittedHistory` decide whether it would track an event or not
yevhenii-nadtochii Jan 12, 2022
a02ec44
Make `onAfterEventPlayed` accept an envelope
yevhenii-nadtochii Jan 13, 2022
10440b9
Enhance documentation
yevhenii-nadtochii Jan 13, 2022
aac8e4f
Rename `salary` package to `employee` and polish the code
yevhenii-nadtochii Jan 13, 2022
ea35d23
Better document the suppression
yevhenii-nadtochii Jan 13, 2022
f5f8d67
Fix broken imports
yevhenii-nadtochii Jan 13, 2022
b189874
Use a more appropriate word in documentation
yevhenii-nadtochii Jan 13, 2022
9ed5ef7
Shorten comments when one doesn't fit into a line
yevhenii-nadtochii Jan 13, 2022
2e8ad44
Fix javadoc – `BoundedContext` does not close `StorageFactory`
yevhenii-nadtochii Jan 14, 2022
518afae
Drop `final` method declarations out of a `final class`
yevhenii-nadtochii Jan 14, 2022
0a46156
Implement `ResultedEvents` data structure
yevhenii-nadtochii Jan 14, 2022
df6ca7c
Implement `AggregateResilienceTest` for cached and non-cached `Aggreg…
yevhenii-nadtochii Jan 14, 2022
fc34823
Polish the code
yevhenii-nadtochii Jan 17, 2022
9034c4c
Make tests assert updated entity's state
yevhenii-nadtochii Jan 17, 2022
c3a0315
Rollback to the option with a transactional events applying
yevhenii-nadtochii Jan 18, 2022
8461f99
Polish the code
yevhenii-nadtochii Jan 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions license-report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# Dependencies of `io.spine:spine-client:2.0.0-SNAPSHOT.91`
# Dependencies of `io.spine:spine-client:2.0.0-SNAPSHOT.92`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -512,12 +512,12 @@

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Jan 05 17:43:57 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 10 12:20:17 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.91`
# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.92`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -989,12 +989,12 @@ This report was generated on **Wed Jan 05 17:43:57 EET 2022** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Jan 05 17:43:57 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 10 12:20:17 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-model-assembler:2.0.0-SNAPSHOT.91`
# Dependencies of `io.spine.tools:spine-model-assembler:2.0.0-SNAPSHOT.92`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -1506,12 +1506,12 @@ This report was generated on **Wed Jan 05 17:43:57 EET 2022** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Jan 05 17:43:58 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 10 12:20:18 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-model-verifier:2.0.0-SNAPSHOT.91`
# Dependencies of `io.spine.tools:spine-model-verifier:2.0.0-SNAPSHOT.92`

## Runtime
1. **Group** : com.github.ben-manes.caffeine. **Name** : caffeine. **Version** : 2.8.8.
Expand Down Expand Up @@ -2123,12 +2123,12 @@ This report was generated on **Wed Jan 05 17:43:58 EET 2022** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Jan 05 17:44:01 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 10 12:20:19 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.91`
# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.92`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -2648,12 +2648,12 @@ This report was generated on **Wed Jan 05 17:44:01 EET 2022** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Jan 05 17:44:05 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 10 12:20:22 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.91`
# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.92`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3217,12 +3217,12 @@ This report was generated on **Wed Jan 05 17:44:05 EET 2022** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Jan 05 17:44:06 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 10 12:20:22 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.91`
# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.92`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3786,12 +3786,12 @@ This report was generated on **Wed Jan 05 17:44:06 EET 2022** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Jan 05 17:44:07 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 10 12:20:23 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.91`
# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.92`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -4399,4 +4399,4 @@ This report was generated on **Wed Jan 05 17:44:07 EET 2022** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Wed Jan 05 17:44:22 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 10 12:20:32 EET 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject.
-->
<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>2.0.0-SNAPSHOT.91</version>
<version>2.0.0-SNAPSHOT.92</version>

<inceptionYear>2015</inceptionYear>

Expand Down
4 changes: 0 additions & 4 deletions server/src/main/java/io/spine/server/BoundedContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
import io.spine.server.integration.IntegrationBroker;
import io.spine.server.security.Security;
import io.spine.server.stand.Stand;
import io.spine.server.storage.StorageFactory;
import io.spine.server.tenant.TenantIndex;
import io.spine.server.trace.TracerFactory;
import io.spine.system.server.SystemClient;
import io.spine.system.server.SystemContext;
import io.spine.type.TypeName;
Expand Down Expand Up @@ -400,14 +398,12 @@ public boolean isMultitenant() {
*
* <p>This method performs the following:
* <ol>
* <li>Closes associated {@link StorageFactory}.
* <li>Closes {@link CommandBus}.
* <li>Closes {@link EventBus}.
* <li>Closes {@link IntegrationBroker}.
* <li>Closes {@link DefaultEventStore EventStore}.
* <li>Closes {@link Stand}.
* <li>Closes {@link ImportBus}.
* <li>Closes {@link TracerFactory} if it is present.
* <li>Closes all registered {@linkplain Repository repositories}.
* </ol>
*
Expand Down
2 changes: 0 additions & 2 deletions server/src/main/java/io/spine/server/ServerEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ public void reset() {
tracerFactory.reset();
storageFactory.reset();
delivery.reset();
var currentEnv = environment().type();
delivery.use(Delivery.local(), currentEnv);
resetDeploymentType();
}

Expand Down
30 changes: 11 additions & 19 deletions server/src/main/java/io/spine/server/aggregate/Aggregate.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ protected DispatchOutcome dispatchCommand(CommandEnvelope command) {
/**
* Dispatches the event on which the aggregate reacts.
*
* <p>Reacting on a event may result in emitting event messages.
* <p>Reacting on an event may result in emitting event messages.
* All the {@linkplain Empty empty} messages are filtered out from the result.
*
* @param event
Expand Down Expand Up @@ -329,8 +329,8 @@ final BatchDispatchOutcome replay(AggregateHistory history) {
* the {@code events} list is of size 3, the applied events will have versions {@code 43},
* {@code 44}, and {@code 45}.
*
* <p>All the events applied to the aggregate instance are
* {@linkplain UncommittedHistory#startTracking(int) tracked} as a part of the aggregate's
* <p>All the events successfully applied to the aggregate instance are
* {@linkplain UncommittedHistory#track(List, int) tracked} as a part of the aggregate's
* {@link UncommittedHistory} and later are stored.
*
* <p>If during the application of the events, the number of the events since the last snapshot
Expand All @@ -346,21 +346,13 @@ final BatchDispatchOutcome replay(AggregateHistory history) {
final BatchDispatchOutcome apply(List<Event> events, int snapshotTrigger) {
var versionSequence = new VersionSequence(version());
var versionedEvents = versionSequence.update(events);
uncommittedHistory.startTracking(snapshotTrigger);
var result = play(versionedEvents);
uncommittedHistory.stopTracking();
return result;
}
var outcome = play(versionedEvents);

/**
* A callback telling that the event has been played on this aggregate in scope
* of a transaction.
*
* <p>If this event is new in the aggregate history (e.g. it's not already stored), it is
* recorded as a part of the aggregate's {@link UncommittedHistory}.
*/
final void onAfterEventPlayed(EventEnvelope event) {
uncommittedHistory.track(event);
if (outcome.getSuccessful()) {
uncommittedHistory.track(versionedEvents, snapshotTrigger);
}

return outcome;
}

/**
Expand Down Expand Up @@ -394,7 +386,7 @@ UncommittedEvents getUncommittedEvents() {
}

/**
* Tells if there any uncommitted events.
* Tells if there are any uncommitted events.
*/
boolean hasUncommittedEvents() {
return uncommittedHistory.hasEvents();
Expand Down Expand Up @@ -483,7 +475,7 @@ protected final RecentHistory recentHistory() {
/**
* Creates an iterator of the aggregate event history with reverse traversal.
*
* <p>The records are returned sorted by timestamp in a descending order (from newer to older).
* <p>The records are returned sorted by timestamp in descending order (from newer to older).
*
* <p>The iterator is empty if there's no history for the aggregate.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private void initInbox() {
.delivery();
inbox = delivery
.<I>newInbox(entityStateType())
.withBatchListener(new BatchDeliveryListener<I>() {
.withBatchListener(new BatchDeliveryListener<>() {
@Override
public void onStart(I id) {
cache.startCaching(id);
Expand Down Expand Up @@ -255,8 +255,8 @@ protected void setupEventRouting(EventRouting<I> routing) {
* <p>The default routing uses {@linkplain io.spine.core.EventContext#getProducerId()
* producer ID} of the event as the ID of the target aggregate.
*
* <p>This default routing requires that {@link Event Event} instances
* {@linkplain ImportBus#post(io.spine.core.Signal, io.grpc.stub.StreamObserver)} posted}
* <p>This default routing requires that {@link Event} instances
* {@linkplain ImportBus#post(io.spine.core.Signal, io.grpc.stub.StreamObserver) posted}
* for import must {@link io.spine.core.EventContext#getProducerId() contain} the ID of the
* target aggregate. Not providing a valid aggregate ID would result in
* {@code RuntimeException}.
Expand Down Expand Up @@ -494,7 +494,7 @@ protected int snapshotTrigger() {
*
* <p><b>NOTE</b>: repository read operations are optimized around the current snapshot
* trigger. Setting the snapshot trigger to a new value may cause read operations to perform
* sub-optimally, until a new snapshot is created. This doesn't apply to newly created
* suboptimally, until a new snapshot is created. This doesn't apply to newly created
* repositories.
*
* @param snapshotTrigger
Expand Down Expand Up @@ -591,7 +591,7 @@ private Optional<A> load(I id) {
* <p>The method loads only the recent history of the aggregate.
*
* <p>The current {@link #snapshotTrigger} is used as a batch size of the read operation,
* so the method can perform sub-optimally for some time
* so the method can perform suboptimally for some time
* after the {@link #snapshotTrigger} change.
*
* @param id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
* its further querying.
* </ol>
*
* <h3>Storing Aggregate events</h3>
* <h1>Storing Aggregate events</h1>
*
* <p>Each Aggregate is an event-sourced Entity. To load an Aggregate instance, one plays all
* of the events emitted by it, eventually obtaining the last known state. While the Event Store
* the events emitted by it, eventually obtaining the last known state. While the Event Store
* of a Bounded Context, to which some Aggregate belongs, stores all domain events, using it
* for the sake of loading an Aggregate is inefficient in most cases. An overwhelming number of
* the domain events emitted in a Bounded Context and the restrictions applied by an underlying
Expand All @@ -91,7 +91,7 @@
* created. It persists data as Protobuf message records in its pre-configured
* {@link io.spine.server.storage.RecordStorage RecordStorage}.
*
* <h3>Storing and querying the latest Aggregate states</h3>
* <h1>Storing and querying the latest Aggregate states</h1>
*
* <p>End-users of the framework are able to set the visibility level for each Aggregate state
* by using an {@linkplain io.spine.server.entity.EntityVisibility (entity).visibility} option
Expand All @@ -108,7 +108,7 @@
* <p>However, even if the Aggregate visibility is set to
* {@link io.spine.option.EntityOption.Visibility#NONE NONE}, the storage still persists
* the essential bits of Aggregate as-an-Entity. Namely, its identifier, its lifecycle flags
* and version. Such a behavior allows to speed up the execution of calls such
* and version. Such a behavior allows speeding up the execution of calls such
* as {@linkplain #index() obtaining an index} of Aggregate identifiers, which otherwise would
* involve major scans of event storage, with {@code DISTINCT} group operation applied.
*
Expand Down Expand Up @@ -208,7 +208,7 @@ public Iterator<I> index() {

/**
* Forms and returns an {@link AggregateHistory} based on the
* {@linkplain #historyBackward(Object, int)} aggregate history}.
* {@linkplain #historyBackward(Object, int) aggregate history}.
*
* @param id
* the identifier of the aggregate for which to return the history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*
* @param <I> the type of aggregate IDs
* @param <S> the type of aggregate state
* @param <B> the type of a {@code ValidatingBuilder} for the aggregate state
* @param <B> the type of {@code ValidatingBuilder} for the aggregate state
*/
@Internal
public class AggregateTransaction<I,
Expand Down Expand Up @@ -76,18 +76,6 @@ protected final DispatchOutcome dispatch(Aggregate<I, S, B> aggregate, EventEnve
return aggregate.invokeApplier(event);
}

/**
* {@inheritDoc}
*
* <p>Additionally, notifies the {@code Aggregate} instance that the event has been played.
*/
@Override
public DispatchOutcome play(EventEnvelope event) {
var outcome = super.play(event);
entity().onAfterEventPlayed(event);
return outcome;
}

@Override
protected VersionIncrement createVersionIncrement(EventEnvelope event) {
return VersionIncrement.fromEvent(event);
Expand Down
Loading