2019-11-13 15:17:45 -05:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dsync
|
|
|
|
|
2020-07-30 02:15:34 -04:00
|
|
|
import "context"
|
|
|
|
|
2019-11-13 15:17:45 -05:00
|
|
|
// LockArgs is minimal required values for any dsync compatible lock operation.
|
|
|
|
type LockArgs struct {
|
|
|
|
// Unique ID of lock/unlock request.
|
|
|
|
UID string
|
|
|
|
|
2020-02-21 00:59:57 -05:00
|
|
|
// Resources contains single or multiple entries to be locked/unlocked.
|
|
|
|
Resources []string
|
2019-11-13 15:17:45 -05:00
|
|
|
|
|
|
|
// Source contains the line number, function and file name of the code
|
|
|
|
// on the client node that requested the lock.
|
|
|
|
Source string
|
2020-09-25 22:21:52 -04:00
|
|
|
|
|
|
|
// Owner represents unique ID for this instance, an owner who originally requested
|
|
|
|
// the locked resource, useful primarily in figuring our stale locks.
|
|
|
|
Owner string
|
2020-10-24 16:23:16 -04:00
|
|
|
|
|
|
|
// Quorum represents the expected quorum for this lock type.
|
|
|
|
Quorum int
|
2019-11-13 15:17:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// NetLocker is dsync compatible locker interface.
|
|
|
|
type NetLocker interface {
|
|
|
|
// Do read lock for given LockArgs. It should return
|
|
|
|
// * a boolean to indicate success/failure of the operation
|
|
|
|
// * an error on failure of lock request operation.
|
2020-07-30 02:15:34 -04:00
|
|
|
RLock(ctx context.Context, args LockArgs) (bool, error)
|
2019-11-13 15:17:45 -05:00
|
|
|
|
|
|
|
// Do write lock for given LockArgs. It should return
|
|
|
|
// * a boolean to indicate success/failure of the operation
|
|
|
|
// * an error on failure of lock request operation.
|
2020-07-30 02:15:34 -04:00
|
|
|
Lock(ctx context.Context, args LockArgs) (bool, error)
|
2019-11-13 15:17:45 -05:00
|
|
|
|
|
|
|
// Do read unlock for given LockArgs. It should return
|
|
|
|
// * a boolean to indicate success/failure of the operation
|
|
|
|
// * an error on failure of unlock request operation.
|
|
|
|
RUnlock(args LockArgs) (bool, error)
|
|
|
|
|
|
|
|
// Do write unlock for given LockArgs. It should return
|
|
|
|
// * a boolean to indicate success/failure of the operation
|
|
|
|
// * an error on failure of unlock request operation.
|
|
|
|
Unlock(args LockArgs) (bool, error)
|
|
|
|
|
2019-11-25 19:39:43 -05:00
|
|
|
// Expired returns if current lock args has expired.
|
2020-07-30 02:15:34 -04:00
|
|
|
Expired(ctx context.Context, args LockArgs) (bool, error)
|
2019-11-25 19:39:43 -05:00
|
|
|
|
2021-01-25 13:01:27 -05:00
|
|
|
// Unlock (read/write) forcefully for given LockArgs. It should return
|
|
|
|
// * a boolean to indicate success/failure of the operation
|
|
|
|
// * an error on failure of unlock request operation.
|
|
|
|
ForceUnlock(ctx context.Context, args LockArgs) (bool, error)
|
|
|
|
|
2019-11-13 15:17:45 -05:00
|
|
|
// Returns underlying endpoint of this lock client instance.
|
|
|
|
String() string
|
|
|
|
|
|
|
|
// Close closes any underlying connection to the service endpoint
|
|
|
|
Close() error
|
2019-11-19 20:42:27 -05:00
|
|
|
|
|
|
|
// Is the underlying connection online? (is always true for any local lockers)
|
|
|
|
IsOnline() bool
|
2020-10-08 15:32:32 -04:00
|
|
|
|
|
|
|
// Is the underlying locker local to this server?
|
|
|
|
IsLocal() bool
|
2019-11-13 15:17:45 -05:00
|
|
|
}
|