-
Notifications
You must be signed in to change notification settings - Fork 2.2k
backport:allow misson control manager to startup despite errors #10402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v0.20.x-branch
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,30 +133,81 @@ func (b *missionControlStore) clear() error { | |
| } | ||
|
|
||
| // fetchAll returns all results currently stored in the database. | ||
| // It also removes any corrupted entries that fail to deserialize from both | ||
| // the database and the in-memory tracking structures. | ||
| func (b *missionControlStore) fetchAll() ([]*paymentResult, error) { | ||
| var results []*paymentResult | ||
| var corruptedKeys [][]byte | ||
|
|
||
| err := b.db.view(func(resultBucket kvdb.RBucket) error { | ||
| err := b.db.update(func(resultBucket kvdb.RwBucket) error { | ||
| results = make([]*paymentResult, 0) | ||
| corruptedKeys = make([][]byte, 0) | ||
|
|
||
| return resultBucket.ForEach(func(k, v []byte) error { | ||
| err := resultBucket.ForEach(func(k, v []byte) error { | ||
| result, err := deserializeResult(k, v) | ||
|
|
||
| // In case of an error, track the key for removal. | ||
| if err != nil { | ||
| return err | ||
| log.Warnf("Failed to deserialize mission "+ | ||
| "control entry (key=%x): %v", k, err) | ||
|
|
||
| // Make a copy of the key since ForEach reuses | ||
| // the slice. | ||
| keyCopy := make([]byte, len(k)) | ||
| copy(keyCopy, k) | ||
| corruptedKeys = append(corruptedKeys, keyCopy) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| results = append(results, result) | ||
|
|
||
| return nil | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Delete corrupted entries from the database. | ||
| for _, key := range corruptedKeys { | ||
| if err := resultBucket.Delete(key); err != nil { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do this in another pass in a diff txn? That way the happy case it only needs a read transaction. |
||
| return fmt.Errorf("failed to delete corrupted "+ | ||
| "entry: %w", err) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| }, func() { | ||
| results = nil | ||
| corruptedKeys = nil | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Remove corrupted keys from in-memory tracking. | ||
| for _, key := range corruptedKeys { | ||
| keyStr := string(key) | ||
| delete(b.keysMap, keyStr) | ||
|
|
||
| // Remove from the keys list. | ||
| for e := b.keys.Front(); e != nil; e = e.Next() { | ||
| keyVal, ok := e.Value.(string) | ||
| if !ok { | ||
| continue | ||
| } | ||
| if keyVal == keyStr { | ||
| b.keys.Remove(e) | ||
| break | ||
| } | ||
| } | ||
|
Comment on lines
+194
to
+203
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loop to remove a key from While corrupted keys are expected to be rare, this could be made more efficient. Consider changing This would require changes in |
||
| } | ||
|
|
||
| if len(corruptedKeys) > 0 { | ||
| log.Infof("Removed %d corrupted mission control entries", | ||
| len(corruptedKeys)) | ||
| } | ||
|
|
||
| return results, nil | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the word 'ecounntering'. It should be 'encountering'.