Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Implement event sourced saga persistence. #52

Merged
merged 28 commits into from
May 25, 2018
Merged

Implement event sourced saga persistence. #52

merged 28 commits into from
May 25, 2018

Conversation

jmalloc
Copy link
Owner

@jmalloc jmalloc commented May 25, 2018

Fixes #46

jmalloc added 15 commits May 23, 2018 07:44
…he saga subsystem.

- Renamed `saga.Repository` to `InstanceRepository`
- Renamed `eventsourcing.Repository` to `InstanceRepository`
- Collapsed the snapshotting/non-snapshotting implementations of
  saga.InstanceRepository` into a single `StandardInstanceReposiotry` struct
This is in preparation for allowing use of evented data instances for CRUD sagas.
Also remove the `ctx` parameter and `error` return value, as creating a new
data instance should always by a simple construction operation.
@codecov-io
Copy link

codecov-io commented May 25, 2018

Codecov Report

Merging #52 into master will decrease coverage by 10.78%.
The diff coverage is 2.52%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #52       +/-   ##
===========================================
- Coverage   56.52%   45.74%   -10.79%     
===========================================
  Files          35       38        +3     
  Lines        1118     1388      +270     
===========================================
+ Hits          632      635        +3     
- Misses        476      743      +267     
  Partials       10       10
Impacted Files Coverage Δ
src/axmysql/sagarepository.go 0% <0%> (ø)
src/axmysql/sagasnapshot.go 0% <0%> (ø)
src/axmysql/sagamapper.go 0% <0%> (ø)
src/axmysql/messagestore.go 0% <0%> (ø)
src/ax/endpoint/sender.go 100% <100%> (ø) ⬆️
src/axmysql/transaction.go 50% <100%> (+50%) ⬆️
src/axmysql/outbox.go 87.03% <80%> (+0.12%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29fe169...7cb5463. Read the comment docs.

@jmalloc jmalloc requested a review from koden-km May 25, 2018 03:25
) error

// OpenStream opens a stream of messages for reading from a specific offset.
OpenStream(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document possible error conditions such as opening from an out of range offset, or stream not existing.

// in its key set.
//
// sn is the saga name. k is the message mapping key.
// LoadSagaInstance fetches a saga instance by its ID.
//
// If a saga instance is found; ok is true, otherwise it is false. A
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ok return value has been removed.

return "saga:" + id.Get()
}

// appendEvents appends the events in envs to the message stream for the given
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems ok, but should it be talking about the "message stream" or "message store".

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is ok, internally it calls ms.AppendEvents(), the docs of which are:

// AppendMessages appends one or more messages to a named stream.

// Data is the application-defined data associated with this instance.
Data Data

// Revision is version of the instance that the data represents.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the ?

Revision is the version

ctx context.Context,
tx persistence.Tx,
sn, k string,
) (InstanceID, bool, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming bool is ok. Should this be documented?


// Save persists changes to the instance.
// It returns true if any changes have occurred.
Save(ctx context.Context) (bool, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does bool need to be documented as ok ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case it's ok just to say "it returns true" as that's the primary piece of data it returns.

func (MessageStore) insertStream(
ctx context.Context,
tx *sql.Tx,
s string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use more descriptive naming for self documenting?

func (MessageStore) incrStreamOffset(
ctx context.Context,
tx *sql.Tx,
s string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use more descriptive naming for self documenting?

s string,
o uint64,
n uint64,
) (int64, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this int64 return value be documented?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's much need when there's only a single non-error return value. The function description does document what it returns -- it's just not named.

--

--
-- messagestore_global stores the next global message offset across all streams.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean messagestore_offset ?

messagestore_global

global_offset BIGINT UNSIGNED NOT NULL,
insert_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),

stream_id BIGINT UNSIGNED NOT NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Column alignment?

ctx context.Context,
ptx persistence.Tx,
sn, k string,
) (saga.InstanceID, bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming bool is ok. Should this be documented?

// LoadSagaInstance fetches a saga instance that has a specific mapping key
// in its key set.
//
// sn is the saga name. k is the message mapping key.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should not exist? There is no sn or k.

Copy link
Collaborator

@koden-km koden-km May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this whole doc block should be reviewed? There is no ok to return, and it looks up by id, not key sets?

}

// SaveSagaInstance persists a saga instance and its associated mapping
// table to the store as part of tx.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ptx instead of tx ?

// SaveSagaInstance persists a saga instance and its associated mapping
// table to the store as part of tx.
//
// It returns an error if the saga instance has been modified since it was
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the whole idea to save modifications?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's poorly worded, it should say "modified by another process" or something like that.

@@ -0,0 +1,16 @@
--
-- This file defines the SQL schema used by SagaInstanceRepository.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SagaInstanceRepository does not exist?

--

--
-- saga_data stores saga.Data instances for each instance of a CRUD saga.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean saga_instance ?

saga_data

// SaveSagaSnapshot saves a snapshot to the store.
func (SnapshotRepository) SaveSagaSnapshot(
ctx context.Context,
tx persistence.Tx,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You called this ptx in the LoadSagaSnapshot() method. Rename one for consistency?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, could go either way. I did this because in the implementation ptx is the one that you use the least. They don't have to match really.

@@ -0,0 +1,16 @@
--
-- This file defines the SQL schema used by SagaSnapshotRepository.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this type name change, I can't find it? SagaSnapshotRepository

--

--
-- saga_snapshot stores snapshots saga.Data instances for eventsourced sagas.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non plural snapshot ?

stores snapshots saga.Data

Copy link
Collaborator

@koden-km koden-km left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done review. Just the comments mentioned.

ctx context.Context,
ptx persistence.Tx,
id saga.InstanceID,
) (saga.Instance, bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming bool is ok. Should this be documented?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I skipped this one before, it was the last one. It seemed like the pattern was to not document those, but you did end up documenting those previously mentioned ones.

@jmalloc jmalloc merged commit 6ab701c into master May 25, 2018
@jmalloc jmalloc deleted the 46-eventsourcing branch May 25, 2018 05:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants