Skip to content

Commit dea8eca

Browse files
committed
exit when boltdb doesnt open
1 parent 4adcdde commit dea8eca

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

bloom.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ type BloomFilter struct {
2929
// the number of items added to the bloom filter
3030
count int
3131

32-
// the bit vector
32+
// the bit array
3333
bit_array []bool
3434

3535
// m is the number bits per slice(hashFn)
3636
m int
3737

38-
// the length of seeds define the number of hashing functions we use
38+
// one seed per hash function
3939
seeds []int64
4040
}
4141

@@ -94,13 +94,8 @@ func (bf *BloomFilter) Add(key, val []byte) {
9494

9595
indices := bf.candidates(string(key))
9696

97-
if bf.Find(key) {
98-
return
99-
}
100-
10197
if bf.count >= bf.capacity {
102-
log.Fatalf("BloomFilter has reached full capacity")
103-
return
98+
log.Panicf("BloomFilter has reached full capacity %d", bf.capacity)
10499
}
105100

106101
for i := 0; i < len(indices); i++ {
@@ -180,11 +175,16 @@ func getBucketIndex(hash, width uint64) uint64 {
180175
return hash % width
181176
}
182177

183-
// Size returns the total capacity of the scalable bloom filter
178+
// Capacity returns the total capacity of the scalable bloom filter
184179
func (bf *BloomFilter) Capacity() int {
185180
return bf.capacity
186181
}
187182

183+
// Count returns the number of items added to the bloom filter
184+
func (bf *BloomFilter) Count() int {
185+
return bf.count
186+
}
187+
188188
// FilterSize returns the size of the bloom filter
189189
func (bf *BloomFilter) FilterSize() int {
190190
return bf.bit_width

boltdb.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gobloomgo
22

33
import (
4+
"fmt"
45
"os"
56
"sync"
67

@@ -42,7 +43,8 @@ func NewBolt(filePath string, filemode os.FileMode, opts ...bolt.Options) *BoltS
4243

4344
err := store.open()
4445
if err != nil {
45-
panic(err)
46+
fmt.Printf("failed to open boltdb: %v", err)
47+
os.Exit(1)
4648
}
4749

4850
return store

0 commit comments

Comments
 (0)