namespace: More // eradication.
The naming.MakeTerminal, naming.Terminal, and naming.MakeResolvable
are now obsolete. Stubs exist in case there are any about to be
checked in CLs that use them.
The namespace routines now clean their input of //s to make sure
that they are no longer relevant.
Expectation of //s has been removed from tests. Some still add
//s but they are ignored in all resolutions.
In a week I'll do another round on naming/parse.go to get rid
of parsing being sensitive to //s. Could probably do it now
but I figure it can wait.
Change-Id: I066fb7b81ddf245fd44398402c38a6a9f814c82f
diff --git a/lib/modules/core/core_test.go b/lib/modules/core/core_test.go
index 23037c0..d8a2a1d 100644
--- a/lib/modules/core/core_test.go
+++ b/lib/modules/core/core_test.go
@@ -241,7 +241,7 @@
srvSession := expect.NewSession(t, srv.Stdout(), time.Minute)
srvSession.ExpectVar("NAME")
addr := srvSession.ExpectVar("ADDR")
- addr = naming.JoinAddressName(addr, "//")
+ addr = naming.JoinAddressName(addr, "")
// Resolve an object
resolver, err := sh.Start(core.ResolveCommand, nil, rootName+"/"+echoName)
@@ -260,7 +260,7 @@
}
// Resolve to a mount table using a rooted name.
- addr = naming.JoinAddressName(mountAddrs[mtName], "//echo")
+ addr = naming.JoinAddressName(mountAddrs[mtName], "echo")
resolver, err = sh.Start(core.ResolveMTCommand, nil, rootName+"/"+echoName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
diff --git a/lib/modules/core/echo.go b/lib/modules/core/echo.go
index 1062779..b1b8877 100644
--- a/lib/modules/core/echo.go
+++ b/lib/modules/core/echo.go
@@ -59,7 +59,7 @@
if err := server.ServeDispatcher(mp, disp); err != nil {
return err
}
- fmt.Fprintf(stdout, "NAME=%s\n", naming.MakeTerminal(naming.JoinAddressName(ep.String(), "")))
+ fmt.Fprintf(stdout, "NAME=%s\n", naming.JoinAddressName(ep.String(), ""))
fmt.Fprintf(stdout, "ADDR=%s\n", ep.String())
fmt.Fprintf(stdout, "PID=%d\n", os.Getpid())
modules.WaitForEOF(stdin)
diff --git a/runtimes/google/ipc/full_test.go b/runtimes/google/ipc/full_test.go
index 19252f1..2c721d9 100644
--- a/runtimes/google/ipc/full_test.go
+++ b/runtimes/google/ipc/full_test.go
@@ -1112,8 +1112,6 @@
}{
{"[foo/bar]", "", "foo/bar", ""},
{"[x/y/...]/", "x/y/...", "", "/"},
- {"[foo/...]//", "", "foo/...", "//"},
- {"[foo]//abc@@/foo", "", "foo", "//abc@@/foo"},
{"[foo]a", "", "foo", "a"},
{"[foo]/a", "foo", "", "/a"},
{"[foo]/a/[bar]", "foo", "bar", "/a"},
diff --git a/runtimes/google/ipc/server.go b/runtimes/google/ipc/server.go
index 840ddd0..be28592 100644
--- a/runtimes/google/ipc/server.go
+++ b/runtimes/google/ipc/server.go
@@ -391,13 +391,9 @@
return ep, nil
}
+// TODO(cnicolaou): Take this out or make the ServesMountTable bit work in the endpoint.
func (s *server) publishEP(ep *inaming.Endpoint, servesMountTable bool) string {
var name string
- if !s.servesMountTable {
- // Make sure that client MountTable code doesn't try and
- // ResolveStep past this final address.
- name = "//"
- }
ep.IsMountTable = servesMountTable
return naming.JoinAddressName(ep.String(), name)
}
diff --git a/runtimes/google/lib/publisher/publisher.go b/runtimes/google/lib/publisher/publisher.go
index 96e39f4..eece0f7 100644
--- a/runtimes/google/lib/publisher/publisher.go
+++ b/runtimes/google/lib/publisher/publisher.go
@@ -213,7 +213,6 @@
deadline time.Time // deadline for the next sync call
names map[string]bool // names that have been added
servers map[string]bool // servers that have been added, true
- servesMT map[string]bool // true if server is a mount table server
mounts map[mountKey]*mountStatus // map each (name,server) to its status
// if server is a mount table server
}
diff --git a/runtimes/google/naming/namespace/all_test.go b/runtimes/google/naming/namespace/all_test.go
index cf66324..da85431 100644
--- a/runtimes/google/naming/namespace/all_test.go
+++ b/runtimes/google/naming/namespace/all_test.go
@@ -197,9 +197,6 @@
boom(t, "Failed to serve mount table at %s: %s", mountPoint, err)
}
name := naming.JoinAddressName(ep.String(), "")
- if !mt {
- name = name + "//"
- }
return &serverEntry{mountPoint: mountPoint, server: s, endpoint: ep, name: name}
}
@@ -291,21 +288,17 @@
// as the address portion of the terminal name for those mounttables.
testResolveToMountTable(t, r, ns, "", root.name)
for _, m := range []string{mt2MP, mt3MP, mt5MP} {
- rootMT := naming.MakeTerminal(naming.Join(root.name, m))
+ rootMT := naming.Join(root.name, m)
// All of these mount tables are hosted by the root mount table
testResolveToMountTable(t, r, ns, m, rootMT)
- testResolveToMountTable(t, r, ns, "//"+m, rootMT)
// The server registered for each mount point is a mount table
testResolve(t, r, ns, m, mts[m].name)
// ResolveToMountTable will walk through to the sub MountTables
mtbar := naming.Join(m, "bar")
- subMT := naming.MakeTerminal(naming.Join(mts[m].name, "bar"))
+ subMT := naming.Join(mts[m].name, "bar")
testResolveToMountTable(t, r, ns, mtbar, subMT)
-
- // ResolveToMountTable will not walk through if the name is terminal
- testResolveToMountTable(t, r, ns, "//"+mtbar, naming.Join(rootMT, "bar"))
}
for _, j := range []string{j1MP, j2MP, j3MP} {
@@ -343,7 +336,7 @@
boom(t, "Failed to Mount %s: %s", mt2a, err)
}
- mt2mt := naming.MakeTerminal(naming.Join(mts[mt2MP].name, "a"))
+ mt2mt := naming.Join(mts[mt2MP].name, "a")
// The mt2/a is served by the mt2 mount table
testResolveToMountTable(t, r, ns, mt2a, mt2mt)
// The server for mt2a is mt3server from the second mount above.
@@ -365,9 +358,9 @@
// We now have 3 mount tables prepared to serve mt2/a
testResolveToMountTable(t, r, ns, "mt2/a",
- mts[mt2MP].name+"//a",
- mts[mt4MP].name+"//a",
- mts[mt5MP].name+"//a")
+ naming.JoinAddressName(mts[mt2MP].name, "a"),
+ naming.JoinAddressName(mts[mt4MP].name, "a"),
+ naming.JoinAddressName(mts[mt5MP].name, "a"))
testResolve(t, r, ns, "mt2", mts[mt2MP].name, mts[mt4MP].name, mts[mt5MP].name)
}
@@ -388,10 +381,11 @@
}
testResolveToMountTable(t, r, ns, "mt4/foo",
- mts[mt4MP].name+"//foo")
+ naming.JoinAddressName(mts[mt4MP].name, "foo"))
testResolveToMountTable(t, r, ns, "mt4/foo/bar",
- mts["mt4/foo"].name+"//bar")
- testResolveToMountTable(t, r, ns, "mt4/foo/baz", mts["mt4/foo"].name+"//baz")
+ naming.JoinAddressName(mts["mt4/foo"].name, "bar"))
+ testResolveToMountTable(t, r, ns, "mt4/foo/baz",
+ naming.JoinAddressName(mts["mt4/foo"].name, "baz"))
}
// TestServers tests invoking RPCs on simple servers
@@ -413,8 +407,8 @@
jokes[gj] = runServer(t, r, disp, globalName)
testResolve(t, r, ns, "mt4/"+j, jokes[gj].name)
knockKnock(t, r, "mt4/"+j)
- testResolveToMountTable(t, r, ns, "mt4/"+j, naming.MakeTerminal(globalName))
- testResolveToMountTable(t, r, ns, "mt4/"+j+"/garbage", naming.MakeTerminal(globalName+"/garbage"))
+ testResolveToMountTable(t, r, ns, "mt4/"+j, globalName)
+ testResolveToMountTable(t, r, ns, "mt4/"+j+"/garbage", globalName+"/garbage")
}
}
diff --git a/runtimes/google/naming/namespace/cache.go b/runtimes/google/naming/namespace/cache.go
index be7b469..8d5293f 100644
--- a/runtimes/google/naming/namespace/cache.go
+++ b/runtimes/google/naming/namespace/cache.go
@@ -45,15 +45,6 @@
return false
}
-// normalize removes any single trailing slash. Added for idiots who seem to
-// like adding trailing slashes.
-func normalize(name string) string {
- if strings.HasSuffix(name, "//") {
- return name
- }
- return strings.TrimSuffix(name, "/")
-}
-
// randomDrop randomly removes one cache entry. Assumes we've already locked the cache.
func (c *ttlCache) randomDrop() {
n := rand.Intn(len(c.entries))
@@ -90,6 +81,7 @@
// Remove suffix. We only care about the name that gets us
// to the mounttable from the last mounttable.
prefix = normalize(prefix)
+ entry.Name = normalize(entry.Name)
prefix = naming.TrimSuffix(prefix, entry.Name)
// Copy the entry.
var ce naming.MountEntry
@@ -97,8 +89,6 @@
ce.Servers = append(ce.Servers, s)
}
ce.SetServesMountTable(entry.ServesMountTable())
- // All keys must be terminal.
- prefix = naming.MakeTerminal(prefix)
c.Lock()
// Enforce an upper limit on the cache size.
if len(c.entries) >= maxCacheEntries {
diff --git a/runtimes/google/naming/namespace/cache_test.go b/runtimes/google/naming/namespace/cache_test.go
index 0f4cffd..e12cd69 100644
--- a/runtimes/google/naming/namespace/cache_test.go
+++ b/runtimes/google/naming/namespace/cache_test.go
@@ -46,8 +46,8 @@
{"/h2//c/d", "d", "/h3", true},
{"/h3//d", "", "/h4:1234", true},
{"/notintcache", "", "", false},
- {"/h1//a/b/f//g", "f//g", "/h2", true},
- {"/h3//d//e", "//e", "/h4:1234", true},
+ {"/h1//a/b/f//g", "f/g", "/h2", true},
+ {"/h3//d//e", "e", "/h4:1234", true},
}
for _, p := range tests {
e, err := c.lookup(p.name)
diff --git a/runtimes/google/naming/namespace/namespace.go b/runtimes/google/naming/namespace/namespace.go
index 1b966d7..7458858 100644
--- a/runtimes/google/naming/namespace/namespace.go
+++ b/runtimes/google/naming/namespace/namespace.go
@@ -1,6 +1,7 @@
package namespace
import (
+ "strings"
"sync"
"time"
@@ -96,6 +97,7 @@
// rootName 'roots' a name: if name is not a rooted name, it prepends the root
// mounttable's OA.
func (ns *namespace) rootName(name string) []string {
+ name = normalize(name)
if address, _ := naming.SplitAddressName(name); len(address) == 0 {
var ret []string
ns.RLock()
@@ -110,6 +112,7 @@
// rootMountEntry 'roots' a name creating a mount entry for the name.
func (ns *namespace) rootMountEntry(name string) (*naming.MountEntry, bool) {
+ name = normalize(name)
e := new(naming.MountEntry)
expiration := time.Now().Add(time.Hour) // plenty of time for a call
address, suffix := naming.SplitAddressName(name)
@@ -178,3 +181,21 @@
}
return nil
}
+
+// normalize removes any single trailing slash and compresses
+// multiple consecutive slashes to one.
+// TODO(p): Transitionally it also removes a leading double
+// slash that used to mean something but doesn't any more.
+// I should remove that in a week or so when we've killed off
+// all code inserting this double slash.
+func normalize(name string) string {
+ // Eradicate leading double slash (for now). Eventually we
+ // should get ris of this.
+ name = strings.TrimPrefix(name, "//")
+ // Eradicate duplicate slashes and trailing slashes. We
+ // could use path.Clean but it has other side effects.
+ for strings.Contains(name, "//") {
+ name = strings.Replace(name, "//", "/", -1)
+ }
+ return strings.TrimSuffix(name, "/")
+}
diff --git a/runtimes/google/naming/namespace/resolve.go b/runtimes/google/naming/namespace/resolve.go
index 5943b6a..1d6e572 100644
--- a/runtimes/google/naming/namespace/resolve.go
+++ b/runtimes/google/naming/namespace/resolve.go
@@ -58,12 +58,7 @@
}
func terminal(e *naming.MountEntry) bool {
- for _, s := range e.Servers {
- if !naming.Terminal(naming.JoinAddressName(s.Server, e.Name)) {
- return false
- }
- }
- return true
+ return len(e.Name) == 0
}
// ResolveX implements veyron2/naming.Namespace.
@@ -130,7 +125,7 @@
}
last := e
for remaining := ns.maxResolveDepth; remaining > 0; remaining-- {
- vlog.VI(2).Infof("ResolveToMountTable(%s) loop %v", name, e)
+ vlog.VI(2).Infof("ResolveToMountTableX(%s) loop %v", name, e)
var err error
curr := e
// If the next name to resolve doesn't point to a mount table, we're done.
@@ -245,7 +240,6 @@
// Walk the cache as we would in a resolution. Unlike a resolution, we have to follow
// all branches since we want to flush all entries at which we might end up whereas in a resolution,
// we stop with the first branch that works.
- n := naming.MakeTerminal(n)
if e, err := ns.resolutionCache.lookup(n); err == nil {
// Recurse.
for _, s := range e.Servers {
diff --git a/services/mgmt/node/impl/config_invoker.go b/services/mgmt/node/impl/config_invoker.go
index 7e191ac..97ccc35 100644
--- a/services/mgmt/node/impl/config_invoker.go
+++ b/services/mgmt/node/impl/config_invoker.go
@@ -78,7 +78,7 @@
func (c *callbackState) listenFor(key string) callbackListener {
id := c.generateID()
- callbackName := naming.MakeTerminal(naming.Join(c.name, configSuffix, id))
+ callbackName := naming.Join(c.name, configSuffix, id)
// Make the channel buffered to avoid blocking the Set method when
// nothing is receiving on the channel. This happens e.g. when
// unregisterCallbacks executes before Set is called.
diff --git a/services/mgmt/node/impl/impl_test.go b/services/mgmt/node/impl/impl_test.go
index 600dd5c..a5670c2 100644
--- a/services/mgmt/node/impl/impl_test.go
+++ b/services/mgmt/node/impl/impl_test.go
@@ -143,7 +143,7 @@
defer rt.R().Cleanup()
server, endpoint := newServer()
defer server.Stop()
- name := naming.MakeTerminal(naming.JoinAddressName(endpoint, ""))
+ name := naming.JoinAddressName(endpoint, "")
vlog.VI(1).Infof("Node manager name: %v", name)
// Satisfy the contract described in doc.go by passing the config state
diff --git a/services/mgmt/node/impl/node_invoker.go b/services/mgmt/node/impl/node_invoker.go
index 1712a0a..8b07f0d 100644
--- a/services/mgmt/node/impl/node_invoker.go
+++ b/services/mgmt/node/impl/node_invoker.go
@@ -254,7 +254,7 @@
return errOperationFailed
}
// Check that invoking Update() succeeds.
- childName = naming.MakeTerminal(naming.Join(childName, "nm"))
+ childName = naming.Join(childName, "nm")
nmClient, err := node.BindNode(childName)
if err != nil {
vlog.Errorf("BindNode(%v) failed: %v", childName, err)
diff --git a/services/mgmt/node/noded/main.go b/services/mgmt/node/noded/main.go
index 47faac9..f1b9a2d 100644
--- a/services/mgmt/node/noded/main.go
+++ b/services/mgmt/node/noded/main.go
@@ -50,7 +50,7 @@
if err != nil {
vlog.Fatalf("Listen(%s) failed: %v", roaming.ListenSpec, err)
}
- name := naming.MakeTerminal(naming.JoinAddressName(endpoint.String(), ""))
+ name := naming.JoinAddressName(endpoint.String(), "")
vlog.VI(0).Infof("Node manager object name: %v", name)
configState, err := config.Load()
if err != nil {
diff --git a/tools/mounttable/impl.go b/tools/mounttable/impl.go
index 1c88cc7..b37d5f6 100644
--- a/tools/mounttable/impl.go
+++ b/tools/mounttable/impl.go
@@ -177,11 +177,14 @@
}
ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
defer cancel()
- c, err := bindMT(ctx, args[0])
+ call, err := rt.R().Client().StartCall(ctx, args[0], "ResolveStepX", []interface{}{}, options.NoResolve(true))
if err != nil {
- return fmt.Errorf("bind error: %v", err)
+ return err
}
- entry, err := c.ResolveStepX(ctx)
+ var entry types.MountEntry
+ if ierr := call.Finish(&entry, &err); ierr != nil {
+ return ierr
+ }
if err != nil {
return err
}
diff --git a/tools/mounttable/impl_test.go b/tools/mounttable/impl_test.go
index 4a7deaf..fdfc5d1 100644
--- a/tools/mounttable/impl_test.go
+++ b/tools/mounttable/impl_test.go
@@ -126,7 +126,8 @@
stdout.Reset()
// Test the 'resolvestep' command.
- if err := cmd.Execute([]string{"resolvestep", naming.JoinAddressName(endpoint.String(), "//name")}); err != nil {
+ vlog.Infof("resovestep %s", naming.JoinAddressName(endpoint.String(), "name"))
+ if err := cmd.Execute([]string{"resolvestep", naming.JoinAddressName(endpoint.String(), "name")}); err != nil {
t.Fatalf("%v", err)
}
if expected, got := `Servers: [{server1 123}] Suffix: "name" MT: false`, strings.TrimSpace(stdout.String()); got != expected {