ref/services/syncbase: Move to using the new XServer API.
Change-Id: Ib00ed98a93a0f26d61b9b88356ab4c759dac9970
diff --git a/services/syncbase/server/service.go b/services/syncbase/server/service.go
index 2d36455..c920f48 100644
--- a/services/syncbase/server/service.go
+++ b/services/syncbase/server/service.go
@@ -50,9 +50,6 @@
RootDir string
// Storage engine to use (for service and per-database engines).
Engine string
- // RPC server for this service. Needed to advertise this service in
- // mount tables attached to SyncGroups.
- Server rpc.Server
}
// NewService creates a new service instance and returns it.
@@ -130,7 +127,7 @@
}
// Note, vsync.New internally handles both first-time and subsequent
// invocations.
- if s.sync, err = vsync.New(ctx, call, s, opts.Server, opts.RootDir); err != nil {
+ if s.sync, err = vsync.New(ctx, call, s, opts.RootDir); err != nil {
return nil, err
}
return s, nil
diff --git a/services/syncbase/syncbased/main.go b/services/syncbase/syncbased/main.go
index 1b84118..a3bb1a7 100644
--- a/services/syncbase/syncbased/main.go
+++ b/services/syncbase/syncbased/main.go
@@ -14,6 +14,7 @@
"v.io/v23/security/access"
"v.io/x/lib/vlog"
"v.io/x/ref/lib/security/securityflag"
+ "v.io/x/ref/lib/xrpc"
_ "v.io/x/ref/runtime/factories/roaming"
"v.io/x/ref/services/syncbase/server"
)
@@ -38,15 +39,7 @@
// TODO(sadovsky): We return rpc.Server and rpc.Dispatcher as a quick hack to
// support Mojo.
-func Serve(ctx *context.T) (rpc.Server, rpc.Dispatcher) {
- s, err := v23.NewServer(ctx)
- if err != nil {
- vlog.Fatal("v23.NewServer() failed: ", err)
- }
- if _, err := s.Listen(v23.GetListenSpec(ctx)); err != nil {
- vlog.Fatal("s.Listen() failed: ", err)
- }
-
+func Serve(ctx *context.T) (rpc.XServer, rpc.Dispatcher) {
perms, err := securityflag.PermissionsFromFlag()
if err != nil {
vlog.Fatal("securityflag.PermissionsFromFlag() failed: ", err)
@@ -62,7 +55,6 @@
Perms: perms,
RootDir: *rootDir,
Engine: *engine,
- Server: s,
})
if err != nil {
vlog.Fatal("server.NewService() failed: ", err)
@@ -70,8 +62,9 @@
d := server.NewDispatcher(service)
// Publish the service in the mount table.
- if err := s.ServeDispatcher(*name, d); err != nil {
- vlog.Fatal("s.ServeDispatcher() failed: ", err)
+ s, err := xrpc.NewDispatchingServer(ctx, *name, d)
+ if err != nil {
+ vlog.Fatal("v23.NewDispatchingServer() failed: ", err)
}
if *name != "" {
vlog.Info("Mounted at: ", *name)
diff --git a/services/syncbase/syncbased/mojo_main.go b/services/syncbase/syncbased/mojo_main.go
index fc1dccc..d8ef19b 100644
--- a/services/syncbase/syncbased/mojo_main.go
+++ b/services/syncbase/syncbased/mojo_main.go
@@ -30,7 +30,7 @@
type delegate struct {
ctx *context.T
- srv rpc.Server
+ srv rpc.XServer
disp rpc.Dispatcher
stubs []*bindings.Stub
}
diff --git a/services/syncbase/vsync/sync.go b/services/syncbase/vsync/sync.go
index cf3c9f1..f2e72ae 100644
--- a/services/syncbase/vsync/sync.go
+++ b/services/syncbase/vsync/sync.go
@@ -32,10 +32,9 @@
// syncService contains the metadata for the sync module.
type syncService struct {
// TODO(hpucha): see if "v.io/v23/uniqueid" is a better fit. It is 128 bits.
- id uint64 // globally unique id for this instance of Syncbase.
- name string // name derived from the global id.
- sv interfaces.Service
- server rpc.Server
+ id uint64 // globally unique id for this instance of Syncbase.
+ name string // name derived from the global id.
+ sv interfaces.Service
// High-level lock to serialize the watcher and the initiator. This lock is
// needed to handle the following cases: (a) When the initiator is
@@ -123,10 +122,9 @@
// changes to its objects. The "initiator" thread is responsible for
// periodically contacting peers to fetch changes from them. In addition, the
// sync module responds to incoming RPCs from remote sync modules.
-func New(ctx *context.T, call rpc.ServerCall, sv interfaces.Service, server rpc.Server, rootDir string) (*syncService, error) {
+func New(ctx *context.T, call rpc.ServerCall, sv interfaces.Service, rootDir string) (*syncService, error) {
s := &syncService{
sv: sv,
- server: server,
batches: make(batchSet),
}
diff --git a/services/syncbase/vsync/syncgroup.go b/services/syncbase/vsync/syncgroup.go
index c9263f1..7225404 100644
--- a/services/syncbase/vsync/syncgroup.go
+++ b/services/syncbase/vsync/syncgroup.go
@@ -770,7 +770,7 @@
name := naming.Join(mt, ss.name)
// TODO(hpucha): Is this add idempotent? Appears to be from code.
// Confirm that it is ok to use absolute names here.
- if err := ss.server.AddName(name); err != nil {
+ if err := call.Server().AddName(name); err != nil {
return err
}
}
diff --git a/services/syncbase/vsync/test_util.go b/services/syncbase/vsync/test_util.go
index 8222caf..d6b60c1 100644
--- a/services/syncbase/vsync/test_util.go
+++ b/services/syncbase/vsync/test_util.go
@@ -132,7 +132,7 @@
dir: dir,
shutdown: shutdown,
}
- if s.sync, err = New(ctx, nil, s, nil, dir); err != nil {
+ if s.sync, err = New(ctx, nil, s, dir); err != nil {
util.DestroyStore(engine, dir)
t.Fatalf("cannot create sync service: %v", err)
}