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

threads: fetch all unknown records #132

Merged
merged 7 commits into from
Nov 28, 2019
Merged

Conversation

jsign
Copy link
Contributor

@jsign jsign commented Nov 26, 2019

Fixes #128

Apart from that main fix, I'll add some further comments with some considerations that I'd like @sanderpick opinion.

Signed-off-by: jsign <[email protected]>
Signed-off-by: jsign <[email protected]>
Signed-off-by: jsign <[email protected]>
Signed-off-by: jsign <[email protected]>
Signed-off-by: jsign <[email protected]>
Copy link
Contributor Author

@jsign jsign left a comment

Choose a reason for hiding this comment

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

These changes seem to completely fix the problem in the folder-sync app regarding can't update instance that doesn't exit, which was the consecuence of missing records.
In particular, save events for instances were being processed without receiving the create event that should prior.

cbor/event.go Show resolved Hide resolved
cbor/event.go Show resolved Hide resolved
client.go Show resolved Hide resolved
cbor/record.go Outdated Show resolved Hide resolved
eventstore/storethread.go Show resolved Hide resolved
threads.go Show resolved Hide resolved
threads.go Show resolved Hide resolved
threads.go Show resolved Hide resolved
threads.go Show resolved Hide resolved
threads.go Show resolved Hide resolved
@jsign jsign marked this pull request as ready for review November 26, 2019 20:54
@jsign
Copy link
Contributor Author

jsign commented Nov 26, 2019

This was an important step to have some correctness in the underlying working of threads.
The next step will be making concurrency safe per-thread at least (for some work it could be concurrent per log but we can leave that for an extra opt in the future).

TBH, I tried to make those changes in this PR, but they're a bit more complicated because I think I should move some code to other places (so to no double lock the same mutex, etc). Prefer to keep this PR as short as possible.

@jsign jsign added this to the Sprint 24 milestone Nov 26, 2019
@jsign jsign self-assigned this Nov 26, 2019
Signed-off-by: jsign <[email protected]>
Copy link
Member

@sanderpick sanderpick left a comment

Choose a reason for hiding this comment

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

Great! I left some non-blocking questions and made some comments that could be turned into issues if the ideas sounds reasonable.

eventstore/storethread.go Show resolved Hide resolved
Comment on lines +121 to 130

// Fix concurrency: adding head without having the block guarantee
if err := s.threads.store.AddLog(req.ThreadID.ID, lg); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

go func() {
func() {
// Get log records for this new log
recs, err := s.getRecords(
s.threads.ctx,
Copy link
Member

Choose a reason for hiding this comment

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

Remembering the logic... you should only receive a log here if you got pushed a record without having the log, at which point you'd request it. However, that doesn't stand as a good enough safety measure. There's a TODO in the method comment mentioning that we ought to only overwrite the log if it comes from the owner. Maybe that only applies to the addresses: update the addresses if the sender is the log owner. I may have left the TODO here because there isn't currently a way to tell if the sender is the owner (also related to the verification TODO). Each log can be signed with the log's private key if the sender has it.

Agreed, updating the head should probably not be done here.

Comment on lines +191 to +196
t.pullLock.Lock()
defer t.pullLock.Unlock()
// Wait for all thread pulls to finish
for _, semaph := range t.pullLocks {
semaph <- struct{}{}
}
Copy link
Member

Choose a reason for hiding this comment

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

Clever!


// PullThread for new records.
// Logs owned by this host are traversed locally.
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this PR, but this comment must be outdated / relic from the old pull functionality.

threads.go Show resolved Hide resolved
threads.go Show resolved Hide resolved
threads.go Show resolved Hide resolved
@jsign
Copy link
Contributor Author

jsign commented Nov 27, 2019

Great! I left some non-blocking questions and made some comments that could be turned into issues if the ideas sounds reasonable.

Replied to all comments.

I'll merge tomorrow. Feel free to create issues for many points of discussion. Will be nice to have them written before forgetting since all are quite important/interesting.

@jsign jsign merged commit 4b3ce43 into textileio:master Nov 28, 2019
@jsign jsign deleted the fixconcurr branch November 28, 2019 12:14
@sanderpick
Copy link
Member

sanderpick commented Nov 28, 2019

I’ve made a note to create some issues from the discussions. Will do when I’m back on!

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 this pull request may close these issues.

store: putRecord should fetch history and notify in order
2 participants