Skip to content

Commit bd062e9

Browse files
use panic so it can be caught earlier
1 parent 849add9 commit bd062e9

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

clustering/cluster.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package clustering
22

33
import (
44
"errors"
5-
"github.com/fabricekabongo/loggerhead/config"
6-
"github.com/fabricekabongo/loggerhead/query"
7-
"github.com/hashicorp/memberlist"
85
"log"
96
"net"
107
"os"
118
"time"
9+
10+
"github.com/fabricekabongo/loggerhead/config"
11+
"github.com/fabricekabongo/loggerhead/query"
12+
"github.com/hashicorp/memberlist"
1213
)
1314

1415
var (
@@ -65,7 +66,7 @@ func NewCluster(engine *query.Engine, config config.Config) (*Cluster, error) {
6566

6667
hostname, err := os.Hostname()
6768
if err != nil {
68-
log.Fatal("Failed to get hostname: ", err)
69+
panic(err)
6970
}
7071

7172
cfg := memberlist.DefaultLocalConfig()

world/namespace.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ func NewNamespace(name string) *Namespace {
2626
}
2727

2828
func (n *Namespace) SaveLocation(id string, lat float64, lon float64) (*Location, error) {
29-
n.mu.RLock()
29+
n.mu.Lock()
30+
defer n.mu.Unlock()
31+
3032
loc, ok := n.locations[id]
31-
n.mu.RUnlock()
3233

3334
if ok {
3435
err := loc.Update(lat, lon)
@@ -42,9 +43,7 @@ func (n *Namespace) SaveLocation(id string, lat float64, lon float64) (*Location
4243
}
4344
loc = newLoc
4445

45-
n.mu.Lock()
4646
n.locations[id] = loc
47-
n.mu.Unlock()
4847
}
4948

5049
err := n.tree.Insert(loc)

world/world.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"encoding/gob"
66
"errors"
7-
"log"
87
"sync"
98
)
109

@@ -97,7 +96,7 @@ func NewWorldFromBytes(buf []byte) *World {
9796
err := dec.Decode(&w)
9897

9998
if err != nil {
100-
log.Fatal(err)
99+
panic(err)
101100
}
102101

103102
return &w
@@ -111,7 +110,7 @@ func (m *World) Merge(w *World) {
111110
for locId, loc := range n.locations {
112111
err := m.Save(ns, locId, loc.Lat(), loc.Lon())
113112
if err != nil {
114-
log.Fatal("Error merging world: ", err)
113+
panic(err)
115114
}
116115
}
117116
}

0 commit comments

Comments
 (0)