[WIP] allow lookup by prefix on ID and Name for jobs#199
[WIP] allow lookup by prefix on ID and Name for jobs#199vieux wants to merge 6 commits intomoby:masterfrom vieux:prefix
Conversation
Current coverage is
|
manager/state/memory.go
Outdated
| Indexes: map[string]*memdb.IndexSchema{ | ||
| indexPrefix: { | ||
| Name: indexPrefix, | ||
| Unique: true, |
There was a problem hiding this comment.
This index cannot be unique. The independent name and id index must be unique, but we need this to be non-unique.
This allows you to do two things:
- Names and identifiers can collide. This is a bad thing but we must allow it.
- Ambiguous names/identifiers can be detected and resolved.
Effectively, if we have a query against this index that this non-unique, we can identify and address the ambiguous items.
For example, let's say we create an object with name a and generate and identifier with the name a. Independently, these should be allowed. There is no requirement for these spaces to be disjoint. If we make the index unique, it is ambiguous as to which entry wins. If both are there, we know they are ambiguous and can have a user take action to resolve the problem, either by changing the name, id or just providing a more specific query (ie id=a) when referencing an object.
|
@vieux Yes, this looks good. As a rule, we shouldn't support "fuzzy" prefix lookup for Get methods. Get methods should only be by id. All of the user facing query functionality should be support through |
|
@stevvooe what about using |
cmd/swarmctl/job/edit.go
Outdated
|
|
||
| id := common.LookupID(common.Context(cmd), c, api.Job{}, args[0]) | ||
| r, err := c.GetJob(common.Context(cmd), &api.GetJobRequest{JobID: id}) | ||
| r, err := c.GetJob(common.Context(cmd), &api.GetJobRequest{JobID: args[0]}) |
There was a problem hiding this comment.
This is part of the issue. We should only using the id from a ListXXXRequest. There is no reason to make the JobID field fancy.
|
@vieux I think the standard lookup for names/ids should be to use ListXXX, the use the id to lookup the object. It means we pay for extra requests but we get consistency. We can always address performance with a cache or have a protobuf that clients can get on startup that sends an index. |
|
@stevvooe what you saying is going a round trip in the cli ? |
|
@vieux Yep. This keeps the API consistent. The other option is to define query options in the |
|
I went for option 1 for now. |
|
LGTM for now. We need to spend some time on the selector design. This is going to be important for selecting any object by |
|
ping @aluzzardi @aaronlehmann |
Signed-off-by: Victor Vieux <vieux@docker.com>
Signed-off-by: Victor Vieux <vieux@docker.com>
Signed-off-by: Victor Vieux <vieux@docker.com>
Signed-off-by: Victor Vieux <vieux@docker.com>
Signed-off-by: Victor Vieux <vieux@docker.com>
|
@stevvooe how about we use the prefix capabilities of |
api/cluster.proto
Outdated
| } | ||
|
|
||
| message ListJobsRequest { | ||
| string prefix = 1; |
|
I'm okay with this approach, but I have a few concerns before we merge this:
|
| } | ||
| if j, ok := obj.(*api.Job); ok { | ||
| jobs = append(jobs, j.Copy()) | ||
| if _, exists := ids[j.ID]; !exists { |
There was a problem hiding this comment.
if a job the same ID and Name, it will be returned twice without this.
|
@aaronlehmann I'm going to compare bench |
|
I posted a version without the new index in #210 alongside with bench comparison. #210 is mush faster, I think we should close this PR /cc @aaronlehmann |
depends on hashicorp/go-memdb#17
result from bench: