Skip to content

Commit

Permalink
Allow pools to be given a ksuid name
Browse files Browse the repository at this point in the history
The commit fixes an issue with pool looks that made it so pools with a
ksuid-like name could not be looked up for most zed commands. Fix the
logic for lake/api.PoolID so that looking up a pool by ID is tried first
and then falls back to looking up a pool by name if nothing is found.

Closes #4431
  • Loading branch information
mattnibs committed Feb 3, 2024
1 parent 5e986d3 commit 758bbf2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
7 changes: 2 additions & 5 deletions cmd/zed/use/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,9 @@ func (c *Command) Run(args []string) error {
if err != nil {
return err
}
poolID, err := lakeparse.ParseID(commitish.Pool)
poolID, err := lake.PoolID(ctx, commitish.Pool)
if err != nil {
poolID, err = lake.PoolID(ctx, commitish.Pool)
if err != nil {
return err
}
return err
}
if _, err = lake.CommitObject(ctx, poolID, commitish.Branch); err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions lake/api/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func (l *local) PoolID(ctx context.Context, poolName string) (ksuid.KSUID, error
if poolName == "" {
return ksuid.Nil, errors.New("no pool name provided")
}
if id, err := lakeparse.ParseID(poolName); err == nil {
if _, err := l.root.OpenPool(ctx, id); err == nil {
return id, nil
}
}
return l.root.PoolID(ctx, poolName)
}

Expand Down
5 changes: 5 additions & 0 deletions lake/api/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func (l *remote) Root() *lake.Root {
}

func (r *remote) PoolID(ctx context.Context, poolName string) (ksuid.KSUID, error) {
if id, err := lakeparse.ParseID(poolName); err == nil {
if _, err := LookupPoolByID(ctx, r, id); err == nil {
return id, nil
}
}
config, err := LookupPoolByName(ctx, r, poolName)
if err != nil {
return ksuid.Nil, err
Expand Down
12 changes: 3 additions & 9 deletions lake/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,10 @@ func (r *Root) PoolID(ctx context.Context, poolName string) (ksuid.KSUID, error)
if poolName == "" {
return ksuid.Nil, errors.New("no pool name given")
}
poolID, err := ksuid.Parse(poolName)
var poolRef *pools.Config
if err != nil {
poolRef = r.pools.LookupByName(ctx, poolName)
if poolRef == nil {
return ksuid.Nil, fmt.Errorf("%s: %w", poolName, pools.ErrNotFound)
}
poolID = poolRef.ID
if poolRef := r.pools.LookupByName(ctx, poolName); poolRef != nil {
return poolRef.ID, nil
}
return poolID, nil
return ksuid.Nil, fmt.Errorf("%s: %w", poolName, pools.ErrNotFound)
}

func (r *Root) CommitObject(ctx context.Context, poolID ksuid.KSUID, branchName string) (ksuid.KSUID, error) {
Expand Down
11 changes: 11 additions & 0 deletions lake/ztests/create-ksuid-name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Test that a pool can be given a ksuid name and everything still works.
script: |
export ZED_LAKE=test
zed init -q
zed create 2WwyVrZdEITo5WkKu1YsJC4dMjU
zed use 2WwyVrZdEITo5WkKu1YsJC4dMjU
outputs:
- name: stdout
regexp: |
pool created: 2WwyVrZdEITo5WkKu1YsJC4dMjU \w{27}
Switched to branch "main" on pool "2WwyVrZdEITo5WkKu1YsJC4dMjU"
12 changes: 12 additions & 0 deletions service/ztests/create-ksuid-name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Test that a pool can be given a ksuid name and everything still works.
script: |
source service.sh
zed create 2WwyVrZdEITo5WkKu1YsJC4dMjU
zed use 2WwyVrZdEITo5WkKu1YsJC4dMjU
inputs:
- name: service.sh
outputs:
- name: stdout
regexp: |
pool created: 2WwyVrZdEITo5WkKu1YsJC4dMjU \w{27}
Switched to branch "main" on pool "2WwyVrZdEITo5WkKu1YsJC4dMjU"

0 comments on commit 758bbf2

Please sign in to comment.