Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

fixing namespace seeding issue #241

Merged
merged 7 commits into from
Jan 9, 2023
Merged

fixing namespace seeding issue #241

merged 7 commits into from
Jan 9, 2023

Conversation

nitro-neal
Copy link
Contributor

Currently we do an empty write to the credential bolt db to get around a bug where if you do a read before anything is written it will throw an error

it's because the namespace bolt is using is created on first write. we should open up another issue to address it.
solutions:

#176

I have handled this error by logic in the code.

If we think a better solution would be to NOT return an error if the bucket / namespace does not exist I am happy to implement that fix instead of this.

@@ -220,7 +220,7 @@ func (s Service) CreateCredential(request CreateCredentialRequest) (*CreateCrede
func getStatusListCredential(s Service, issuerID string, schemaID string) (*credential.VerifiableCredential, error) {
storedStatusListCreds, err := s.storage.GetStatusListCredentialsByIssuerAndSchema(issuerID, schemaID)
if err != nil {
return nil, util.LoggingNewErrorf("problem with getting status list credential for issuer: %s schema: %s", issuerID, schemaID)
logrus.Warnf("problem with getting status list credential for issuer: %s schema: %s. Continuing because this could be first time accessing this pair...", issuerID, schemaID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logrus.WithError(err).Warnf(...

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you see ReadPrefix and ReadAllKeys we return an error; however, in Read and in ReadAll we do not.

I think all of these should not return an error and instead return a warning.

Similarly, for deletes we may want to change to a warning as well.

Edit: Neal I see you mentioned this too. Sorry, missed that.

@andresuribe87
Copy link
Contributor

If we think a better solution would be to NOT return an error if the bucket / namespace does not exist I am happy to implement that fix instead of this.

Heavy +1 to this.

Comment on lines -81 to -99
// 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")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

errMsg := fmt.Sprintf("namespace<%s> does not exist", namespace)
logrus.Error(errMsg)
return errors.New(errMsg)
logrus.Infof("namespace<%s> does not exist", namespace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should log on this since it's expected behavior.

Instead, a test can detect whether the implementation is correct. Is there a unit test covering this behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup agree,

I have created unit tests and removed this log

pkg/storage/bolt.go Outdated Show resolved Hide resolved
@@ -141,7 +136,7 @@ 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)
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep the error as a warn or info

@nitro-neal nitro-neal merged commit d0dde58 into main Jan 9, 2023
@nitro-neal nitro-neal deleted the bolt-namespace-issue branch January 9, 2023 22:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants