Skip to content

Commit

Permalink
Merge pull request #15 from satta/bloomempty
Browse files Browse the repository at this point in the history
do not make empty Bloom filter file fatal
  • Loading branch information
Robert Haist authored Nov 27, 2018
2 parents b8370fb + 6dadbc6 commit 713cae3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 5 additions & 3 deletions processing/bloom_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package processing

import (
"encoding/json"
"errors"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -138,9 +137,12 @@ func MakeBloomHandlerFromFile(bloomFilename string, compressed bool,
iocBloom, err := bloom.LoadFilter(bloomFilename, compressed)
if err != nil {
if err == io.EOF {
return nil, errors.New("file is empty")
log.Warnf("file is empty, using empty default one")
myBloom := bloom.Initialize(100, 0.00000001)
iocBloom = &myBloom
} else {
return nil, err
}
return nil, err
}
bh := MakeBloomHandler(iocBloom, databaseChan, forwardHandler)
bh.BloomFilename = bloomFilename
Expand Down
12 changes: 5 additions & 7 deletions processing/bloom_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,11 @@ func TestBloomHandlerEmptyInput(t *testing.T) {
dbChan := make(chan types.Entry, 10)
defer close(dbChan)

_, err = MakeBloomHandlerFromFile(blFile.Name(), false, dbChan, nil)
if err == nil {
t.Fatal("error expected")
bf, err := MakeBloomHandlerFromFile(blFile.Name(), false, dbChan, nil)
if err != nil {
t.Fatal(err)
}
if err.Error() != "file is empty" {
t.Fatalf("wrong error message: %s (expected \"file is empty\")",
err.Error())
if bf == nil {
t.Fatal("bloom filter should not be nil for empty file")
}

}

0 comments on commit 713cae3

Please sign in to comment.