Skip to content

questions over userStatesMtx #662

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

Closed
bboreham opened this issue Jan 18, 2018 · 1 comment
Closed

questions over userStatesMtx #662

bboreham opened this issue Jan 18, 2018 · 1 comment
Labels

Comments

@bboreham
Copy link
Contributor

Exhibit 1:

func (i *Ingester) query(ctx context.Context, from, through model.Time, matchers []*labels.Matcher) (model.Matrix, error) {
	i.queries.Inc()

	i.userStatesMtx.RLock()
	defer i.userStatesMtx.RUnlock()
	state, err := i.userStates.getOrCreate(ctx)

In what sense is this a Read lock if we can Create a user state inside it?
And why do we hold this lock (over all user states) for the duration of the query over one?
There are five other RLock calls which are very similar.

Exhibit 2:

// TransferChunks receives all the chunks from another ingester.
func (i *Ingester) TransferChunks(stream client.Ingester_TransferChunksServer) error {
[...]
	i.userStatesMtx.Lock()
	defer i.userStatesMtx.Unlock()

	if err := i.ChangeState(ring.ACTIVE); err != nil {
		return err
	}
	i.userStates = userStates

	return nil

This is the only place a write-lock is taken on userStatesMtx, and only for as long as it takes to CAS the state change.

Since there is a lock mtx inside userStates protecting its data, I suspect that userStatesMtx is left-over from some earlier implementation that needed it.

@tomwilkie
Copy link
Contributor

I think this has been answered in #859? The lock protects the pointer to userStates, which is only ever changed in TransferChunks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants