Skip to content

Conversation

@SUMUKHA-PK
Copy link
Contributor

@SUMUKHA-PK SUMUKHA-PK commented Oct 5, 2020

This closes #24 and #29

…imer implementaion, splitting of domains for acquire and release, addition of context
…n the lock client: gracefulShutdown, maintaining list of current locks
…criptor and LockDescriptor separation, solving #29
@SUMUKHA-PK
Copy link
Contributor Author

Still needs to handle some race conditions when session time outs occur, add tests specific to sessions.

@SUMUKHA-PK SUMUKHA-PK marked this pull request as ready for review October 13, 2020 10:17
Copy link
Contributor

@suraj44 suraj44 left a comment

Choose a reason for hiding this comment

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

suggestion of having a mutex per process.
Really good work though! such clean CLEAN code!

}

// Parse parses an ID from a byte slice.
func Parse(idBytes []byte) (ID, 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 didn't understand what this function does exactly ? Why are there two version of an ID - string and bytes?

Also, it doesn't seem to be used elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's recommended to pass the ID in type ID but sometimes we do need its string form. Thus bytes.

close := make(chan struct{}, 1)
go func() {
for {
sc.mu.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think instead of having a single mutex for the whole client, it would make sense to have a mutex per process. because if MANY clients are connected to the client, and all of the call acquire() at around the same time then they'll all just be waiting (because others might get the lock first) but would ideally like for them to acquire there respective locks right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the way you've done this though! really nice :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You really missed the point of locks in that question. Locks are meant to serialise things. As you can see, we have a COMMON MAP session*, which when used in multiple goroutines cause a race. Thus a lock and thus a single lock.

}
}()
ld := lockservice.NewLockDescriptor(d.ID(), s.ProcessID().String())
err := sc.acquire(ctx, ld)
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't there be a lock() and unlock() before and after acquire()?

Copy link
Contributor

Choose a reason for hiding this comment

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

ohhhhh nice, you've handled the timeout in acquire() :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is a principle Ive used generally while writing raft w.r.t locks - if a function needs something to be locked, let it lock it inside itself and dont lock it before its called. It keeps the locks cleaner and within the scope of the problem.

@SUMUKHA-PK SUMUKHA-PK merged commit 9725fa7 into master Nov 8, 2020
@SUMUKHA-PK SUMUKHA-PK deleted the sessions branch November 8, 2020 03:20
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.

lockclient: Implement Session Management

3 participants