fabriziosestito / commanded-spear-adapter

Spear event store adapter for Commanded
MIT License
19 stars 5 forks source link

Ignore system events #10

Closed philipgiuliani closed 1 year ago

philipgiuliani commented 2 years ago

When performing a hard-delete of a stream, the adapter will receive a system event which cannot be handled.

Steps to reproduce:

  1. Create a new stream
  2. Delete the stream curl -i -X DELETE "http://127.0.0.1:2113/streams/prefix-stream_name" -H "ES-HardDelete:true"

Expected result: Stream gets deleted and applications works fine

Actual result: Application terminates with the following crash:

[error] GenServer {Commanded.EventStore.Adapters.Spear.Subscription, "$ce-prefix", "Dia.Beneficiary.Handlers.Emails", 0} terminating
** (UndefinedFunctionError) function :"$>".__struct__/0 is undefined (module :"$>" is not available)
    :"$>".__struct__()
    (elixir 1.13.4) lib/kernel.ex:2342: Kernel.struct/3
    (commanded 1.3.1) lib/commanded/serialization/json_serializer.ex:26: Commanded.Serialization.JsonSerializer.deserialize/2
    (commanded_spear_adapter 0.1.0) lib/commanded/event_store/adapters/extreme/mapper.ex:59: Commanded.EventStore.Adapters.Spear.Mapper.to_recorded_event/2
    (commanded_spear_adapter 0.1.0) lib/commanded/event_store/adapters/extreme/subscription.ex:102: Commanded.EventStore.Adapters.Spear.Subscription.handle_info/2
    (stdlib 4.0.1) gen_server.erl:1120: :gen_server.try_dispatch/4
    (stdlib 4.0.1) gen_server.erl:1197: :gen_server.handle_msg/6
    (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {#Reference<0.577788016.627048450.176481>, {:"event_store.client.persistent_subscriptions.ReadResp", {:event, {:"event_store.client.persistent_subscriptions.ReadResp.ReadEvent", :undefined, {:"event_store.client.persistent_subscriptions.ReadResp.ReadEvent.RecordedEvent", {:"event_store.client.UUID", {:string, "f962ef2f-36c6-4d79-aed6-bfa60ec18fa7"}}, {:"event_store.client.StreamIdentifier", "$ce-prefix"}, 2, 94932, 94932, %{"content-type" => "application/octet-stream", "created" => "16607371869697351", "type" => "$>"}, "{\"$v\":\"3:-1:1:4\",\"$c\":94552,\"$p\":94552,\"$o\":\"prefix-DTP4HWV4HV4K\",\"$deleted\":-1,\"$causedBy\":\"f4eb048c-b19f-4b65-aa5d-5ae7d26be4d7\"}", "9223372036854775807@prefix-DTP4HWV4HV4K"}, {:commit_position, 94932}, {:retry_count, 7}}}}}
State: %Commanded.EventStore.Adapters.Spear.Subscription{conn: Dia.App.Spear.Spear.Connection, last_seen_event_id: nil, last_seen_event_number: nil, name: "Dia.Beneficiary.Handlers.Emails", retry_interval: 60000, serializer: Commanded.Serialization.JsonSerializer, start_from: :current, stream: "$ce-prefix", subscribed?: true, subscriber: #PID<0.1387.0>, subscriber_max_count: 1, subscriber_ref: #Reference<0.577788016.627048449.177679>, subscription: #Reference<0.577788016.627048450.176481>}

The JSON deserializer will be called with the following arguments:

binary: "0@prefix-stream_name"
config: [type: "$>"]
fabriziosestito commented 2 years ago

NOTE: this was solved by a workaround in #14

Deleting a stream causes a system event to be sent to the persistent subscription to the $ce-prefix projection. This is unexpected since persistent subscriptions are created with the exclude_system_events filter.

Also, adding the filter to the catch-up subscription in the EventPublishers causes no events to be received.