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

Postgres error on fetching an aggregate on a fresh eventstore #84

Closed
lunetics opened this issue Jun 8, 2017 · 2 comments · Fixed by #85
Closed

Postgres error on fetching an aggregate on a fresh eventstore #84

lunetics opened this issue Jun 8, 2017 · 2 comments · Fixed by #85

Comments

@lunetics
Copy link
Member

lunetics commented Jun 8, 2017

--Update:--
It works with event bus bridge disabled!! so it's not an PDO event store error, but a event bus bridge (event publisher?)

Postgres log without event bus bridge:

2017-06-08 21:09:30.149 UTC,"checkout","event_store",18714,"127.0.0.1:50758",5939bd00.491a,1,"PARSE",2017-06-08 21:09:20 UTC,5/654,0,ERROR,42P01,"relation ""_1ab510b111f0b82586710baf96ce47d895b3807a"" does not exist",,,,,,"SELECT * FROM _1ab510b111f0b82586710baf96ce47d895b3807a
WHERE no >= $1
ORDER BY no ASC
LIMIT $2;",15,,""
2017-06-08 21:09:32.879 UTC,"checkout","event_store",18714,"127.0.0.1:50758",5939bd00.491a,2,"INSERT",2017-06-08 21:09:20 UTC,5/656,0,LOG,00000,"execute pdo_stmt_00000002: INSERT INTO event_streams (real_stream_name, stream_name, metadata, category)
VALUES ($1, $2, $3, $4);","parameters: $1 = 'customer_checkout-e657ef5a-d6d4-4cd6-bb5e-3924928f725a', $2 = '_1ab510b111f0b82586710baf96ce47d895b3807a', $3 = '{}', $4 = 'customer_checkout'",,,,,,,,""
2017-06-08 21:09:32.880 UTC,"checkout","event_store",18714,"127.0.0.1:50758",5939bd00.491a,3,"idle",2017-06-08 21:09:20 UTC,5/657,0,LOG,00000,"statement: DEALLOCATE pdo_stmt_00000002",,,,,,,,,""
2017-06-08 21:09:32.880 UTC,"checkout","event_store",18714,"127.0.0.1:50758",5939bd00.491a,4,"CREATE TABLE",2017-06-08 21:09:20 UTC,5/659,0,LOG,00000,"execute pdo_stmt_00000003: CREATE TABLE _1ab510b111f0b82586710baf96ce47d895b3807a (
    no BIGSERIAL,
    event_id CHAR(36) NOT NULL,
    event_name VARCHAR(100) NOT NULL,
    payload JSON NOT NULL,
    metadata JSONB NOT NULL,
    created_at TIMESTAMP(6) NOT NULL,
    PRIMARY KEY (no),
    UNIQUE (event_id)
);",,,,,,,,,""
2017-06-08 21:09:32.907 UTC,"checkout","event_store",18714,"127.0.0.1:50758",5939bd00.491a,5,"idle",2017-06-08 21:09:20 UTC,5/660,0,LOG,00000,"statement: DEALLOCATE pdo_stmt_00000003",,,,,,,,,""
2017-06-08 21:09:32.908 UTC,"checkout","event_store",18714,"127.0.0.1:50758",5939bd00.491a,6,"CREATE INDEX",2017-06-08 21:09:20 UTC,5/662,0,LOG,00000,"execute pdo_stmt_00000004: CREATE UNIQUE INDEX on _1ab510b111f0b82586710baf96ce47d895b3807a ((metadata->>'_aggregate_version'));",,,,,,,,,""
2017-06-08 21:09:32.917 UTC,"checkout","event_store",18714,"127.0.0.1:50758",5939bd00.491a,7,"idle",2017-06-08 21:09:20 UTC,5/663,0,LOG,00000,"statement: DEALLOCATE pdo_stmt_00000004",,,,,,,,,""
2017-06-08 21:09:32.918 UTC,"checkout","event_store",18714,"127.0.0.1:50758",5939bd00.491a,8,"INSERT",2017-06-08 21:09:20 UTC,5/665,0,LOG,00000,"execute pdo_stmt_00000005: INSERT INTO _1ab510b111f0b82586710baf96ce47d895b3807a (no, event_id, event_name, payload, metadata, created_at) VALUES ($1, $2, $3, $4, $5, $6)","parameters: $1 = '1', $2 = '86f0b94e-2d05-4cea-a1d7-78db839a7f54', $3 = 'Justix\Checkout\Domain\Model\CustomerCheckout\Event\CheckoutStarted', $4 = '{""source"":""cms""}', $5 = '{""_aggregate_id"": ""e657ef5a-d6d4-4cd6-bb5e-3924928f725a"", ""_aggregate_type"": ""Justix\\Checkout\\Domain\\Model\\CustomerCheckout\\CustomerCheckout"", ""_aggregate_version"": 1}', $6 = '2017-06-08 21:09:32.031817'",,,,,,,,""
2017-06-08 21:09:32.919 UTC,"checkout","event_store",18714,"127.0.0.1:50758",5939bd00.491a,9,"idle",2017-06-08 21:09:20 UTC,5/666,0,LOG,00000,"statement: DEALLOCATE pdo_stmt_00000005",,,,,,,,,""

