summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2018-01-12 15:50:51 +0100
committerChristian Pointner <equinox@spreadspace.org>2018-01-12 15:50:51 +0100
commitf2b3d6a80dc8a842cec3fa4c31957edd2dd4cf2c (patch)
treea5f7158b2a21bb69b9926ad21d1fd227bcf5289c
parentuse int64 for ids everywhere (diff)
added search index buckets
-rw-r--r--src/hub/Makefile2
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go11
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store_test.go23
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5typesStore.go4
4 files changed, 39 insertions, 1 deletions
diff --git a/src/hub/Makefile b/src/hub/Makefile
index 4b281b4..5e86cc1 100644
--- a/src/hub/Makefile
+++ b/src/hub/Makefile
@@ -75,7 +75,7 @@ build: getlibs
test: getlibs
@echo "testing: sfive"
- @$(GOCMD) test spreadspace.org/sfive
+ @$(GOCMD) test -v spreadspace.org/sfive
bench: getlibs
@echo "testing and benchmarking: sfive"
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index eb5793c..dda9247 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -51,6 +51,7 @@ const (
var (
storeBuckets = []string{latestUpdatesBn, hubUUIDsFwdBn, hubUUIDsRevBn, updatesBn,
sourcesFwdBn, sourcesRevBn, clientsFwdBn, clientsRevBn, clientDataBn, userAgentsFwdBn, userAgentsRevBn}
+ storeIndexBuckets = []string{timestampsIdxBn}
)
type Store struct {
@@ -104,6 +105,11 @@ func openDB(dbPath string, readOnly bool) (db *bolt.DB, version int64, hubUUID s
return errors.New("store: failed to open, bucket '" + bn + "' does not exist.")
}
}
+ for _, bn := range storeIndexBuckets {
+ if b := tx.Bucket([]byte(bn)); b == nil {
+ return errors.New("store: failed to open, index bucket '" + bn + "' does not exist - please re-index the store.")
+ }
+ }
return nil
})
if err != nil {
@@ -124,6 +130,11 @@ func createDB(dbPath string) (db *bolt.DB, version int64, hubUUID string, err er
return err
}
}
+ for _, bn := range storeIndexBuckets {
+ if _, err := tx.CreateBucket([]byte(bn)); err != nil {
+ return err
+ }
+ }
b, err := tx.CreateBucket([]byte(hubInfoBn))
if err != nil {
diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go
index 2e69c89..46a959a 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store_test.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go
@@ -271,6 +271,29 @@ func TestOpen(t *testing.T) {
t.Fatalf("opening store with (some) buckets missing should throw an error")
}
+ // bolt db with missing index buckets
+ if db, err := bolt.Open(testBoltPath, 0600, &bolt.Options{Timeout: 100 * time.Millisecond}); err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ } else {
+ err = db.Update(func(tx *bolt.Tx) error {
+ for _, bn := range storeBuckets {
+ if _, err := tx.CreateBucket([]byte(bn)); err != nil {
+ return err
+ }
+ }
+ return nil
+ })
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if err = db.Close(); err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ }
+ if _, err := NewStore(StoreConfig{testBoltPath, false}); err == nil {
+ t.Fatalf("opening store with index buckets missing should throw an error")
+ }
+
// create new bolt-db and reopen it
os.Remove(testBoltPath)
store, err := NewStore(StoreConfig{testBoltPath, false})
diff --git a/src/hub/src/spreadspace.org/sfive/s5typesStore.go b/src/hub/src/spreadspace.org/sfive/s5typesStore.go
index 9996018..67d38d1 100644
--- a/src/hub/src/spreadspace.org/sfive/s5typesStore.go
+++ b/src/hub/src/spreadspace.org/sfive/s5typesStore.go
@@ -45,6 +45,7 @@ var (
ErrSourceNotFound = errors.New("source entry not found")
ErrClientNotFound = errors.New("client entry not found")
ErrReadOnly = errors.New("store is in read-only mode")
+ ErrIndexCorrupt = errors.New("the search index seems to be corrupt")
)
const (
@@ -62,6 +63,9 @@ const (
userAgentsFwdBn = "UserAgentsFwd"
userAgentsRevBn = "UserAgentsRev"
+ // index buckets
+ timestampsIdxBn = "_timestamps"
+
// well-known keys
hubUUIDKey = "HubUUID"
storeVersionKey = "Version"