From 1857c55f52e2c27e1a316a786f0508a885527706 Mon Sep 17 00:00:00 2001 From: Andrzej Ludwikowski Date: Fri, 17 Jan 2025 11:12:08 +0100 Subject: [PATCH] feat: isDeleted method for entity command handlers --- .../testkit/KeyValueEntityTestKit.java | 10 +++++- .../impl/EventSourcedEntityEffectsRunner.java | 15 ++++++--- .../testkit/impl/EventSourcedResultImpl.scala | 11 +++++++ .../CounterEventSourcedEntity.java | 4 +++ .../CounterEventSourcedEntityTest.java | 12 +++++++ .../CounterKeyValueEntityTest.java | 4 +++ .../akkajavasdk/EventSourcedEntityTest.java | 20 +++++++++--- .../java/akkajavasdk/SdkIntegrationTest.java | 7 ++++ .../counter/CounterEntity.java | 11 +++++++ .../keyvalueentities/user/UserEntity.java | 4 +++ .../EventSourcedEntity.java | 11 ++++++- .../keyvalueentity/KeyValueEntity.java | 12 ++++++- .../EventSourcedEntityImpl.scala | 4 +-- .../keyvalueentity/KeyValueEntityImpl.scala | 12 ++----- .../java/pages/event-sourced-entities.adoc | 32 +++++++++---------- .../java/pages/key-value-entities.adoc | 2 +- 16 files changed, 130 insertions(+), 41 deletions(-) diff --git a/akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/KeyValueEntityTestKit.java b/akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/KeyValueEntityTestKit.java index 1059a841c..f4565dfbf 100644 --- a/akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/KeyValueEntityTestKit.java +++ b/akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/KeyValueEntityTestKit.java @@ -27,6 +27,7 @@ public class KeyValueEntityTestKit> { private S state; + private boolean deleted; private final S emptyState; private final E entity; private final String entityId; @@ -36,6 +37,7 @@ private KeyValueEntityTestKit(String entityId, E entity) { this.entity = entity; this.state = entity.emptyState(); this.emptyState = state; + this.deleted = false; } /** @@ -79,6 +81,11 @@ public S getState() { return state; } + /** @return true if the entity is deleted */ + public boolean isDeleted() { + return deleted; + } + @SuppressWarnings("unchecked") private KeyValueEntityResult interpretEffects(KeyValueEntity.Effect effect) { KeyValueEntityResultImpl result = new KeyValueEntityResultImpl<>(effect); @@ -86,6 +93,7 @@ private KeyValueEntityResult interpretEffects(KeyValueEntity.Effe this.state = (S) result.getUpdatedState(); } else if (result.stateWasDeleted()) { this.state = emptyState; + this.deleted = true; } return result; } @@ -117,7 +125,7 @@ public KeyValueEntityResult call(Function> fu TestKitKeyValueEntityCommandContext commandContext = new TestKitKeyValueEntityCommandContext(entityId, metadata); entity._internalSetCommandContext(Optional.of(commandContext)); - entity._internalSetCurrentState(this.state); + entity._internalSetCurrentState(this.state, this.deleted); return interpretEffects(func.apply(entity)); } } diff --git a/akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/impl/EventSourcedEntityEffectsRunner.java b/akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/impl/EventSourcedEntityEffectsRunner.java index 5ba9ab5eb..3da2da91d 100644 --- a/akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/impl/EventSourcedEntityEffectsRunner.java +++ b/akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/impl/EventSourcedEntityEffectsRunner.java @@ -17,6 +17,7 @@ public abstract class EventSourcedEntityEffectsRunner { private EventSourcedEntity entity; private S _state; + private boolean deleted = false; private List events = new ArrayList<>(); public EventSourcedEntityEffectsRunner(EventSourcedEntity entity) { @@ -33,7 +34,7 @@ public EventSourcedEntityEffectsRunner(EventSourcedEntity entity, List this.entity = entity; this._state = entity.emptyState(); - entity._internalSetCurrentState(this._state); + entity._internalSetCurrentState(this._state, false); // NB: updates _state playEventsForEntity(initialEvents); } @@ -48,7 +49,12 @@ public S getState() { return _state; } - /** @return All events emitted by command handlers of this entity up to now */ + /** @return true if the entity is deleted */ + public boolean isDeleted() { + return deleted; + } + + /** @return All events persisted by command handlers of this entity up to now */ public List getAllEvents() { return events; } @@ -66,7 +72,7 @@ protected EventSourcedResult interpretEffects( EventSourcedEntity.Effect effectExecuted; try { entity._internalSetCommandContext(Optional.of(commandContext)); - entity._internalSetCurrentState(this._state); + entity._internalSetCurrentState(this._state, this.deleted); effectExecuted = effect.get(); this.events.addAll(EventSourcedResultImpl.eventsOf(effectExecuted)); } finally { @@ -74,6 +80,7 @@ protected EventSourcedResult interpretEffects( } playEventsForEntity(EventSourcedResultImpl.eventsOf(effectExecuted)); + deleted = EventSourcedResultImpl.checkIfDeleted(effectExecuted); EventSourcedResult result; try { @@ -91,7 +98,7 @@ private void playEventsForEntity(List events) { entity._internalSetEventContext(Optional.of(new TestKitEventSourcedEntityEventContext())); for (E event : events) { this._state = handleEvent(this._state, event); - entity._internalSetCurrentState(this._state); + entity._internalSetCurrentState(this._state, this.deleted); } } finally { entity._internalSetEventContext(Optional.empty()); diff --git a/akka-javasdk-testkit/src/main/scala/akka/javasdk/testkit/impl/EventSourcedResultImpl.scala b/akka-javasdk-testkit/src/main/scala/akka/javasdk/testkit/impl/EventSourcedResultImpl.scala index d56372874..12802ed4e 100644 --- a/akka-javasdk-testkit/src/main/scala/akka/javasdk/testkit/impl/EventSourcedResultImpl.scala +++ b/akka-javasdk-testkit/src/main/scala/akka/javasdk/testkit/impl/EventSourcedResultImpl.scala @@ -23,6 +23,17 @@ import scala.jdk.CollectionConverters._ * INTERNAL API */ private[akka] object EventSourcedResultImpl { + + def checkIfDeleted[E](effect: EventSourcedEntity.Effect[_]): Boolean = { + effect match { + case ei: EventSourcedEntityEffectImpl[_, E @unchecked] => + ei.primaryEffect match { + case ee: EmitEvents[E @unchecked] => ee.deleteEntity + case _ => false + } + } + } + def eventsOf[E](effect: EventSourcedEntity.Effect[_]): JList[E] = { effect match { case ei: EventSourcedEntityEffectImpl[_, E @unchecked] => diff --git a/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/eventsourced/CounterEventSourcedEntity.java b/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/eventsourced/CounterEventSourcedEntity.java index c949ed667..423cb69d3 100644 --- a/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/eventsourced/CounterEventSourcedEntity.java +++ b/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/eventsourced/CounterEventSourcedEntity.java @@ -28,6 +28,10 @@ else if (wouldOverflow(value + value) || (value + value) < 0) { } } + public Effect delete() { + return effects().persist(new Increased(commandContext().entityId(), 0)).deleteEntity().thenReply(__ -> "Ok"); + } + @Override public Integer applyEvent(Increased increased) { if (currentState() == null) return increased.value(); diff --git a/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/eventsourced/CounterEventSourcedEntityTest.java b/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/eventsourced/CounterEventSourcedEntityTest.java index 1aa9d492d..9aa83b575 100644 --- a/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/eventsourced/CounterEventSourcedEntityTest.java +++ b/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/eventsourced/CounterEventSourcedEntityTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; @@ -26,6 +27,7 @@ public void testIncrease() { assertEquals("Ok", result.getReply()); assertEquals(10, testKit.getState()); assertEquals(1, testKit.getAllEvents().size()); + assertFalse(testKit.isDeleted()); } @Test @@ -52,6 +54,16 @@ public void testDoubleIncrease() { assertEquals(2, testKit.getAllEvents().size()); } + @Test + public void testDelete() { + EventSourcedTestKit testKit = + EventSourcedTestKit.of(ctx -> new CounterEventSourcedEntity()); + EventSourcedResult result = testKit.call(entity -> entity.delete()); + assertTrue(result.isReply()); + assertEquals("Ok", result.getReply()); + assertTrue(testKit.isDeleted()); + } + @Test public void testIncreaseWithNegativeValue() { EventSourcedTestKit testKit = diff --git a/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/keyvalueentity/CounterKeyValueEntityTest.java b/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/keyvalueentity/CounterKeyValueEntityTest.java index c3b6f2b65..03d1699fd 100644 --- a/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/keyvalueentity/CounterKeyValueEntityTest.java +++ b/akka-javasdk-testkit/src/test/java/akka/javasdk/testkit/keyvalueentity/CounterKeyValueEntityTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; public class CounterKeyValueEntityTest { @@ -40,6 +41,7 @@ public void testIncreaseWithNegativeValue() { KeyValueEntityTestKit.of(ctx -> new CounterValueEntity()); KeyValueEntityResult result = testKit.call(entity -> entity.increaseBy(-10)); assertTrue(result.isError()); + assertFalse(testKit.isDeleted()); assertEquals(result.getError(), "Can't increase with a negative value"); } @@ -52,5 +54,7 @@ public void testDeleteValueEntity() { assertTrue(result.isReply()); assertEquals(result.getReply(), "Deleted"); assertEquals(testKit.getState(), 0); + assertTrue(testKit.isDeleted()); + assertTrue(result.stateWasDeleted()); } } diff --git a/akka-javasdk-tests/src/test/java/akkajavasdk/EventSourcedEntityTest.java b/akka-javasdk-tests/src/test/java/akkajavasdk/EventSourcedEntityTest.java index 4ed7888a5..0927d3afa 100644 --- a/akka-javasdk-tests/src/test/java/akkajavasdk/EventSourcedEntityTest.java +++ b/akka-javasdk-tests/src/test/java/akkajavasdk/EventSourcedEntityTest.java @@ -41,10 +41,7 @@ protected TestKit.Settings testKitSettings() { } @Test - public void verifyCounterEventSourcedWiring() throws InterruptedException { - - Thread.sleep(10000); - + public void verifyCounterEventSourcedWiring() { var counterId = "hello"; var client = componentClient.forEventSourcedEntity(counterId); @@ -58,6 +55,20 @@ public void verifyCounterEventSourcedWiring() throws InterruptedException { Assertions.assertEquals(200, counterGet); } + @Test + public void verifyCounterEventSourcedDeletion() { + var counterId = "deleted-hello"; + var client = componentClient.forEventSourcedEntity(counterId); + + var isDeleted = await(client.method(CounterEntity::getDeleted).invokeAsync()); + assertThat(isDeleted).isFalse(); + + await(client.method(CounterEntity::delete).invokeAsync()); + + var isDeleted2 = await(client.method(CounterEntity::getDeleted).invokeAsync()); + assertThat(isDeleted2).isFalse(); + } + @Test public void verifyCounterErrorEffect() { var counterId = "hello-error"; @@ -230,5 +241,4 @@ private void restartCounterEntity(EventSourcedEntityClient client) { private Integer getCounter(EventSourcedEntityClient client) { return await(client.method(CounterEntity::get).invokeAsync()); } - } diff --git a/akka-javasdk-tests/src/test/java/akkajavasdk/SdkIntegrationTest.java b/akka-javasdk-tests/src/test/java/akkajavasdk/SdkIntegrationTest.java index 5758353d7..0c391bc8b 100644 --- a/akka-javasdk-tests/src/test/java/akkajavasdk/SdkIntegrationTest.java +++ b/akka-javasdk-tests/src/test/java/akkajavasdk/SdkIntegrationTest.java @@ -245,6 +245,13 @@ public void verifyUserSubscriptionAction() { deleteUser(user); + var isDeleted = await(componentClient + .forKeyValueEntity(user.id()) + .method(UserEntity::getDelete) + .invokeAsync()); + + assertThat(isDeleted).isEqualTo(true); + Awaitility.await() .ignoreExceptions() .atMost(15, TimeUnit.of(SECONDS)) diff --git a/akka-javasdk-tests/src/test/java/akkajavasdk/components/eventsourcedentities/counter/CounterEntity.java b/akka-javasdk-tests/src/test/java/akkajavasdk/components/eventsourcedentities/counter/CounterEntity.java index 5e5abb0c2..3966b017c 100644 --- a/akka-javasdk-tests/src/test/java/akkajavasdk/components/eventsourcedentities/counter/CounterEntity.java +++ b/akka-javasdk-tests/src/test/java/akkajavasdk/components/eventsourcedentities/counter/CounterEntity.java @@ -4,6 +4,7 @@ package akkajavasdk.components.eventsourcedentities.counter; +import akka.Done; import akka.javasdk.annotations.Acl; import akka.javasdk.annotations.ComponentId; import akka.javasdk.eventsourcedentity.EventSourcedEntity; @@ -13,6 +14,7 @@ import java.util.List; +import static akka.Done.done; import static java.util.function.Function.identity; @ComponentId("counter-entity") @@ -96,6 +98,11 @@ public ReadOnlyEffect get() { return effects().reply(currentState().value()); } + public ReadOnlyEffect getDeleted() { + // don't modify, we want to make sure we call currentState().value here + return effects().reply(isDeleted()); + } + public Effect times(Integer value) { logger.info( "Multiplying counter with commandId={} commandName={} seqNr={} current={} by value={}", @@ -119,6 +126,10 @@ public Effect restart() { // force entity restart, useful for testing throw new RuntimeException("Forceful restarting entity!"); } + public Effect delete() { + return effects().persist(new CounterEvent.ValueSet(0)).deleteEntity().thenReply(__ -> done()); + } + @Override public Counter applyEvent(CounterEvent event) { return currentState().apply(event); diff --git a/akka-javasdk-tests/src/test/java/akkajavasdk/components/keyvalueentities/user/UserEntity.java b/akka-javasdk-tests/src/test/java/akkajavasdk/components/keyvalueentities/user/UserEntity.java index dae1ace75..5d6480408 100644 --- a/akka-javasdk-tests/src/test/java/akkajavasdk/components/keyvalueentities/user/UserEntity.java +++ b/akka-javasdk-tests/src/test/java/akkajavasdk/components/keyvalueentities/user/UserEntity.java @@ -59,6 +59,10 @@ public Effect deleteUser(Delete cmd) { return effects().deleteEntity().thenReply(Ok.instance); } + public Effect getDelete() { + return effects().reply(isDeleted()); + } + public Effect restart(Restart cmd) { // force entity restart, useful for testing logger.info( "Restarting counter with commandId={} commandName={} current={}", diff --git a/akka-javasdk/src/main/java/akka/javasdk/eventsourcedentity/EventSourcedEntity.java b/akka-javasdk/src/main/java/akka/javasdk/eventsourcedentity/EventSourcedEntity.java index 3d434c58c..bc51e3d01 100644 --- a/akka-javasdk/src/main/java/akka/javasdk/eventsourcedentity/EventSourcedEntity.java +++ b/akka-javasdk/src/main/java/akka/javasdk/eventsourcedentity/EventSourcedEntity.java @@ -69,6 +69,7 @@ public abstract class EventSourcedEntity { private Optional commandContext = Optional.empty(); private Optional eventContext = Optional.empty(); private Optional currentState = Optional.empty(); + private boolean deleted = false; private boolean handlingCommands = false; /** @@ -131,10 +132,11 @@ public void _internalSetEventContext(Optional context) { * responsible for finally calling _internalClearCurrentState */ @InternalApi - public boolean _internalSetCurrentState(S state) { + public boolean _internalSetCurrentState(S state, boolean deleted) { var wasHandlingCommands = handlingCommands; handlingCommands = true; currentState = Optional.ofNullable(state); + this.deleted = deleted; return !wasHandlingCommands; } @@ -207,6 +209,13 @@ protected final S currentState() { throw new IllegalStateException("Current state is only available when handling a command."); } + /** + * Returns true if the entity has been deleted. + */ + protected boolean isDeleted() { + return deleted; + } + protected final Effect.Builder effects() { return new EventSourcedEntityEffectImpl(); } diff --git a/akka-javasdk/src/main/java/akka/javasdk/keyvalueentity/KeyValueEntity.java b/akka-javasdk/src/main/java/akka/javasdk/keyvalueentity/KeyValueEntity.java index e678102eb..80e504197 100644 --- a/akka-javasdk/src/main/java/akka/javasdk/keyvalueentity/KeyValueEntity.java +++ b/akka-javasdk/src/main/java/akka/javasdk/keyvalueentity/KeyValueEntity.java @@ -43,6 +43,8 @@ public abstract class KeyValueEntity { private Optional currentState = Optional.empty(); + private boolean deleted = false; + private boolean handlingCommands = false; /** @@ -85,9 +87,10 @@ public void _internalSetCommandContext(Optional context) { * @hidden */ @InternalApi - public void _internalSetCurrentState(S state) { + public void _internalSetCurrentState(S state, boolean deleted) { handlingCommands = true; currentState = Optional.ofNullable(state); + this.deleted = deleted; } /** @@ -119,6 +122,13 @@ protected final S currentState() { throw new IllegalStateException("Current state is only available when handling a command."); } + /** + * Returns true if the entity has been deleted. + */ + protected boolean isDeleted() { + return deleted; + } + protected final Effect.Builder effects() { return new KeyValueEntityEffectImpl(); } diff --git a/akka-javasdk/src/main/scala/akka/javasdk/impl/eventsourcedentity/EventSourcedEntityImpl.scala b/akka-javasdk/src/main/scala/akka/javasdk/impl/eventsourcedentity/EventSourcedEntityImpl.scala index b64082da3..d80600cfa 100644 --- a/akka-javasdk/src/main/scala/akka/javasdk/impl/eventsourcedentity/EventSourcedEntityImpl.scala +++ b/akka-javasdk/src/main/scala/akka/javasdk/impl/eventsourcedentity/EventSourcedEntityImpl.scala @@ -126,7 +126,7 @@ private[impl] final class EventSourcedEntityImpl[S, E, ES <: EventSourcedEntity[ try { entity._internalSetCommandContext(Optional.of(cmdContext)) - entity._internalSetCurrentState(state) + entity._internalSetCurrentState(state, command.isDeleted) val commandEffect = router .handleCommand(command.name, cmdPayload) .asInstanceOf[EventSourcedEntityEffectImpl[AnyRef, E]] // FIXME improve? @@ -223,7 +223,7 @@ private[impl] final class EventSourcedEntityImpl[S, E, ES <: EventSourcedEntity[ sequenceNumber: Long): SpiEventSourcedEntity.State = { val eventContext = new EventContextImpl(entityId, sequenceNumber) entity._internalSetEventContext(Optional.of(eventContext)) - val clearState = entity._internalSetCurrentState(state) + val clearState = entity._internalSetCurrentState(state, false) try { router.handleEvent(event) } finally { diff --git a/akka-javasdk/src/main/scala/akka/javasdk/impl/keyvalueentity/KeyValueEntityImpl.scala b/akka-javasdk/src/main/scala/akka/javasdk/impl/keyvalueentity/KeyValueEntityImpl.scala index 179a746e2..a43b3f806 100644 --- a/akka-javasdk/src/main/scala/akka/javasdk/impl/keyvalueentity/KeyValueEntityImpl.scala +++ b/akka-javasdk/src/main/scala/akka/javasdk/impl/keyvalueentity/KeyValueEntityImpl.scala @@ -49,7 +49,6 @@ private[impl] object KeyValueEntityImpl { override val entityId: String, val sequenceNumber: Long, override val commandName: String, - val isDeleted: Boolean, override val metadata: Metadata, span: Option[Span], tracerFactory: () => Tracer) @@ -109,18 +108,11 @@ private[impl] final class KeyValueEntityImpl[S, KV <: KeyValueEntity[S]]( val cmdPayload = command.payload.getOrElse(BytesPayload.empty) val metadata: Metadata = MetadataImpl.of(command.metadata) val cmdContext = - new CommandContextImpl( - entityId, - command.sequenceNumber, - command.name, - command.isDeleted, - metadata, - span, - tracerFactory) + new CommandContextImpl(entityId, command.sequenceNumber, command.name, metadata, span, tracerFactory) try { entity._internalSetCommandContext(Optional.of(cmdContext)) - entity._internalSetCurrentState(state) + entity._internalSetCurrentState(state, command.isDeleted) val commandEffect = router .handleCommand(command.name, cmdPayload) .asInstanceOf[KeyValueEntityEffectImpl[AnyRef]] // FIXME improve? diff --git a/docs/src/modules/java/pages/event-sourced-entities.adoc b/docs/src/modules/java/pages/event-sourced-entities.adoc index 06fd93dd6..af03a39d0 100644 --- a/docs/src/modules/java/pages/event-sourced-entities.adoc +++ b/docs/src/modules/java/pages/event-sourced-entities.adoc @@ -141,21 +141,7 @@ include::example$shopping-cart-quickstart/src/main/java/shoppingcart/application IMPORTANT: We are returning the internal state directly back to the requester. In the endpoint, it's usually best to convert this internal domain model into a public model so the internal representation is free to evolve without breaking clients code. -== Snapshots - -Snapshots are an important optimization for Event Sourced Entities that persist many events. Rather than reading the entire journal upon loading or restart, Akka can initiate them from a snapshot. - -Snapshots are stored and handled automatically by Akka without any specific code required. Snapshots are stored after a configured number of events: - -[source,conf,indent=0] -.{sample-base-url}/shopping-cart-quickstart/src/main/resources/application.conf[application.conf] ----- -include::example$shopping-cart-quickstart/src/main/resources/application.conf[tag=snapshot-every] ----- - -When the Event Sourced Entity is loaded again, the snapshot will be loaded before any other events are received. - -== Deleting an Entity +=== Deleting an Entity Normally, Event Sourced Entities are not deleted because the history of the events typically provide business value. For certain use cases or for regulatory reasons the entity can be deleted. @@ -170,12 +156,26 @@ include::example$shopping-cart-quickstart/src/main/java/shoppingcart/application When you give the instruction to delete the entity it will still exist for some time, including its events and snapshots. The actual removal of events and snapshots will be deleted later to give downstream consumers time to process all prior events, including the final event that was persisted together with the `deleteEntity` effect. By default, the existence of the entity is completely cleaned up after a week. -It is not allowed to persist more events after the entity has been "marked" as deleted. You can still handle read requests to the entity until it has been completely removed. +It is not allowed to persist more events after the entity has been "marked" as deleted. You can still handle read requests to the entity until it has been completely removed. To check whether the entity has been deleted, you can use the `isDeleted` method inherited from the `EventSourcedEntity` class. It is best to not reuse the same entity id after deletion, but if that happens after the entity has been completely removed it will be instantiated as a completely new entity without any knowledge of previous state. Note that xref:views.adoc#ve_delete[deleting View state] must be handled explicitly. +== Snapshots + +Snapshots are an important optimization for Event Sourced Entities that persist many events. Rather than reading the entire journal upon loading or restart, Akka can initiate them from a snapshot. + +Snapshots are stored and handled automatically by Akka without any specific code required. Snapshots are stored after a configured number of events: + +[source,conf,indent=0] +.{sample-base-url}/shopping-cart-quickstart/src/main/resources/application.conf[application.conf] +---- +include::example$shopping-cart-quickstart/src/main/resources/application.conf[tag=snapshot-every] +---- + +When the Event Sourced Entity is loaded again, the snapshot will be loaded before any other events are received. + [#_replication] include::partial$mutli-region-replication.adoc[] diff --git a/docs/src/modules/java/pages/key-value-entities.adoc b/docs/src/modules/java/pages/key-value-entities.adoc index 3d943e6c9..129b8603d 100644 --- a/docs/src/modules/java/pages/key-value-entities.adoc +++ b/docs/src/modules/java/pages/key-value-entities.adoc @@ -112,7 +112,7 @@ include::example$key-value-counter/src/main/java/com/example/application/Counter When you give the instruction to delete the entity it will still exist with an empty state for some time. The actual removal happens later to give downstream consumers time to process the change. By default, the existence of the entity is completely cleaned up after a week. -It is not allowed to make further changes after the entity has been "marked" as deleted. You can still handle read requests to the entity until it has been completely removed, but the current state will be empty. +It is not allowed to make further changes after the entity has been "marked" as deleted. You can still handle read requests to the entity until it has been completely removed, but the current state will be empty. To check whether the entity has been deleted, you can use the `isDeleted` method inherited from the `KeyValueEntity` class. NOTE: If you don't want to permanently delete an entity, you can instead use the `updateState` effect with an empty state. This will work the same as resetting the entity to its initial state.