diff --git a/pkg/service/credential/storage.go b/pkg/service/credential/storage.go index 7a7715fa8..23dd201d5 100644 --- a/pkg/service/credential/storage.go +++ b/pkg/service/credential/storage.go @@ -78,25 +78,6 @@ func NewCredentialStorage(db storage.ServiceStorage) (*Storage, error) { return nil, errors.New("bolt db reference is nil") } - // TODO: (Neal) there is a current bug with our Bolt implementation where if we do a GET without anything in the db it will throw an error - // Doing initial writes and then deleting will "warm up" our database and when we do a GET after that it will not crash and return empty list - // https://github.com/TBD54566975/ssi-service/issues/176 - if err := db.Write(credentialNamespace, fakeKey, nil); err != nil { - return nil, util.LoggingErrorMsg(err, "problem writing status initial write to db") - - } - if err := db.Delete(credentialNamespace, fakeKey); err != nil { - return nil, util.LoggingErrorMsg(err, "problem with initial delete to db") - } - - if err := db.Write(statusListCredentialNamespace, fakeKey, nil); err != nil { - return nil, util.LoggingErrorMsg(err, "problem writing status initial write to db") - } - - if err := db.Delete(statusListCredentialNamespace, fakeKey); err != nil { - return nil, util.LoggingErrorMsg(err, "problem with initial delete to db") - } - randUniqueList := randomUniqueNum(bitStringLength) uniqueNumBytes, err := json.Marshal(randUniqueList) if err != nil { diff --git a/pkg/storage/bolt.go b/pkg/storage/bolt.go index a7549914b..e98538c0e 100644 --- a/pkg/storage/bolt.go +++ b/pkg/storage/bolt.go @@ -90,7 +90,7 @@ func (b *BoltDB) Read(namespace, key string) ([]byte, error) { err := b.db.View(func(tx *bolt.Tx) error { bucket := tx.Bucket([]byte(namespace)) if bucket == nil { - logrus.Infof("namespace<%s> does not exist", namespace) + logrus.Warnf("namespace<%s> does not exist", namespace) return nil } result = bucket.Get([]byte(key)) @@ -105,9 +105,8 @@ func (b *BoltDB) ReadPrefix(namespace, prefix string) (map[string][]byte, error) err := b.db.View(func(tx *bolt.Tx) error { bucket := tx.Bucket([]byte(namespace)) if bucket == nil { - errMsg := fmt.Sprintf("namespace<%s> does not exist", namespace) - logrus.Error(errMsg) - return errors.New(errMsg) + logrus.Warnf("namespace<%s> does not exist", namespace) + return nil } cursor := bucket.Cursor() prefix := []byte(prefix) @@ -124,7 +123,7 @@ func (b *BoltDB) ReadAll(namespace string) (map[string][]byte, error) { err := b.db.View(func(tx *bolt.Tx) error { bucket := tx.Bucket([]byte(namespace)) if bucket == nil { - logrus.Errorf("namespace<%s> does not exist", namespace) + logrus.Warnf("namespace<%s> does not exist", namespace) return nil } cursor := bucket.Cursor() @@ -141,7 +140,8 @@ func (b *BoltDB) ReadAllKeys(namespace string) ([]string, error) { err := b.db.View(func(tx *bolt.Tx) error { bucket := tx.Bucket([]byte(namespace)) if bucket == nil { - return util.LoggingNewErrorf("namespace<%s> does not exist", namespace) + logrus.Warnf("namespace<%s> does not exist", namespace) + return nil } cursor := bucket.Cursor() for k, _ := cursor.First(); k != nil; k, _ = cursor.Next() { diff --git a/pkg/storage/db_test.go b/pkg/storage/db_test.go index 855b54f47..84bb71309 100644 --- a/pkg/storage/db_test.go +++ b/pkg/storage/db_test.go @@ -173,6 +173,31 @@ func TestDBPrefixAndKeys(t *testing.T) { } } +func TestDBEmptyNamespace(t *testing.T) { + for _, dbImpl := range getDBImplementations(t) { + db := dbImpl + + namespace := "dne" + key := "doesnotexist" + + prefixValues, err := db.ReadPrefix(namespace, key) + assert.NoError(t, err) + assert.Len(t, prefixValues, 0) + + allKeys, err := db.ReadAllKeys(namespace) + assert.NoError(t, err) + assert.Len(t, allKeys, 0) + + allValues, err := db.ReadAll(namespace) + assert.NoError(t, err) + assert.Len(t, allValues, 0) + + value, err := db.Read(namespace, key) + assert.NoError(t, err) + assert.Nil(t, value) + } +} + type testStruct struct { Status int `json:"status"` Reason string `json:"reason"`