Also on the failure below, the "parameters" of the insert are "empty"
--Given--

  1. A fresh event store on postgres (no data / saved aggregates)

  2. Try to get an aggregate via repository will return an error in the addStreamToStreamsTable method.

Error:
ERROR 25P02 current transaction is aborted, commands ignored until end of transaction block

Postgreslog:

2017-06-08 18:39:40.681 UTC,"checkout","event_store",15963,"127.0.0.1:46546",593999ec.3e5b,1,"idle",2017-06-08 18:39:40 UTC,3/50,0,LOG,00000,"statement: BEGIN",,,,,,,,,""
2017-06-08 18:39:40.682 UTC,"checkout","event_store",15963,"127.0.0.1:46546",593999ec.3e5b,2,"PARSE",2017-06-08 18:39:40 UTC,3/50,0,ERROR,42P01,"relation ""_1ab510b111f0b82586710baf96ce47d895b3807a"" does not exist",,,,,,"SELECT * FROM _1ab510b111f0b82586710baf96ce47d895b3807a
WHERE no >= $1
ORDER BY no ASC
LIMIT $2;",15,,""
2017-06-08 18:39:40.688 UTC,"checkout","event_store",15963,"127.0.0.1:46546",593999ec.3e5b,3,"PARSE",2017-06-08 18:39:40 UTC,3/0,0,ERROR,25P02,"current transaction is aborted, commands ignored until end of transaction block",,,,,,"INSERT INTO event_streams (real_stream_name, stream_name, metadata, category)
VALUES ($1, $2, $3, $4);",,,""
2017-06-08 18:39:40.689 UTC,"checkout","event_store",15963,"127.0.0.1:46546",593999ec.3e5b,4,"idle in transaction (aborted)",2017-06-08 18:39:40 UTC,3/0,0,LOG,00000,"statement: ROLLBACK",,,,,,,,,""

Also i tried to dig deeper, maybe that helps:

ID = 123;

  1. try to fetch non-existing aggregate by ID 123 -> StreamNotFound

  2. try to create and save / add aggregate with ID 123

example command handler:

  public function __invoke(InitiateCheckout $command)
    {
        $customerCheckout = $this->customerCheckoutCollection->get($command->checkoutId());
        if ($customerCheckout instanceof CustomerCheckout) {
            $customerCheckout->restartCheckout();
            $this->customerCheckoutCollection->add($customerCheckout);

            return;
        }

        $customerCheckout = CustomerCheckout::startedFromSource($command->checkoutId(), $command->source());
        $this->customerCheckoutCollection->add($customerCheckout);
    }
@lunetics
Copy link
Member Author

lunetics commented Jun 8, 2017

@prolic also see: prooph/event-store-bus-bridge#29

don't know who is responsible, so it's up to you to close the wrong one :)

@prolic
Copy link
Member

prolic commented Jun 9, 2017

Here is the test-case:

    /**
     * @test
     */
    public function it_loads_and_saves_within_one_transaction(): void
    {
        $testStream = $this->getTestStream();

        $this->eventStore->beginTransaction();

        $streamNotFound = false;

        try {
            $this->eventStore->load($testStream->streamName());
        } catch (StreamNotFound $e) {
            $streamNotFound = true;
        }

        $this->assertTrue($streamNotFound);

        $this->eventStore->create($testStream);

        $this->eventStore->commit();
    }

The problem is the load & save within same transaction. The load failed, therefore the transaction failed. Any ideas how to handle this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants