lock/rpc: change rpcPath to be called serviceEndpoint. (#4088)

This is a cleanup to ensure proper naming.
This commit is contained in:
Harshavardhana 2017-04-11 10:25:21 -07:00 committed by GitHub
parent 1b0b2c1c76
commit 1b1b9e4801
5 changed files with 95 additions and 89 deletions

View File

@ -29,9 +29,9 @@ func TestLockRPCClient(t *testing.T) {
accessKey: "abcd",
secretKey: "abcd123",
serverAddr: fmt.Sprintf("%X", UTCNow().UnixNano()),
serviceEndpoint: pathJoin(lockRPCPath, "/test/1"),
serviceEndpoint: pathJoin(lockServicePath, "/test/1"),
secureConn: false,
serviceName: "Dsync",
serviceName: lockServiceName,
})
// Attempt all calls.

View File

@ -28,12 +28,12 @@ func TestLockRpcServerRemoveEntryIfExists(t *testing.T) {
defer removeAll(testPath)
lri := lockRequesterInfo{
writer: false,
node: "host",
rpcPath: "rpc-path",
uid: "0123-4567",
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
writer: false,
node: "host",
serviceEndpoint: "rpc-path",
uid: "0123-4567",
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
}
nlrip := nameLockRequesterInfoPair{name: "name", lri: lri}
@ -65,20 +65,20 @@ func TestLockRpcServerRemoveEntry(t *testing.T) {
defer removeAll(testPath)
lockRequesterInfo1 := lockRequesterInfo{
writer: true,
node: "host",
rpcPath: "rpc-path",
uid: "0123-4567",
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
writer: true,
node: "host",
serviceEndpoint: "rpc-path",
uid: "0123-4567",
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
}
lockRequesterInfo2 := lockRequesterInfo{
writer: true,
node: "host",
rpcPath: "rpc-path",
uid: "89ab-cdef",
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
writer: true,
node: "host",
serviceEndpoint: "rpc-path",
uid: "89ab-cdef",
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
}
locker.lockMap["name"] = []lockRequesterInfo{
@ -127,12 +127,12 @@ func TestLockRpcServerGetLongLivedLocks(t *testing.T) {
{
lockMap: map[string][]lockRequesterInfo{
"test": {{
writer: true,
node: "10.1.10.21",
rpcPath: "/lock/mnt/disk1",
uid: "10000112",
timestamp: ut,
timeLastCheck: ut,
writer: true,
node: "10.1.10.21",
serviceEndpoint: "/lock/mnt/disk1",
uid: "10000112",
timestamp: ut,
timeLastCheck: ut,
}},
},
lockInterval: 1 * time.Minute,
@ -142,12 +142,12 @@ func TestLockRpcServerGetLongLivedLocks(t *testing.T) {
{
lockMap: map[string][]lockRequesterInfo{
"test": {{
writer: true,
node: "10.1.10.21",
rpcPath: "/lock/mnt/disk1",
uid: "10000112",
timestamp: ut,
timeLastCheck: ut.Add(-2 * time.Minute),
writer: true,
node: "10.1.10.21",
serviceEndpoint: "/lock/mnt/disk1",
uid: "10000112",
timestamp: ut,
timeLastCheck: ut.Add(-2 * time.Minute),
}},
},
lockInterval: 1 * time.Minute,
@ -155,12 +155,12 @@ func TestLockRpcServerGetLongLivedLocks(t *testing.T) {
{
name: "test",
lri: lockRequesterInfo{
writer: true,
node: "10.1.10.21",
rpcPath: "/lock/mnt/disk1",
uid: "10000112",
timestamp: ut,
timeLastCheck: ut.Add(-2 * time.Minute),
writer: true,
node: "10.1.10.21",
serviceEndpoint: "/lock/mnt/disk1",
uid: "10000112",
timestamp: ut,
timeLastCheck: ut.Add(-2 * time.Minute),
},
},
},

View File

@ -30,7 +30,10 @@ import (
const (
// Lock rpc server endpoint.
lockRPCPath = "/lock"
lockServicePath = "/lock"
// Lock rpc service name.
lockServiceName = "Dsync"
// Lock maintenance interval.
lockMaintenanceInterval = 1 * time.Minute // 1 minute.
@ -39,17 +42,17 @@ const (
lockValidityCheckInterval = 2 * time.Minute // 2 minutes.
)
// lockRequesterInfo stores various info from the client for each lock that is requested
// lockRequesterInfo stores various info from the client for each lock that is requested.
type lockRequesterInfo struct {
writer bool // Bool whether write or read lock
node string // Network address of client claiming lock
rpcPath string // RPC path of client claiming lock
uid string // Uid to uniquely identify request of client
timestamp time.Time // Timestamp set at the time of initialization
timeLastCheck time.Time // Timestamp for last check of validity of lock
writer bool // Bool whether write or read lock.
node string // Network address of client claiming lock.
serviceEndpoint string // RPC path of client claiming lock.
uid string // UID to uniquely identify request of client.
timestamp time.Time // Timestamp set at the time of initialization.
timeLastCheck time.Time // Timestamp for last check of validity of lock.
}
// isWriteLock returns whether the lock is a write or read lock
// isWriteLock returns whether the lock is a write or read lock.
func isWriteLock(lri []lockRequesterInfo) bool {
return len(lri) == 1 && lri[0].writer
}
@ -57,9 +60,9 @@ func isWriteLock(lri []lockRequesterInfo) bool {
// lockServer is type for RPC handlers
type lockServer struct {
AuthRPCServer
rpcPath string
mutex sync.Mutex
lockMap map[string][]lockRequesterInfo
serviceEndpoint string
mutex sync.Mutex
lockMap map[string][]lockRequesterInfo
}
// Start lock maintenance from all lock servers.
@ -105,9 +108,9 @@ func newLockServers(srvConfig serverCmdConfig) (lockServers []*lockServer) {
if isLocalStorage(ep) {
// Create handler for lock RPCs
locker := &lockServer{
rpcPath: getPath(ep),
mutex: sync.Mutex{},
lockMap: make(map[string][]lockRequesterInfo),
serviceEndpoint: getPath(ep),
mutex: sync.Mutex{},
lockMap: make(map[string][]lockRequesterInfo),
}
lockServers = append(lockServers, locker)
}
@ -119,11 +122,11 @@ func newLockServers(srvConfig serverCmdConfig) (lockServers []*lockServer) {
func registerStorageLockers(mux *router.Router, lockServers []*lockServer) error {
for _, lockServer := range lockServers {
lockRPCServer := rpc.NewServer()
if err := lockRPCServer.RegisterName("Dsync", lockServer); err != nil {
if err := lockRPCServer.RegisterName(lockServiceName, lockServer); err != nil {
return traceError(err)
}
lockRouter := mux.PathPrefix(minioReservedBucketPath).Subrouter()
lockRouter.Path(path.Join(lockRPCPath, lockServer.rpcPath)).Handler(lockRPCServer)
lockRouter.Path(path.Join(lockServicePath, lockServer.serviceEndpoint)).Handler(lockRPCServer)
}
return nil
}
@ -141,12 +144,12 @@ func (l *lockServer) Lock(args *LockArgs, reply *bool) error {
if !*reply { // No locks held on the given name, so claim write lock
l.lockMap[args.LockArgs.Resource] = []lockRequesterInfo{
{
writer: true,
node: args.LockArgs.ServerAddr,
rpcPath: args.LockArgs.ServiceEndpoint,
uid: args.LockArgs.UID,
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
writer: true,
node: args.LockArgs.ServerAddr,
serviceEndpoint: args.LockArgs.ServiceEndpoint,
uid: args.LockArgs.UID,
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
},
}
}
@ -182,12 +185,12 @@ func (l *lockServer) RLock(args *LockArgs, reply *bool) error {
return err
}
lrInfo := lockRequesterInfo{
writer: false,
node: args.LockArgs.ServerAddr,
rpcPath: args.LockArgs.ServiceEndpoint,
uid: args.LockArgs.UID,
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
writer: false,
node: args.LockArgs.ServerAddr,
serviceEndpoint: args.LockArgs.ServiceEndpoint,
uid: args.LockArgs.UID,
timestamp: UTCNow(),
timeLastCheck: UTCNow(),
}
if lri, ok := l.lockMap[args.LockArgs.Resource]; ok {
if *reply = !isWriteLock(lri); *reply { // Unless there is a write lock
@ -288,13 +291,16 @@ func (l *lockServer) lockMaintenance(interval time.Duration) {
accessKey: serverCred.AccessKey,
secretKey: serverCred.SecretKey,
serverAddr: nlrip.lri.node,
serviceEndpoint: nlrip.lri.rpcPath,
secureConn: globalIsSSL,
serviceName: "Dsync",
serviceEndpoint: nlrip.lri.serviceEndpoint,
serviceName: lockServiceName,
})
// Call back to original server verify whether the lock is still active (based on name & uid)
expired, _ := c.Expired(dsync.LockArgs{UID: nlrip.lri.uid, Resource: nlrip.name})
expired, _ := c.Expired(dsync.LockArgs{
UID: nlrip.lri.uid,
Resource: nlrip.name,
})
// Close the connection regardless of the call response.
c.rpcClient.Close()

View File

@ -34,7 +34,7 @@ func testLockEquality(lriLeft, lriRight []lockRequesterInfo) bool {
for i := 0; i < len(lriLeft); i++ {
if lriLeft[i].writer != lriRight[i].writer ||
lriLeft[i].node != lriRight[i].node ||
lriLeft[i].rpcPath != lriRight[i].rpcPath ||
lriLeft[i].serviceEndpoint != lriRight[i].serviceEndpoint ||
lriLeft[i].uid != lriRight[i].uid {
return false
}
@ -50,10 +50,10 @@ func createLockTestServer(t *testing.T) (string, *lockServer, string) {
}
locker := &lockServer{
AuthRPCServer: AuthRPCServer{},
rpcPath: "rpc-path",
mutex: sync.Mutex{},
lockMap: make(map[string][]lockRequesterInfo),
AuthRPCServer: AuthRPCServer{},
serviceEndpoint: "rpc-path",
mutex: sync.Mutex{},
lockMap: make(map[string][]lockRequesterInfo),
}
creds := serverConfig.GetCredential()
loginArgs := LoginRPCArgs{
@ -97,10 +97,10 @@ func TestLockRpcServerLock(t *testing.T) {
gotLri, _ := locker.lockMap["name"]
expectedLri := []lockRequesterInfo{
{
writer: true,
node: "node",
rpcPath: "rpc-path",
uid: "0123-4567",
writer: true,
node: "node",
serviceEndpoint: "rpc-path",
uid: "0123-4567",
},
}
if !testLockEquality(expectedLri, gotLri) {
@ -198,10 +198,10 @@ func TestLockRpcServerRLock(t *testing.T) {
gotLri, _ := locker.lockMap["name"]
expectedLri := []lockRequesterInfo{
{
writer: false,
node: "node",
rpcPath: "rpc-path",
uid: "0123-4567",
writer: false,
node: "node",
serviceEndpoint: "rpc-path",
uid: "0123-4567",
},
}
if !testLockEquality(expectedLri, gotLri) {
@ -285,10 +285,10 @@ func TestLockRpcServerRUnlock(t *testing.T) {
gotLri, _ := locker.lockMap["name"]
expectedLri := []lockRequesterInfo{
{
writer: false,
node: "node",
rpcPath: "rpc-path",
uid: "89ab-cdef",
writer: false,
node: "node",
serviceEndpoint: "rpc-path",
uid: "89ab-cdef",
},
}
if !testLockEquality(expectedLri, gotLri) {

View File

@ -50,9 +50,9 @@ func initDsyncNodes() error {
accessKey: cred.AccessKey,
secretKey: cred.SecretKey,
serverAddr: ep.Host,
serviceEndpoint: pathutil.Join(minioReservedBucketPath, lockRPCPath, getPath(ep)),
secureConn: globalIsSSL,
serviceName: "Dsync",
serviceEndpoint: pathutil.Join(minioReservedBucketPath, lockServicePath, getPath(ep)),
serviceName: lockServiceName,
})
if isLocalStorage(ep) && myNode == -1 {
myNode = index