Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

add lock to db #34

Merged
merged 1 commit into from
May 9, 2020
Merged

add lock to db #34

merged 1 commit into from
May 9, 2020

Conversation

phritz
Copy link
Contributor

@phritz phritz commented May 9, 2020

  • add a lock around db.head
  • fix instances where we read head multiple times in the same operation and assume it hasn't changed
  • use db.Head() where possible

fixes rocicorp/replicache#42

@vercel
Copy link

vercel bot commented May 9, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/rocicorp/diff-server/e3wo4r50p
✅ Preview: https://diff-server-git-db.rocicorp.now.sh

Copy link
Contributor

@aboodman aboodman left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -23,17 +23,17 @@ func fullSync(db *DB, from hash.Hash) ([]kv.Operation, Commit) {
return r, makeCommit(db.Noms(), types.Ref{}, datetime.Epoch, db.ds.Database().WriteValue(m.NomsMap()), m.NomsChecksum(), 0 /*lastMutationID*/)
}

func (db *DB) Diff(from hash.Hash, fromChecksum kv.Checksum) ([]kv.Operation, error) {
func (db *DB) Diff(fromHash hash.Hash, fromChecksum kv.Checksum, to Commit) ([]kv.Operation, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's not part of this change, but why does this function require fromChecksum? It already has a Noms hash (presumably because client sent it) -- could the checksum really not match?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AIUI the protocol treats the state id as an opaque token and it is just convenient (and helpful) that it is a noms hash. The mechansim we have to ensure the two maps are identical is the checksum, so seems prudent to use it for that purpose. I admit that I have a hard time imagining how they might not match, but you don't build safety nets if you can see all the potential problems I guess.

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.

use accessors to get and set db.head
2 participants