Debian Codegraph @

dsync.go

raw symbols SCIP
1 /*
2 * Minio Cloud Storage, (C) 2016 Minio, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package dsync
18
19 import "errors"
20
21 // Number of nodes participating in the distributed locking.
22 var dnodeCount int
23
24 // List of rpc client objects, one per lock server.
25 var clnts []NetLocker
26
27 // Index into rpc client array for server running on localhost
28 var ownNode int
29
30 // Simple majority based quorum, set to dNodeCount/2+1
31 var dquorum int
32
33 // Simple quorum for read operations, set to dNodeCount/2
34 var dquorumReads int
35
36 // Init - initializes package-level global state variables such as clnts.
37 // N B - This function should be called only once inside any program
38 // that uses dsync.
39 func Init(rpcClnts []NetLocker, rpcOwnNode int) (err error) {
40
41 // Validate if number of nodes is within allowable range.
42 if dnodeCount != 0 {
43 return errors.New("Cannot reinitialize dsync package")
44 }
45 if len(rpcClnts) < 4 {
46 return errors.New("Dsync is not designed for less than 4 nodes")
47 } else if len(rpcClnts) > 16 {
48 return errors.New("Dsync is not designed for more than 16 nodes")
49 } else if len(rpcClnts)%2 != 0 {
50 return errors.New("Dsync is not designed for an uneven number of nodes")
51 }
52
53 if rpcOwnNode > len(rpcClnts) {
54 return errors.New("Index for own node is too large")
55 }
56
57 dnodeCount = len(rpcClnts)
58 dquorum = dnodeCount/2 + 1
59 dquorumReads = dnodeCount / 2
60 // Initialize node name and rpc path for each NetLocker object.
61 clnts = make([]NetLocker, dnodeCount)
62 copy(clnts, rpcClnts)
63
64 ownNode = rpcOwnNode
65 return nil
66 }