MCPcopy Create free account
hub / github.com/dadgar/onecache / Create

Function Create

onecache/onecache.go:57–111  ·  view source on GitHub ↗

Create creates a new Node instance and initializes all resources necessary to be a member of the hash ring.

(config *NodeConfig)

Source from the content-addressed store, hash-verified

55// Create creates a new Node instance and initializes all resources necessary to
56// be a member of the hash ring.
57func Create(config *NodeConfig) (*Node, error) {
58 if err := configValidator(config); err != nil {
59 return nil, err
60 }
61
62 node := &Node{
63 name: uuid.New(),
64 eventCh: make(chan serf.Event),
65 quitCh: make(chan bool),
66 replicas: config.Replicas,
67 nodes: make(map[string]*peerNode),
68 config: config,
69 }
70
71 // RPC Endpoint
72 node.server = newRpcServer(node)
73
74 // Initialize the ring.
75 node.ring = newConsistentRing(node.name, config.Replicas)
76
77 // Set up logging.
78 if config.LogOutput == nil {
79 config.LogOutput = os.Stderr
80 }
81 node.logger = log.New(config.LogOutput, "", log.LstdFlags)
82
83 // Initialize the data storage.
84 d, err := ttlstore.New(config.MaxMemoryUsage, node.logger)
85 if err != nil {
86 return nil, fmt.Errorf("DataStore initialization failed: %v", err)
87 }
88 node.data = d
89
90 // Initialize replication
91 if config.Replicas == 1 {
92 node.replicator = &noOpReplicator{}
93 } else {
94 node.replicator = newReplicator(node)
95 }
96
97 // Initialize garbage collection.
98 node.gc = time.AfterFunc(10*time.Minute, node.garbageCollect)
99 node.gc.Stop()
100
101 // Initialize the RPC Server
102 if err := node.initRpcServer(config.RpcPort); err != nil {
103 return nil, fmt.Errorf("RPC server initialization failed: %v", err)
104 }
105
106 if err := node.initSerf(config.SerfConfig); err != nil {
107 return nil, fmt.Errorf("serf initialization failed: %v", err)
108 }
109
110 return node, nil
111}
112
113// Start starts handling connections from other rings in the cluster as well as
114// clients.

Callers 4

TestCreateInvalidFunction · 0.85
TestJoinValidFunction · 0.85
defaultTestNodeFunction · 0.85
buildConnectedNodesFunction · 0.85

Calls 7

initRpcServerMethod · 0.95
initSerfMethod · 0.95
configValidatorFunction · 0.85
newRpcServerFunction · 0.85
newConsistentRingFunction · 0.85
newReplicatorFunction · 0.85
StopMethod · 0.65

Tested by 2

TestCreateInvalidFunction · 0.68
TestJoinValidFunction · 0.68