-
Couldn't load subscription status.
- Fork 2.2k
[Feature]: Persist imported Mission Control Data across restarts #8898
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: master
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
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -266,8 +266,23 @@ func (m *MissionControl) init() error { | |
| m.applyPaymentResult(result) | ||
| } | ||
|
|
||
| mcSnapshots, err := m.store.fetchMCData() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| mcPairsPersisted := 0 | ||
| for _, mcSnapshot := range mcSnapshots { | ||
| err := m.ImportHistory(mcSnapshot, false, true) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| mcPairsPersisted += len(mcSnapshot.Pairs) | ||
| } | ||
|
|
||
| log.Debugf("Mission control state reconstruction finished: "+ | ||
| "n=%v, time=%v", len(results), time.Since(start)) | ||
| "raw_payment_results_count=%v, persisted_mc_pairs_count=%v, "+ | ||
| "time=%v", len(results), mcPairsPersisted, time.Since(start)) | ||
|
|
||
| return nil | ||
| } | ||
|
|
@@ -312,8 +327,10 @@ func (m *MissionControl) SetConfig(cfg *MissionControlConfig) error { | |
| } | ||
|
|
||
| // ResetHistory resets the history of MissionControl returning it to a state as | ||
| // if no payment attempts have been made. | ||
| func (m *MissionControl) ResetHistory() error { | ||
| // if no payment attempts have been made. If the resetImportedPersistedMC | ||
| // flag is set to true, it also resets the imported and persisted mission | ||
| // control data on disk. | ||
| func (m *MissionControl) ResetHistory(resetImportedPersistedMC bool) error { | ||
| m.Lock() | ||
| defer m.Unlock() | ||
|
|
||
|
|
@@ -323,6 +340,13 @@ func (m *MissionControl) ResetHistory() error { | |
|
|
||
| m.state.resetHistory() | ||
|
|
||
| if resetImportedPersistedMC { | ||
| err := m.store.resetMCData() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| log.Debugf("Mission control history cleared") | ||
|
|
||
| return nil | ||
|
|
@@ -360,11 +384,11 @@ func (m *MissionControl) GetHistorySnapshot() *MissionControlSnapshot { | |
| return m.state.getSnapshot() | ||
| } | ||
|
|
||
| // ImportHistory imports the set of mission control results provided to our | ||
| // in-memory state. These results are not persisted, so will not survive | ||
| // restarts. | ||
| // ImportHistory imports the set of mission control results to our in-memory | ||
| // state and disk, ensuring that the mission control data is available across | ||
| // restarts (if persistMC flag is set). | ||
| func (m *MissionControl) ImportHistory(history *MissionControlSnapshot, | ||
| force bool) error { | ||
| force bool, persistMC bool) error { | ||
|
|
||
| if history == nil { | ||
| return errors.New("cannot import nil history") | ||
|
|
@@ -378,6 +402,13 @@ func (m *MissionControl) ImportHistory(history *MissionControlSnapshot, | |
|
|
||
| imported := m.state.importSnapshot(history, force) | ||
|
|
||
| if persistMC { | ||
| err := m.store.persistMCData(history) | ||
|
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. so it will first import the new data, and then flush the updated set to disk ? |
||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| log.Infof("Imported %v results to mission control", imported) | ||
|
|
||
| return nil | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.