You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
742 B
Go
41 lines
742 B
Go
package snapshot
|
|
|
|
import (
|
|
"expvar"
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/hashicorp/raft"
|
|
)
|
|
|
|
// Snapshot represents a snapshot of the database state.
|
|
type Snapshot struct {
|
|
rc io.ReadCloser
|
|
}
|
|
|
|
// NewSnapshot creates a new snapshot.
|
|
func NewSnapshot(rc io.ReadCloser) *Snapshot {
|
|
return &Snapshot{
|
|
rc: rc,
|
|
}
|
|
}
|
|
|
|
// Persist writes the snapshot to the given sink.
|
|
func (s *Snapshot) Persist(sink raft.SnapshotSink) error {
|
|
defer s.rc.Close()
|
|
startT := time.Now()
|
|
|
|
n, err := io.Copy(sink, s.rc)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
dur := time.Since(startT)
|
|
stats.Get(persistSize).(*expvar.Int).Set(n)
|
|
stats.Get(persistDuration).(*expvar.Int).Set(dur.Milliseconds())
|
|
return err
|
|
}
|
|
|
|
// Release releases the snapshot.
|
|
func (s *Snapshot) Release() {}
|