Address review feedback

This commit is contained in:
Jeff Mitchell 2017-06-16 23:54:19 -04:00 committed by Jeff Mitchell
parent 186e4af95e
commit 43d7547235
2 changed files with 12 additions and 12 deletions

View File

@ -14,10 +14,10 @@ import (
// Router is used to do prefix based routing of a request to a logical backend // Router is used to do prefix based routing of a request to a logical backend
type Router struct { type Router struct {
l sync.RWMutex l sync.RWMutex
root *radix.Tree root *radix.Tree
mountEntryCache *radix.Tree mountUUIDCache *radix.Tree
tokenStoreSalt *salt.Salt tokenStoreSalt *salt.Salt
// storagePrefix maps the prefix used for storage (ala the BarrierView) // storagePrefix maps the prefix used for storage (ala the BarrierView)
// to the backend. This is used to map a key back into the backend that owns it. // to the backend. This is used to map a key back into the backend that owns it.
@ -28,9 +28,9 @@ type Router struct {
// NewRouter returns a new router // NewRouter returns a new router
func NewRouter() *Router { func NewRouter() *Router {
r := &Router{ r := &Router{
root: radix.New(), root: radix.New(),
storagePrefix: radix.New(), storagePrefix: radix.New(),
mountEntryCache: radix.New(), mountUUIDCache: radix.New(),
} }
return r return r
} }
@ -79,7 +79,7 @@ func (r *Router) Mount(backend logical.Backend, prefix string, mountEntry *Mount
r.root.Insert(prefix, re) r.root.Insert(prefix, re)
r.storagePrefix.Insert(storageView.prefix, re) r.storagePrefix.Insert(storageView.prefix, re)
r.mountEntryCache.Insert(re.mountEntry.UUID, re.mountEntry) r.mountUUIDCache.Insert(re.mountEntry.UUID, re.mountEntry)
return nil return nil
} }
@ -102,7 +102,7 @@ func (r *Router) Unmount(prefix string) error {
// Purge from the radix trees // Purge from the radix trees
r.root.Delete(prefix) r.root.Delete(prefix)
r.storagePrefix.Delete(re.storageView.prefix) r.storagePrefix.Delete(re.storageView.prefix)
r.mountEntryCache.Delete(re.mountEntry.UUID) r.mountUUIDCache.Delete(re.mountEntry.UUID)
return nil return nil
} }
@ -147,7 +147,7 @@ func (r *Router) Untaint(path string) error {
return nil return nil
} }
func (r *Router) MatchingMountByID(mountID string) *MountEntry { func (r *Router) MatchingMountByUUID(mountID string) *MountEntry {
if mountID == "" { if mountID == "" {
return nil return nil
} }
@ -155,7 +155,7 @@ func (r *Router) MatchingMountByID(mountID string) *MountEntry {
r.l.RLock() r.l.RLock()
defer r.l.RUnlock() defer r.l.RUnlock()
_, raw, ok := r.mountEntryCache.LongestPrefix(mountID) _, raw, ok := r.mountUUIDCache.LongestPrefix(mountID)
if !ok { if !ok {
return nil return nil
} }

View File

@ -114,7 +114,7 @@ func TestRouter_Mount(t *testing.T) {
t.Fatalf("bad: %v", v) t.Fatalf("bad: %v", v)
} }
mountEntryFetched := r.MatchingMountByID(mountEntry.UUID) mountEntryFetched := r.MatchingMountByUUID(mountEntry.UUID)
if mountEntryFetched == nil || !reflect.DeepEqual(mountEntry, mountEntryFetched) { if mountEntryFetched == nil || !reflect.DeepEqual(mountEntry, mountEntryFetched) {
t.Fatalf("failed to fetch mount entry using its ID; expected: %#v\n actual: %#v\n", mountEntry, mountEntryFetched) t.Fatalf("failed to fetch mount entry using its ID; expected: %#v\n actual: %#v\n", mountEntry, mountEntryFetched)
} }