Skip to content

Comments

no need to re-fetch the nameIndex during docker ps queries#33885

Closed
fabiokung wants to merge 1 commit intomoby:masterfrom
fabiokung:out-of-sync-nameindex
Closed

no need to re-fetch the nameIndex during docker ps queries#33885
fabiokung wants to merge 1 commit intomoby:masterfrom
fabiokung:out-of-sync-nameindex

Conversation

@fabiokung
Copy link
Contributor

@fabiokung fabiokung commented Jun 29, 2017

... by always using the one that has been snapshotted for each query.

Related to #33863

Signed-off-by: Fabio Kung [email protected]

/cc @aaronlehmann @thaJeztah

@aaronlehmann
Copy link

I don't think this solves the problem because the snapshotting of the containers themselves and the name index are done separately, with no guarantee that they return consistent results. To do this properly, we would have to add a name index to the memdb and rely on its atomic snapshotting. This would involve changing the type of data we store in the memdb from Container to a wrapper that contains a Container and a names field, and updating the names in the memdb whenever a change is made to the Registrar.

@aaronlehmann
Copy link

(...or even better, remove Registrar completely and use the memdb as the authoritative source of naming information instead).

@fabiokung
Copy link
Contributor Author

fabiokung commented Jun 30, 2017

I agree that would be a better design, but also a bigger change.

You are right that the snapshotting of containers and nameIndex happens separately, but they are very close: https://github.com/moby/moby/blob/master/container/view.go#L88-L89

Maybe slightly extending the Registrar.mu.Lock() and doing the memdb snapshot while holding that lock is a simpler fix?

@fabiokung
Copy link
Contributor Author

... in that case we should also deep copy the []string slices in (*Registrar).GetAll()

@fabiokung
Copy link
Contributor Author

I changed the commit message to indicate that this is not a fix, only a slight improvement, since we shouldn't be calling daemon.nameIndex.GetAll() again in (*Daemon).foldFilter and just use what the snapshot has.

... by reusing the one that has been acquired for each query while
taking a snapshot of the in-memory db.

More context on moby#33863

Signed-off-by: Fabio Kung <[email protected]>
@aaronlehmann
Copy link

It seems like we're in agreement that pulling this information in the memdb is a better design.

I agree that holding a lock around the snapshotting process could potentially work, but it would require expensive deep copies, and negate part of the benefit of this new lock-free code path.

Unless there is a problem with using an out-of-date nameindex, I'd prefer to either leave this as-is or move everything into the memdb when we find time.

BTW, it seems really broken that GetAll is returning slices that can be modified later on. It looks inherently racy. Seems like an argument for replacing it with an index on the memdb.

@fabiokung fabiokung force-pushed the out-of-sync-nameindex branch from d348adb to b62c627 Compare June 30, 2017 00:23
@fabiokung
Copy link
Contributor Author

Yep, I agreed with you at #33863 (comment)

(sorry for spreading the discussion onto multiple threads)

@fabiokung fabiokung changed the title prevent using an out-of-sync nameIndex no need to re-fetch the nameIndex during docker ps queries Jun 30, 2017
@aaronlehmann
Copy link

I'm going to try moving the replacing the registrar stuff with an index on the memdb.

I'll open a PR, either tonight or sometime next week.

@thaJeztah
Copy link
Member

does that mean we should close this PR? Thanks for thinking along btw, @fabiokung, much appreciated

@aaronlehmann
Copy link

I've opened #33886. It still needs testing, and possibly additional changes to make adding containers/names transactional, but I think the concept is sound.

I think we can close this one if people are happy with the direction #33886 is going.

@fabiokung
Copy link
Contributor Author

Let's reopen as needed.

@fabiokung fabiokung closed this Jun 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants