MCPcopy
hub / github.com/kopia/kopia / Shutdown

Method Shutdown

tests/robustness/engine/engine.go:108–157  ·  view source on GitHub ↗

Shutdown makes a last snapshot then flushes the metadata and prints the final statistics.

(ctx context.Context)

Source from the content-addressed store, hash-verified

106
107// Shutdown makes a last snapshot then flushes the metadata and prints the final statistics.
108func (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
159func (e *Engine) setupLogging() error {
160 dirPath := e.MetaStore.GetPersistDir()

Callers 7

stopMethod · 0.80
runMethod · 0.80
shutdownHTTPServerFunction · 0.80
UnmountMethod · 0.80
CleanupMethod · 0.80
CleanupMethod · 0.80
cleanupMethod · 0.80

Calls 12

ExecActionMethod · 0.95
StatsMethod · 0.95
cleanComponentsMethod · 0.95
saveLogMethod · 0.95
saveStatsMethod · 0.95
saveSnapIDIndexMethod · 0.95
NowFunction · 0.92
FindLastThisRunMethod · 0.80
StringThisRunMethod · 0.80
SubMethod · 0.80
FlushMetadataMethod · 0.65
StringMethod · 0.45

Tested by 2

CleanupMethod · 0.64
cleanupMethod · 0.64