diff --git a/.gitignore b/.gitignore index b4d173b..e9acf95 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,8 @@ snapshots # Output of the go coverage tool, specifically when used with LiteIDE *.out - +coverage.txt +__debug_bin* # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/cluster.go b/cluster.go index 298deb1..30f2baa 100644 --- a/cluster.go +++ b/cluster.go @@ -91,7 +91,7 @@ func (c *Cluster) Join(ctx context.Context, p Peer) error { _, err := a.WaitAny(ctx) - if err != nil && !exists { + if err == nil && !exists { c.peers = append(c.peers, p) } diff --git a/conn.go b/conn.go index 70640f0..79d6653 100644 --- a/conn.go +++ b/conn.go @@ -47,8 +47,3 @@ func (c *Conn) Write(p []byte) (n int, err error) { go c.wait() return c.Conn.Write(p) } - -func (c *Conn) Close() error { - go c.wait() - return c.Conn.Close() -} diff --git a/coverage.txt b/coverage.txt deleted file mode 100644 index 1b5a57b..0000000 --- a/coverage.txt +++ /dev/null @@ -1,247 +0,0 @@ -mode: atomic -github.com/yaitoo/dlm/cluster.go:19.66,21.28 1 5 -github.com/yaitoo/dlm/cluster.go:21.28,23.3 1 3 -github.com/yaitoo/dlm/cluster.go:25.2,25.65 1 5 -github.com/yaitoo/dlm/cluster.go:25.65,39.17 5 5 -github.com/yaitoo/dlm/cluster.go:39.17,41.4 1 0 -github.com/yaitoo/dlm/cluster.go:44.2,44.53 1 5 -github.com/yaitoo/dlm/cluster.go:44.53,46.3 1 1 -github.com/yaitoo/dlm/cluster.go:46.5,48.3 1 4 -github.com/yaitoo/dlm/cluster.go:50.2,51.8 2 5 -github.com/yaitoo/dlm/cluster.go:51.8,53.29 2 5 -github.com/yaitoo/dlm/cluster.go:53.29,56.18 3 4 -github.com/yaitoo/dlm/cluster.go:56.18,58.5 1 0 -github.com/yaitoo/dlm/cluster.go:61.3,61.13 1 5 -github.com/yaitoo/dlm/cluster.go:64.2,64.29 1 0 -github.com/yaitoo/dlm/cluster.go:67.59,71.31 3 9 -github.com/yaitoo/dlm/cluster.go:71.31,73.30 1 25 -github.com/yaitoo/dlm/cluster.go:73.30,75.4 1 2 -github.com/yaitoo/dlm/cluster.go:77.3,78.17 2 25 -github.com/yaitoo/dlm/cluster.go:78.17,80.12 2 0 -github.com/yaitoo/dlm/cluster.go:83.3,83.61 1 25 -github.com/yaitoo/dlm/cluster.go:83.61,84.43 1 25 -github.com/yaitoo/dlm/cluster.go:84.43,88.5 3 25 -github.com/yaitoo/dlm/cluster.go:92.2,94.27 2 9 -github.com/yaitoo/dlm/cluster.go:94.27,96.3 1 0 -github.com/yaitoo/dlm/cluster.go:98.2,98.12 1 9 -github.com/yaitoo/dlm/cluster_option.go:7.67,8.26 1 2 -github.com/yaitoo/dlm/cluster_option.go:8.26,10.3 1 2 -github.com/yaitoo/dlm/cluster_option.go:13.45,14.26 1 1 -github.com/yaitoo/dlm/cluster_option.go:14.26,16.3 1 1 -github.com/yaitoo/dlm/conn.go:11.92,18.16 3 25 -github.com/yaitoo/dlm/conn.go:18.16,20.3 1 0 -github.com/yaitoo/dlm/conn.go:22.2,22.53 1 25 -github.com/yaitoo/dlm/conn.go:31.23,36.82 4 75 -github.com/yaitoo/dlm/conn.go:36.82,38.3 1 75 -github.com/yaitoo/dlm/conn.go:41.50,44.2 2 50 -github.com/yaitoo/dlm/conn.go:46.51,49.2 2 25 -github.com/yaitoo/dlm/conn.go:51.30,54.2 2 0 -github.com/yaitoo/dlm/lease.go:19.31,21.2 1 4 -github.com/yaitoo/dlm/mutex.go:14.64,31.28 2 0 -github.com/yaitoo/dlm/mutex.go:31.28,33.3 1 0 -github.com/yaitoo/dlm/mutex.go:35.2,35.10 1 0 -github.com/yaitoo/dlm/mutex.go:53.52,54.22 1 0 -github.com/yaitoo/dlm/mutex.go:54.22,56.35 2 0 -github.com/yaitoo/dlm/mutex.go:56.35,57.71 1 0 -github.com/yaitoo/dlm/mutex.go:57.71,58.59 1 0 -github.com/yaitoo/dlm/mutex.go:58.59,60.6 1 0 -github.com/yaitoo/dlm/mutex.go:64.3,65.23 2 0 -github.com/yaitoo/dlm/mutex.go:65.23,68.4 2 0 -github.com/yaitoo/dlm/mutex.go:70.3,70.13 1 0 -github.com/yaitoo/dlm/mutex.go:73.2,73.12 1 0 -github.com/yaitoo/dlm/mutex.go:76.68,87.16 8 0 -github.com/yaitoo/dlm/mutex.go:87.16,89.3 1 0 -github.com/yaitoo/dlm/mutex.go:91.2,91.30 1 0 -github.com/yaitoo/dlm/mutex.go:91.30,92.70 1 0 -github.com/yaitoo/dlm/mutex.go:92.70,93.52 1 0 -github.com/yaitoo/dlm/mutex.go:93.52,97.5 3 0 -github.com/yaitoo/dlm/mutex.go:101.2,103.16 3 0 -github.com/yaitoo/dlm/mutex.go:103.16,105.3 1 0 -github.com/yaitoo/dlm/mutex.go:106.2,109.29 3 0 -github.com/yaitoo/dlm/mutex.go:109.29,111.3 1 0 -github.com/yaitoo/dlm/mutex.go:113.2,120.17 5 0 -github.com/yaitoo/dlm/mutex.go:124.51,130.30 5 0 -github.com/yaitoo/dlm/mutex.go:130.30,131.69 1 0 -github.com/yaitoo/dlm/mutex.go:131.69,132.51 1 0 -github.com/yaitoo/dlm/mutex.go:132.51,135.19 3 0 -github.com/yaitoo/dlm/mutex.go:135.19,137.6 1 0 -github.com/yaitoo/dlm/mutex.go:139.5,139.18 1 0 -github.com/yaitoo/dlm/mutex.go:143.2,146.16 3 0 -github.com/yaitoo/dlm/mutex.go:146.16,148.3 1 0 -github.com/yaitoo/dlm/mutex.go:150.2,150.12 1 0 -github.com/yaitoo/dlm/mutex.go:152.45,158.2 1 0 -github.com/yaitoo/dlm/mutex.go:160.50,165.30 5 0 -github.com/yaitoo/dlm/mutex.go:165.30,166.70 1 0 -github.com/yaitoo/dlm/mutex.go:166.70,167.52 1 0 -github.com/yaitoo/dlm/mutex.go:167.52,170.19 3 0 -github.com/yaitoo/dlm/mutex.go:170.19,172.6 1 0 -github.com/yaitoo/dlm/mutex.go:173.5,173.18 1 0 -github.com/yaitoo/dlm/mutex.go:178.2,183.16 5 0 -github.com/yaitoo/dlm/mutex.go:183.16,185.3 1 0 -github.com/yaitoo/dlm/mutex.go:187.2,190.29 3 0 -github.com/yaitoo/dlm/mutex.go:190.29,192.3 1 0 -github.com/yaitoo/dlm/mutex.go:194.2,194.30 1 0 -github.com/yaitoo/dlm/mutex.go:194.30,196.3 1 0 -github.com/yaitoo/dlm/mutex.go:198.2,199.12 2 0 -github.com/yaitoo/dlm/mutex.go:202.77,205.6 3 0 -github.com/yaitoo/dlm/mutex.go:205.6,212.35 5 0 -github.com/yaitoo/dlm/mutex.go:212.35,214.4 1 0 -github.com/yaitoo/dlm/mutex.go:218.75,222.6 3 0 -github.com/yaitoo/dlm/mutex.go:222.6,228.10 4 0 -github.com/yaitoo/dlm/mutex.go:229.17,230.10 1 0 -github.com/yaitoo/dlm/mutex.go:231.38,233.36 1 0 -github.com/yaitoo/dlm/mutex.go:233.36,235.5 1 0 -github.com/yaitoo/dlm/mutex.go:237.4,238.72 2 0 -github.com/yaitoo/dlm/mutex.go:238.72,240.5 1 0 -github.com/yaitoo/dlm/mutex_option.go:7.56,8.24 1 0 -github.com/yaitoo/dlm/mutex_option.go:8.24,10.3 1 0 -github.com/yaitoo/dlm/mutex_option.go:13.47,14.24 1 0 -github.com/yaitoo/dlm/mutex_option.go:14.24,16.3 1 0 -github.com/yaitoo/dlm/node.go:14.56,22.28 3 14 -github.com/yaitoo/dlm/node.go:22.28,24.3 1 26 -github.com/yaitoo/dlm/node.go:26.2,26.20 1 14 -github.com/yaitoo/dlm/node.go:26.20,28.3 1 0 -github.com/yaitoo/dlm/node.go:30.2,30.10 1 14 -github.com/yaitoo/dlm/node.go:49.32,51.2 1 73 -github.com/yaitoo/dlm/node.go:53.54,56.9 3 20 -github.com/yaitoo/dlm/node.go:56.9,58.3 1 7 -github.com/yaitoo/dlm/node.go:60.2,61.16 2 13 -github.com/yaitoo/dlm/node.go:61.16,63.3 1 0 -github.com/yaitoo/dlm/node.go:64.2,64.15 1 13 -github.com/yaitoo/dlm/node.go:67.62,72.8 4 16 -github.com/yaitoo/dlm/node.go:72.8,74.17 2 11 -github.com/yaitoo/dlm/node.go:74.17,76.4 1 0 -github.com/yaitoo/dlm/node.go:77.8,79.3 1 5 -github.com/yaitoo/dlm/node.go:81.2,81.13 1 16 -github.com/yaitoo/dlm/node.go:81.13,83.3 1 0 -github.com/yaitoo/dlm/node.go:85.2,85.17 1 16 -github.com/yaitoo/dlm/node.go:88.65,90.16 2 7 -github.com/yaitoo/dlm/node.go:90.16,92.3 1 0 -github.com/yaitoo/dlm/node.go:93.2,102.18 4 7 -github.com/yaitoo/dlm/node.go:105.75,107.16 2 6 -github.com/yaitoo/dlm/node.go:107.16,109.3 1 0 -github.com/yaitoo/dlm/node.go:110.2,119.18 4 6 -github.com/yaitoo/dlm/node.go:122.51,132.2 4 4 -github.com/yaitoo/dlm/node_fsm.go:12.47,13.19 1 21 -github.com/yaitoo/dlm/node_fsm.go:13.19,16.3 2 4 -github.com/yaitoo/dlm/node_fsm.go:18.2,19.51 2 21 -github.com/yaitoo/dlm/node_fsm.go:19.51,20.69 1 0 -github.com/yaitoo/dlm/node_fsm.go:23.2,23.16 1 21 -github.com/yaitoo/dlm/node_fsm.go:24.14,25.36 1 16 -github.com/yaitoo/dlm/node_fsm.go:26.17,27.30 1 5 -github.com/yaitoo/dlm/node_fsm.go:28.10,29.62 1 0 -github.com/yaitoo/dlm/node_fsm.go:34.53,40.24 4 0 -github.com/yaitoo/dlm/node_fsm.go:40.24,42.3 1 0 -github.com/yaitoo/dlm/node_fsm.go:43.2,43.33 1 0 -github.com/yaitoo/dlm/node_fsm.go:47.48,49.55 2 0 -github.com/yaitoo/dlm/node_fsm.go:49.55,51.3 1 0 -github.com/yaitoo/dlm/node_fsm.go:55.2,56.12 2 0 -github.com/yaitoo/dlm/node_fsm.go:59.63,62.2 2 16 -github.com/yaitoo/dlm/node_fsm.go:64.52,67.2 2 5 -github.com/yaitoo/dlm/node_option.go:9.50,10.23 1 14 -github.com/yaitoo/dlm/node_option.go:10.23,13.3 2 14 -github.com/yaitoo/dlm/node_option.go:16.41,17.23 1 1 -github.com/yaitoo/dlm/node_option.go:17.23,19.3 1 1 -github.com/yaitoo/dlm/node_option.go:22.41,23.23 1 11 -github.com/yaitoo/dlm/node_option.go:23.23,25.3 1 11 -github.com/yaitoo/dlm/node_rpc.go:12.57,13.19 1 7 -github.com/yaitoo/dlm/node_rpc.go:13.19,15.3 1 1 -github.com/yaitoo/dlm/node_rpc.go:17.2,17.39 1 6 -github.com/yaitoo/dlm/node_rpc.go:17.39,19.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:21.2,26.16 4 6 -github.com/yaitoo/dlm/node_rpc.go:26.16,28.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:30.2,33.16 3 6 -github.com/yaitoo/dlm/node_rpc.go:33.16,34.47 1 1 -github.com/yaitoo/dlm/node_rpc.go:34.47,36.4 1 1 -github.com/yaitoo/dlm/node_rpc.go:37.8,38.34 1 5 -github.com/yaitoo/dlm/node_rpc.go:38.34,40.4 1 0 -github.com/yaitoo/dlm/node_rpc.go:44.2,54.16 3 5 -github.com/yaitoo/dlm/node_rpc.go:54.16,56.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:58.2,58.14 1 5 -github.com/yaitoo/dlm/node_rpc.go:58.14,60.3 1 5 -github.com/yaitoo/dlm/node_rpc.go:62.2,62.12 1 5 -github.com/yaitoo/dlm/node_rpc.go:65.59,66.19 1 6 -github.com/yaitoo/dlm/node_rpc.go:66.19,68.3 1 1 -github.com/yaitoo/dlm/node_rpc.go:70.2,75.16 4 5 -github.com/yaitoo/dlm/node_rpc.go:75.16,77.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:79.2,82.16 3 5 -github.com/yaitoo/dlm/node_rpc.go:82.16,84.3 1 1 -github.com/yaitoo/dlm/node_rpc.go:86.2,86.28 1 4 -github.com/yaitoo/dlm/node_rpc.go:86.28,88.3 1 1 -github.com/yaitoo/dlm/node_rpc.go:90.2,90.21 1 3 -github.com/yaitoo/dlm/node_rpc.go:90.21,92.3 1 1 -github.com/yaitoo/dlm/node_rpc.go:94.2,98.16 4 2 -github.com/yaitoo/dlm/node_rpc.go:98.16,100.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:101.2,101.14 1 2 -github.com/yaitoo/dlm/node_rpc.go:101.14,103.3 1 2 -github.com/yaitoo/dlm/node_rpc.go:104.2,104.12 1 2 -github.com/yaitoo/dlm/node_rpc.go:107.61,108.19 1 4 -github.com/yaitoo/dlm/node_rpc.go:108.19,110.3 1 1 -github.com/yaitoo/dlm/node_rpc.go:112.2,118.16 5 3 -github.com/yaitoo/dlm/node_rpc.go:118.16,120.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:122.2,122.28 1 3 -github.com/yaitoo/dlm/node_rpc.go:122.28,124.3 1 1 -github.com/yaitoo/dlm/node_rpc.go:126.2,128.16 2 2 -github.com/yaitoo/dlm/node_rpc.go:128.16,130.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:132.2,134.12 2 2 -github.com/yaitoo/dlm/node_rpc.go:137.59,138.19 1 7 -github.com/yaitoo/dlm/node_rpc.go:138.19,140.3 1 1 -github.com/yaitoo/dlm/node_rpc.go:141.2,144.63 3 6 -github.com/yaitoo/dlm/node_rpc.go:147.62,148.19 1 3 -github.com/yaitoo/dlm/node_rpc.go:148.19,150.3 1 1 -github.com/yaitoo/dlm/node_rpc.go:151.2,156.16 4 2 -github.com/yaitoo/dlm/node_rpc.go:156.16,158.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:160.2,161.12 2 2 -github.com/yaitoo/dlm/node_rpc.go:166.45,167.19 1 25 -github.com/yaitoo/dlm/node_rpc.go:167.19,169.3 1 16 -github.com/yaitoo/dlm/node_rpc.go:171.2,175.45 4 9 -github.com/yaitoo/dlm/node_rpc.go:175.45,177.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:179.2,179.59 1 9 -github.com/yaitoo/dlm/node_rpc.go:179.59,182.46 1 37 -github.com/yaitoo/dlm/node_rpc.go:182.46,185.47 1 0 -github.com/yaitoo/dlm/node_rpc.go:185.47,189.5 3 0 -github.com/yaitoo/dlm/node_rpc.go:191.4,192.41 2 0 -github.com/yaitoo/dlm/node_rpc.go:192.41,194.5 1 0 -github.com/yaitoo/dlm/node_rpc.go:198.2,199.22 2 9 -github.com/yaitoo/dlm/node_rpc.go:199.22,201.3 1 0 -github.com/yaitoo/dlm/node_rpc.go:203.2,204.12 2 9 -github.com/yaitoo/dlm/node_svc.go:18.49,26.16 4 14 -github.com/yaitoo/dlm/node_svc.go:26.16,28.3 1 0 -github.com/yaitoo/dlm/node_svc.go:29.2,30.16 2 14 -github.com/yaitoo/dlm/node_svc.go:30.16,32.3 1 0 -github.com/yaitoo/dlm/node_svc.go:35.2,39.17 4 14 -github.com/yaitoo/dlm/node_svc.go:39.17,43.3 3 13 -github.com/yaitoo/dlm/node_svc.go:43.8,45.37 2 1 -github.com/yaitoo/dlm/node_svc.go:45.37,47.18 2 1 -github.com/yaitoo/dlm/node_svc.go:47.18,49.5 1 0 -github.com/yaitoo/dlm/node_svc.go:52.3,53.17 2 1 -github.com/yaitoo/dlm/node_svc.go:53.17,55.4 1 0 -github.com/yaitoo/dlm/node_svc.go:57.3,62.17 3 1 -github.com/yaitoo/dlm/node_svc.go:62.17,64.4 1 0 -github.com/yaitoo/dlm/node_svc.go:65.3,66.23 2 1 -github.com/yaitoo/dlm/node_svc.go:70.2,71.16 2 14 -github.com/yaitoo/dlm/node_svc.go:71.16,73.3 1 0 -github.com/yaitoo/dlm/node_svc.go:74.2,76.12 2 14 -github.com/yaitoo/dlm/node_svc.go:76.12,80.3 2 14 -github.com/yaitoo/dlm/node_svc.go:82.2,82.12 1 14 -github.com/yaitoo/dlm/node_svc.go:86.49,88.16 2 11 -github.com/yaitoo/dlm/node_svc.go:88.16,90.3 1 0 -github.com/yaitoo/dlm/node_svc.go:92.2,97.40 4 11 -github.com/yaitoo/dlm/node_svc.go:100.44,101.6 1 11 -github.com/yaitoo/dlm/node_svc.go:101.6,103.17 2 36 -github.com/yaitoo/dlm/node_svc.go:103.17,105.4 1 25 -github.com/yaitoo/dlm/node_svc.go:105.9,106.37 1 11 -github.com/yaitoo/dlm/node_svc.go:106.37,108.5 1 11 -github.com/yaitoo/dlm/node_svc.go:110.4,110.98 1 0 -github.com/yaitoo/dlm/node_svc.go:116.63,120.2 2 11 -github.com/yaitoo/dlm/snapshot.go:14.58,15.22 1 0 -github.com/yaitoo/dlm/snapshot.go:15.22,18.17 2 0 -github.com/yaitoo/dlm/snapshot.go:18.17,20.4 1 0 -github.com/yaitoo/dlm/snapshot.go:23.3,23.42 1 0 -github.com/yaitoo/dlm/snapshot.go:23.42,25.4 1 0 -github.com/yaitoo/dlm/snapshot.go:28.3,28.22 1 0 -github.com/yaitoo/dlm/snapshot.go:31.2,31.16 1 0 -github.com/yaitoo/dlm/snapshot.go:31.16,32.35 1 0 -github.com/yaitoo/dlm/snapshot.go:32.35,34.4 1 0 -github.com/yaitoo/dlm/snapshot.go:37.2,37.12 1 0 -github.com/yaitoo/dlm/snapshot.go:40.31,40.32 0 0 diff --git a/node_svc.go b/node_svc.go index 608e49c..10804b2 100644 --- a/node_svc.go +++ b/node_svc.go @@ -114,7 +114,6 @@ func (n *Node) waitRequest(l net.Listener) { } func (n *Node) waitClose(ctx context.Context, l net.Listener) { - defer l.Close() - <-ctx.Done() + l.Close() } diff --git a/snapshot.go b/snapshot.go index 51774e8..c86745f 100644 --- a/snapshot.go +++ b/snapshot.go @@ -37,4 +37,4 @@ func (s *snapshot) Persist(sink raft.SnapshotSink) error { return err } -func (s *snapshot) Release() {} +func (_ *snapshot) Release() {}