Handle err returned by rpc.Server.RegisterName (#2910)

This commit is contained in:
Krishnan Parthasarathi 2016-10-13 11:43:24 +05:30 committed by Harshavardhana
parent 84acc820c7
commit b59bac670a
7 changed files with 56 additions and 21 deletions

View File

@ -79,7 +79,7 @@ type controlAPIHandlers struct {
} }
// Register control RPC handlers. // Register control RPC handlers.
func registerControlRPCRouter(mux *router.Router, srvCmdConfig serverCmdConfig) { func registerControlRPCRouter(mux *router.Router, srvCmdConfig serverCmdConfig) (err error) {
// Initialize Control. // Initialize Control.
ctrlHandlers := &controlAPIHandlers{ ctrlHandlers := &controlAPIHandlers{
ObjectAPI: newObjectLayerFn, ObjectAPI: newObjectLayerFn,
@ -89,8 +89,12 @@ func registerControlRPCRouter(mux *router.Router, srvCmdConfig serverCmdConfig)
} }
ctrlRPCServer := rpc.NewServer() ctrlRPCServer := rpc.NewServer()
ctrlRPCServer.RegisterName("Control", ctrlHandlers) err = ctrlRPCServer.RegisterName("Control", ctrlHandlers)
if err != nil {
return traceError(err)
}
ctrlRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter() ctrlRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter()
ctrlRouter.Path(controlPath).Handler(ctrlRPCServer) ctrlRouter.Path(controlPath).Handler(ctrlRPCServer)
return nil
} }

View File

@ -77,9 +77,9 @@ type lockServer struct {
} }
// Register distributed NS lock handlers. // Register distributed NS lock handlers.
func registerDistNSLockRouter(mux *router.Router, serverConfig serverCmdConfig) { func registerDistNSLockRouter(mux *router.Router, serverConfig serverCmdConfig) error {
lockServers := newLockServers(serverConfig) lockServers := newLockServers(serverConfig)
registerStorageLockers(mux, lockServers) return registerStorageLockers(mux, lockServers)
} }
// Create one lock server for every local storage rpc server. // Create one lock server for every local storage rpc server.
@ -128,13 +128,17 @@ func newLockServers(serverConfig serverCmdConfig) (lockServers []*lockServer) {
} }
// registerStorageLockers - register locker rpc handlers for net/rpc library clients // registerStorageLockers - register locker rpc handlers for net/rpc library clients
func registerStorageLockers(mux *router.Router, lockServers []*lockServer) { func registerStorageLockers(mux *router.Router, lockServers []*lockServer) error {
for _, lockServer := range lockServers { for _, lockServer := range lockServers {
lockRPCServer := rpc.NewServer() lockRPCServer := rpc.NewServer()
lockRPCServer.RegisterName("Dsync", lockServer) err := lockRPCServer.RegisterName("Dsync", lockServer)
if err != nil {
return traceError(err)
}
lockRouter := mux.PathPrefix(reservedBucket).Subrouter() lockRouter := mux.PathPrefix(reservedBucket).Subrouter()
lockRouter.Path(path.Join("/lock", lockServer.rpcPath)).Handler(lockRPCServer) lockRouter.Path(path.Join("/lock", lockServer.rpcPath)).Handler(lockRPCServer)
} }
return nil
} }
/// Distributed lock handlers /// Distributed lock handlers

View File

@ -67,24 +67,36 @@ func newObjectLayer(storageDisks []StorageAPI) (ObjectLayer, error) {
} }
// configureServer handler returns final handler for the http server. // configureServer handler returns final handler for the http server.
func configureServerHandler(srvCmdConfig serverCmdConfig) http.Handler { func configureServerHandler(srvCmdConfig serverCmdConfig) (http.Handler, error) {
// Initialize router. // Initialize router.
mux := router.NewRouter() mux := router.NewRouter()
// Initialize distributed NS lock. // Initialize distributed NS lock.
if srvCmdConfig.isDistXL { if srvCmdConfig.isDistXL {
// Register storage rpc router only if its a distributed setup. // Register storage rpc router only if its a distributed setup.
registerStorageRPCRouters(mux, srvCmdConfig) err := registerStorageRPCRouters(mux, srvCmdConfig)
if err != nil {
return nil, err
}
// Register distributed namespace lock. // Register distributed namespace lock.
registerDistNSLockRouter(mux, srvCmdConfig) err = registerDistNSLockRouter(mux, srvCmdConfig)
if err != nil {
return nil, err
}
} }
// Register S3 peer communication router. // Register S3 peer communication router.
registerS3PeerRPCRouter(mux) err := registerS3PeerRPCRouter(mux)
if err != nil {
return nil, err
}
// Register controller rpc router. // Register controller rpc router.
registerControlRPCRouter(mux, srvCmdConfig) err = registerControlRPCRouter(mux, srvCmdConfig)
if err != nil {
return nil, err
}
// set environmental variable MINIO_BROWSER=off to disable minio web browser. // set environmental variable MINIO_BROWSER=off to disable minio web browser.
// By default minio web browser is enabled. // By default minio web browser is enabled.
@ -122,5 +134,5 @@ func configureServerHandler(srvCmdConfig serverCmdConfig) http.Handler {
} }
// Register rest of the handlers. // Register rest of the handlers.
return registerHandlers(mux, handlerFns...) return registerHandlers(mux, handlerFns...), nil
} }

View File

@ -30,14 +30,18 @@ type s3PeerAPIHandlers struct {
ObjectAPI func() ObjectLayer ObjectAPI func() ObjectLayer
} }
func registerS3PeerRPCRouter(mux *router.Router) { func registerS3PeerRPCRouter(mux *router.Router) error {
s3PeerHandlers := &s3PeerAPIHandlers{ s3PeerHandlers := &s3PeerAPIHandlers{
ObjectAPI: newObjectLayerFn, ObjectAPI: newObjectLayerFn,
} }
s3PeerRPCServer := rpc.NewServer() s3PeerRPCServer := rpc.NewServer()
s3PeerRPCServer.RegisterName("S3", s3PeerHandlers) err := s3PeerRPCServer.RegisterName("S3", s3PeerHandlers)
if err != nil {
return traceError(err)
}
s3PeerRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter() s3PeerRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter()
s3PeerRouter.Path(s3Path).Handler(s3PeerRPCServer) s3PeerRouter.Path(s3Path).Handler(s3PeerRPCServer)
return nil
} }

View File

@ -346,7 +346,8 @@ func serverMain(c *cli.Context) {
} }
// Configure server. // Configure server.
handler := configureServerHandler(srvConfig) handler, err := configureServerHandler(srvConfig)
fatalIf(err, "Unable to configure one of server's RPC services.")
// Set nodes for dsync for distributed setup. // Set nodes for dsync for distributed setup.
if srvConfig.isDistXL { if srvConfig.isDistXL {
@ -375,7 +376,7 @@ func serverMain(c *cli.Context) {
}(tls) }(tls)
// Wait for formatting of disks. // Wait for formatting of disks.
err := waitForFormatDisks(firstDisk, endPoints[0], storageDisks) err = waitForFormatDisks(firstDisk, endPoints[0], storageDisks)
fatalIf(err, "formatting storage disks failed") fatalIf(err, "formatting storage disks failed")
// Once formatted, initialize object layer. // Once formatted, initialize object layer.

View File

@ -257,17 +257,23 @@ func newRPCServer(serverConfig serverCmdConfig) (servers []*storageServer, err e
} }
// registerStorageRPCRouter - register storage rpc router. // registerStorageRPCRouter - register storage rpc router.
func registerStorageRPCRouters(mux *router.Router, srvCmdConfig serverCmdConfig) { func registerStorageRPCRouters(mux *router.Router, srvCmdConfig serverCmdConfig) error {
// Initialize storage rpc servers for every disk that is hosted on this node. // Initialize storage rpc servers for every disk that is hosted on this node.
storageRPCs, err := newRPCServer(srvCmdConfig) storageRPCs, err := newRPCServer(srvCmdConfig)
fatalIf(err, "Unable to initialize storage RPC server.") if err != nil {
return traceError(err)
}
// Create a unique route for each disk exported from this node. // Create a unique route for each disk exported from this node.
for _, stServer := range storageRPCs { for _, stServer := range storageRPCs {
storageRPCServer := rpc.NewServer() storageRPCServer := rpc.NewServer()
storageRPCServer.RegisterName("Storage", stServer) err = storageRPCServer.RegisterName("Storage", stServer)
if err != nil {
return traceError(err)
}
// Add minio storage routes. // Add minio storage routes.
storageRouter := mux.PathPrefix(reservedBucket).Subrouter() storageRouter := mux.PathPrefix(reservedBucket).Subrouter()
storageRouter.Path(path.Join("/storage", stServer.path)).Handler(storageRPCServer) storageRouter.Path(path.Join("/storage", stServer.path)).Handler(storageRPCServer)
} }
return nil
} }

View File

@ -183,12 +183,16 @@ func StartTestServer(t TestErrHandler, instanceType string) TestServer {
} }
// Run TestServer. // Run TestServer.
testServer.Server = httptest.NewServer(configureServerHandler( httpHandler, err := configureServerHandler(
serverCmdConfig{ serverCmdConfig{
disks: disks, disks: disks,
storageDisks: storageDisks, storageDisks: storageDisks,
}, },
)) )
if err != nil {
t.Fatalf("Failed to configure one of the RPC services <ERROR> %s", err)
}
testServer.Server = httptest.NewServer(httpHandler)
testServer.Obj = objLayer testServer.Obj = objLayer
globalObjLayerMutex.Lock() globalObjLayerMutex.Lock()