Shutdown makes a last snapshot then flushes the metadata and prints the final statistics.
(ctx context.Context)
| 106 | |
| 107 | // Shutdown makes a last snapshot then flushes the metadata and prints the final statistics. |
| 108 | func (e *Engine) Shutdown(ctx context.Context) error { |
| 109 | // Perform a snapshot action to capture the state of the data directory |
| 110 | // at the end of the run |
| 111 | lastWriteEntry := e.EngineLog.FindLastThisRun(WriteRandomFilesActionKey) |
| 112 | lastSnapEntry := e.EngineLog.FindLastThisRun(SnapshotDirActionKey) |
| 113 | |
| 114 | if lastWriteEntry != nil { |
| 115 | if lastSnapEntry == nil || lastSnapEntry.Idx < lastWriteEntry.Idx { |
| 116 | // Only force a final snapshot if the data tree has been modified since the last snapshot |
| 117 | e.ExecAction(ctx, SnapshotDirActionKey, make(map[string]string)) //nolint:errcheck |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | var cleanupSummaryBuilder strings.Builder |
| 122 | |
| 123 | cleanupSummaryBuilder.WriteString("\n================\n") |
| 124 | cleanupSummaryBuilder.WriteString("Cleanup Summary:\n\n") |
| 125 | cleanupSummaryBuilder.WriteString(e.Stats()) |
| 126 | cleanupSummaryBuilder.WriteString("\n\n") |
| 127 | cleanupSummaryBuilder.WriteString(e.EngineLog.StringThisRun()) |
| 128 | cleanupSummaryBuilder.WriteString("\n") |
| 129 | |
| 130 | log.Print(cleanupSummaryBuilder.String()) |
| 131 | |
| 132 | e.RunStats.RunTime = clock.Now().Sub(e.RunStats.CreationTime) |
| 133 | e.CumulativeStats.RunTime += e.RunStats.RunTime |
| 134 | |
| 135 | defer e.cleanComponents() |
| 136 | |
| 137 | if e.MetaStore != nil { |
| 138 | err := e.saveLog(ctx) |
| 139 | if err != nil { |
| 140 | return err |
| 141 | } |
| 142 | |
| 143 | err = e.saveStats(ctx) |
| 144 | if err != nil { |
| 145 | return err |
| 146 | } |
| 147 | |
| 148 | err = e.saveSnapIDIndex(ctx) |
| 149 | if err != nil { |
| 150 | return err |
| 151 | } |
| 152 | |
| 153 | return e.MetaStore.FlushMetadata() |
| 154 | } |
| 155 | |
| 156 | return nil |
| 157 | } |
| 158 | |
| 159 | func (e *Engine) setupLogging() error { |
| 160 | dirPath := e.MetaStore.GetPersistDir() |