Skip to content

Commit

Permalink
Rename state "pulled" to "shared"
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-blessing committed Nov 10, 2023
1 parent 3ab572a commit 00ceed1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
14 changes: 7 additions & 7 deletions docs/entity_states.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Each entity is in one of the following states at any given time:
* Unshared: This is the default state that entities start in.
* Activated: The entity is in the process of being pulled/deleted to/from the local side. It is only present in the source side of the link.
* Received: The entity is in the process of being pulled/deleted to/from the local side. It is present in both sides of the link.
* Pulled: The entity has been copied from the source to the local side.
* Shared: The entity has been copied from the source to the local side.
* Tainted: The entity was flagged by the source side indicating to the local side to delete it.
* Deprecated: The entity was flagged by the source side and subsequently deleted by the local side.

Expand All @@ -18,13 +18,13 @@ stateDiagram-v2
[*] --> Unshared
Unshared --> Activated: pulled / start pull process
Activated --> Received: processed [in pull process and not flagged] / add to local
Received --> Pulled: processed [in pull process and not flagged] / finish pull process
Received --> Shared: processed [in pull process and not flagged] / finish pull process
Received --> Tainted: processed [in pull process and flagged] / finish pull process
Pulled --> Received: deleted / start delete process
Shared --> Received: deleted / start delete process
Received --> Activated: processed [in delete process] / remove from local
Activated --> Unshared: processed [in delete process and not flagged] / finish delete process
Pulled --> Tainted: flagged
Tainted --> Pulled: unflagged
Shared --> Tainted: flagged
Tainted --> Shared: unflagged
Tainted --> Received: deleted / start delete process
Activated --> Deprecated: processed [flagged] / deprecate
Deprecated --> Unshared: unflagged
Expand All @@ -39,7 +39,7 @@ Not following this rule can lead to entities in invalid states due to modifying
The `pulled`, `processed` and `deleted` events are triggered by the application, whereas the `flagged` and `unflagged` events are triggered by the source side directly by modifying the persistent data. The `flagged` and `unflagged` events are also not associated with activities for the same reason.

## Processes
Unshared entities can be pulled from the source side into the local side and once they are pulled they can be deleted from the local side. Activated and received entities are currently undergoing one of these two processes. The name of the specific process is associated with entities that are in the aforementioned states. This allows us to correctly transition these entities. For example without associating the process with the entity we would not be able to determine whether an activated entity should become a received one (pull) or an unshared one (delete).
Unshared entities can be pulled from the source side into the local side and once they are shared they can be deleted from the local side. Activated and received entities are currently undergoing one of these two processes. The name of the specific process is associated with entities that are in the aforementioned states. This allows us to correctly transition these entities. For example without associating the process with the entity we would not be able to determine whether an activated entity should become a received one (pull) or an unshared one (delete).

## Persistence

Expand All @@ -53,7 +53,7 @@ The following table illustrates the chosen mapping:
| :white_check_mark: | :x: | :x: | :x: | :x: | Unshared |
| :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: / :x: | Activated |
| :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: / :x: | Received |
| :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | Pulled |
| :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | Shared |
| :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | Tainted |
| :white_check_mark: | :white_check_mark: | :x: | :x: | :white_check_mark: | Deprecated |

Expand Down
12 changes: 6 additions & 6 deletions link/domain/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def process(cls, entity: Entity) -> None:
if entity.is_tainted:
return transition_entity(Tainted, new_process=Processes.NONE)
else:
return transition_entity(Pulled, new_process=Processes.NONE)
return transition_entity(Shared, new_process=Processes.NONE)
elif entity.current_process is Processes.DELETE:
return transition_entity(Activated)
raise RuntimeError
Expand All @@ -116,7 +116,7 @@ def process(cls, entity: Entity) -> None:
states.register(Received)


class Pulled(State):
class Shared(State):
"""The state of an entity that has been copied to the local side."""

@classmethod
Expand All @@ -125,7 +125,7 @@ def start_delete(cls, entity: Entity) -> None:
return cls._transition_entity(entity, Operations.START_DELETE, Received, new_process=Processes.DELETE)


states.register(Pulled)
states.register(Shared)


