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

Datastore v2 #581

Merged
merged 15 commits into from
May 20, 2022
Merged

Datastore v2 #581

merged 15 commits into from
May 20, 2022

Conversation

jakedt
Copy link
Member

@jakedt jakedt commented May 2, 2022

Fixes #118

@jakedt jakedt added the area/datastore Affects the storage system label May 2, 2022
@jakedt jakedt requested a review from a team as a code owner May 2, 2022 17:47
@jakedt jakedt marked this pull request as draft May 2, 2022 17:47
@github-actions github-actions bot added area/dependencies Affects dependencies area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels May 2, 2022
@jakedt jakedt force-pushed the datastore-v2 branch 2 times, most recently from 5d5ebd8 to ff3ac89 Compare May 4, 2022 19:01
@github-actions github-actions bot added area/api v0 Affects the v0 API area/api v1 Affects the v1 API area/CLI Affects the command line area/dashboard Affects the dashboard area/dispatch Affects dispatching of requests labels May 4, 2022
@github-actions github-actions bot removed the area/dependencies Affects dependencies label May 4, 2022
@jakedt jakedt force-pushed the datastore-v2 branch 4 times, most recently from 9e5f9ac to 6cb191f Compare May 10, 2022 14:14
@github-actions github-actions bot added the area/dependencies Affects dependencies label May 10, 2022
@jakedt jakedt force-pushed the datastore-v2 branch 2 times, most recently from fa897aa to 4ecb13a Compare May 10, 2022 22:21
@jakedt jakedt marked this pull request as ready for review May 10, 2022 22:23
@jakedt jakedt requested a review from vroldanbet as a code owner May 10, 2022 22:23
@jakedt
Copy link
Member Author

jakedt commented May 10, 2022

I will look into resolving any E2E test problems, but I don't think it should hold up the review.

jzelinskie
jzelinskie previously approved these changes May 17, 2022
Copy link
Member

@jzelinskie jzelinskie left a comment

Choose a reason for hiding this comment

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

🥹

DeleteRelationships(ctx context.Context, preconditions []*v1.Precondition, filter *v1.RelationshipFilter) (Revision, error)
// ReadWriteTx tarts a read/write transaction, which will be committed if no error is
// returned and rolled back if an error is returned.
ReadWriteTx(context.Context, TxUserFunc) (Revision, error)

// OptimizedRevision gets a revision that will likely already be replicated
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment right? I can't expand it for some reason

// occurred when building the transaction.
type TxFactory func(context.Context) (pgx.Tx, TxCleanupFunc, error)

func NewPGXExecutor(txSource TxFactory) ExecuteQueryFunc {
Copy link
Member

Choose a reason for hiding this comment

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

Doc comment?


cleanup := func(ctx context.Context) {
if err := tx.Rollback(ctx); err != nil {
log.Ctx(ctx).Err(err).Msg("error rolling back transaction")
Copy link
Member

Choose a reason for hiding this comment

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

Add additional context to the error message, since it is the same message as below, and once line numbers move, it'll be harder to pin down the exact location if we see the error occur

Copy link
Member Author

Choose a reason for hiding this comment

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

i mean they will have different underlying errors.

bulkTouch := queryTouchTuple
var bulkTouchCount int64

// Process the actual updates var tupleCountChange int64
Copy link
Member

Choose a reason for hiding this comment

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

var tupleCountChange int64?

func (rwt *crdbReadWriteTXN) DeleteRelationships(filter *v1.RelationshipFilter) error {
ctx, span := tracer.Start(datastore.SeparateContextWithTracing(rwt.ctx), "DeleteRelationships")
defer span.End()
// Add clauses for the ResourceFilter
Copy link
Member

Choose a reason for hiding this comment

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

newline before this line

if err != nil {
return fmt.Errorf(errUnableToWriteConfig, err)
}
query = query.Values(newConfig.Name, serialized)
Copy link
Member

Choose a reason for hiding this comment

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

We might have a risk of hitting query limits here too

Copy link
Member Author

@jakedt jakedt May 19, 2022

Choose a reason for hiding this comment

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

Yeah, there is a hard upper bound on how big our schema can get now, but it's unlikely to hit this limit without first hitting the overall schema byte limit.

return tx, err
}

newRevision := revisionFromTimestamp(time.Now().UTC())
Copy link
Member

Choose a reason for hiding this comment

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

+1

}
if tx != nil {
for _, change := range tx.Changes() {
if change.Table == "relationship" {
Copy link
Member

Choose a reason for hiding this comment

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

Place the table name into a const

}

// caller must already hold the concurrent access lock
func (rwt *memdbReadWriteTx) delete(tx *memdb.Txn, filter *v1.RelationshipFilter) error {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe name to indicate the caller must hold the lock?

return nil, fmt.Errorf("failed to open connection to db: %w", err)
}

// The go mysql driver implements the ExecerContext interface, assert that here.
Copy link
Member

Choose a reason for hiding this comment

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

ExecerContext?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean you can see it on the next line. What do you want here?

Copy link
Member

Choose a reason for hiding this comment

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

Just seems a weird name, but its fine

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't name it, it's part of the go sql interface.


rwt := &mysqlReadWriteTXN{
&mysqlReader{
mds.QueryBuilder,
Copy link
Member

Choose a reason for hiding this comment

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

True... it just makes it harder to read, but I'd rather have the safety.

))
}

func (r relationship) Relationship() *v1.Relationship {
Copy link
Member

Choose a reason for hiding this comment

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

I think the core package provides conversions that could remove the need for this

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is going from the flat struct that we use to represent a row in the memdb to the relationship.

Copy link
Member

Choose a reason for hiding this comment

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

We do convert to a core rel below, so we could in theory chain that way, but not sure it is worth it

ctx, span := tracer.Start(ctx, "WriteNamespaces")
defer span.End()

// span.SetAttributes(common.ObjNamespaceNameKey.String(newNamespace.Name))
Copy link
Member

Choose a reason for hiding this comment

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

Add a new key and set it to the list of namespace names?

Copy link
Member

@josephschorr josephschorr left a comment

Choose a reason for hiding this comment

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

LGTM

@jakedt jakedt enabled auto-merge May 20, 2022 17:04
@jakedt jakedt merged commit fc39ad4 into main May 20, 2022
@jakedt jakedt deleted the datastore-v2 branch May 20, 2022 19:53
@github-actions github-actions bot locked and limited conversation to collaborators May 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/api v0 Affects the v0 API area/api v1 Affects the v1 API area/CLI Affects the command line area/dashboard Affects the dashboard area/datastore Affects the storage system area/dependencies Affects dependencies area/dispatch Affects dispatching of requests area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Datastore interface should have more fine grained control over transactions
5 participants