class Tainted(State):
Expand Down Expand Up @@ -176,10 +176,10 @@ class Commands(Enum):
Transition(Activated, Received): Commands.ADD_TO_LOCAL,
Transition(Activated, Unshared): Commands.FINISH_DELETE_PROCESS,
Transition(Activated, Deprecated): Commands.DEPRECATE,
Transition(Received, Pulled): Commands.FINISH_PULL_PROCESS,
Transition(Received, Shared): Commands.FINISH_PULL_PROCESS,
Transition(Received, Tainted): Commands.FINISH_PULL_PROCESS,
Transition(Received, Activated): Commands.REMOVE_FROM_LOCAL,
Transition(Pulled, Received): Commands.START_DELETE_PROCESS,
Transition(Shared, Received): Commands.START_DELETE_PROCESS,
Transition(Tainted, Received): Commands.START_DELETE_PROCESS,
}

Expand Down Expand Up @@ -247,7 +247,7 @@ class PersistentState:
frozenset({Components.SOURCE, Components.OUTBOUND, Components.LOCAL}),
is_tainted=False,
has_process=False,
): Pulled,
): Shared,
PersistentState(
frozenset({Components.SOURCE, Components.OUTBOUND, Components.LOCAL}),
is_tainted=True,
Expand Down
2 changes: 1 addition & 1 deletion link/infrastructure/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LocalEndpoint(Table):
_progress_view: ProgressView

def delete(self, *, display_progress: bool = False) -> None:
"""Delete pulled entities from the local table."""
"""Delete shared entities from the local table."""
if display_progress:
self._progress_view.enable()
primary_keys = self.proj().fetch(as_dict=True)
Expand Down
4 changes: 2 additions & 2 deletions link/service/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def pull_entity(command: commands.PullEntity, *, uow: UnitOfWork, message_bus: M


def delete_entity(command: commands.DeleteEntity, *, uow: UnitOfWork, message_bus: MessageBus) -> None:
"""Delete a pulled entity."""
"""Delete a shared entity."""
message_bus.handle(events.ProcessStarted(Processes.DELETE, command.requested))
with uow:
uow.link[command.requested].delete()
Expand All @@ -38,7 +38,7 @@ def pull(command: commands.PullEntities, *, message_bus: MessageBus) -> None:


def delete(command: commands.DeleteEntities, *, message_bus: MessageBus) -> None:
"""Delete pulled entities."""
"""Delete shared entities."""
message_bus.handle(events.BatchProcessingStarted(Processes.DELETE, command.requested))
for identifier in command.requested:
message_bus.handle(commands.DeleteEntity(identifier))
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_uow(state: type[State], process: Processes | None = None, is_tainted:
assert process is None
if state in (states.Tainted, states.Deprecated):
assert is_tainted
elif state in (states.Unshared, states.Pulled):
elif state in (states.Unshared, states.Shared):
assert not is_tainted

if is_tainted:
Expand Down Expand Up @@ -117,7 +117,7 @@ class EntityConfig(TypedDict):
{"state": states.Received, "is_tainted": False, "process": Processes.DELETE},
{"state": states.Received, "is_tainted": True, "process": Processes.PULL},
{"state": states.Received, "is_tainted": True, "process": Processes.DELETE},
{"state": states.Pulled, "is_tainted": False, "process": None},
{"state": states.Shared, "is_tainted": False, "process": None},
{"state": states.Tainted, "is_tainted": True, "process": None},
{"state": states.Deprecated, "is_tainted": True, "process": None},
]
Expand Down Expand Up @@ -151,16 +151,16 @@ def test_deleted_entity_ends_in_correct_state(state: EntityConfig, expected: typ
@pytest.mark.parametrize(
("state", "expected"),
[
(STATES[0], states.Pulled),
(STATES[1], states.Pulled),
(STATES[2], states.Pulled),
(STATES[0], states.Shared),
(STATES[1], states.Shared),
(STATES[2], states.Shared),
(STATES[3], states.Deprecated),
(STATES[4], states.Deprecated),
(STATES[5], states.Pulled),
(STATES[6], states.Pulled),
(STATES[5], states.Shared),
(STATES[6], states.Shared),
(STATES[7], states.Tainted),
(STATES[8], states.Deprecated),
(STATES[9], states.Pulled),
(STATES[9], states.Shared),
(STATES[10], states.Tainted),
(STATES[11], states.Deprecated),
],
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_uow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_updates_are_applied_to_gateway_on_commit() -> None:
uow.link[create_identifier("2")].delete()
uow.commit()
actual = {(entity.identifier, entity.state) for entity in gateway.create_link()}
expected = {(create_identifier("1"), states.Pulled), (create_identifier("2"), states.Unshared)}
expected = {(create_identifier("1"), states.Shared), (create_identifier("2"), states.Unshared)}
assert actual == expected


Expand All @@ -34,7 +34,7 @@ def test_updates_are_discarded_on_context_exit() -> None:
uow.link[create_identifier("1")].pull()
uow.link[create_identifier("2")].delete()
actual = {(entity.identifier, entity.state) for entity in gateway.create_link()}
expected = {(create_identifier("1"), states.Unshared), (create_identifier("2"), states.Pulled)}
expected = {(create_identifier("1"), states.Unshared), (create_identifier("2"), states.Shared)}
assert actual == expected


Expand All @@ -45,7 +45,7 @@ def test_updates_are_discarded_on_rollback() -> None:
uow.link[create_identifier("2")].delete()
uow.rollback()
actual = {(entity.identifier, entity.state) for entity in gateway.create_link()}
expected = {(create_identifier("1"), states.Unshared), (create_identifier("2"), states.Pulled)}
expected = {(create_identifier("1"), states.Unshared), (create_identifier("2"), states.Shared)}
assert actual == expected


Expand Down Expand Up @@ -143,13 +143,13 @@ def test_correct_events_are_collected() -> None:
events.StateChanged(
Operations.PROCESS,
create_identifier("1"),
Transition(states.Received, states.Pulled),
Transition(states.Received, states.Shared),
Commands.FINISH_PULL_PROCESS,
),
events.StateChanged(
Operations.START_DELETE,
create_identifier("2"),
Transition(states.Pulled, states.Received),
Transition(states.Shared, states.Received),
Commands.START_DELETE_PROCESS,
),
events.StateChanged(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/entities/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestCreateLink:
(states.Unshared, create_identifiers("1")),
(states.Activated, create_identifiers("2", "7")),
(states.Received, create_identifiers("3", "8")),
(states.Pulled, create_identifiers("4")),
(states.Shared, create_identifiers("4")),
(states.Tainted, create_identifiers("5")),
(states.Deprecated, create_identifiers("6")),
],
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/entities/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(create_identifier("1"), states.Unshared, [Operations.START_DELETE, Operations.PROCESS]),
(create_identifier("2"), states.Activated, [Operations.START_PULL, Operations.START_DELETE]),
(create_identifier("3"), states.Received, [Operations.START_PULL, Operations.START_DELETE]),
(create_identifier("4"), states.Pulled, [Operations.START_PULL, Operations.PROCESS]),
(create_identifier("4"), states.Shared, [Operations.START_PULL, Operations.PROCESS]),
(create_identifier("5"), states.Tainted, [Operations.START_PULL, Operations.PROCESS]),
(
create_identifier("6"),
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_processing_activated_entity_returns_correct_entity(
@pytest.mark.parametrize(
("process", "tainted_identifiers", "new_state", "new_process", "command"),
[
(Processes.PULL, set(), states.Pulled, Processes.NONE, Commands.FINISH_PULL_PROCESS),
(Processes.PULL, set(), states.Shared, Processes.NONE, Commands.FINISH_PULL_PROCESS),
(Processes.PULL, create_identifiers("1"), states.Tainted, Processes.NONE, Commands.FINISH_PULL_PROCESS),
(Processes.DELETE, set(), states.Activated, Processes.DELETE, Commands.REMOVE_FROM_LOCAL),
(Processes.DELETE, create_identifiers("1"), states.Activated, Processes.DELETE, Commands.REMOVE_FROM_LOCAL),
Expand Down Expand Up @@ -132,12 +132,12 @@ def test_processing_received_entity_returns_correct_entity(
assert list(entity.events) == expected_events


def test_starting_delete_on_pulled_entity_returns_correct_entity() -> None:
def test_starting_delete_on_shared_entity_returns_correct_entity() -> None:
link = create_link(
create_assignments({Components.SOURCE: {"1"}, Components.OUTBOUND: {"1"}, Components.LOCAL: {"1"}})
)
entity = next(iter(link))
transition = Transition(states.Pulled, states.Received)
transition = Transition(states.Shared, states.Received)
expected_events = [
events.StateChanged(
Operations.START_DELETE,
Expand Down

0 comments on commit 00ceed1

Please sign in to comment.