Skip to content

Commit

Permalink
Turning snapshot save/restore into flag
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpert committed Oct 10, 2022
1 parent 3c8c0f9 commit d933ac9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var Cleanup = flag.Bool("cleanup", false, "Only cleanup marmot triggers and changelogs")
var SaveSnapshot = flag.Bool("save-snapshot", false, "Only take snapshot and upload")
var RestoreSnapshot = flag.Bool("restore-snapshot", true, "Restore snapshot at boot")
var EnableSnapshot = flag.Bool("enable-snapshot", true, "Restore snapshot at boot")
var DBPathString = flag.String("db-path", "/tmp/marmot.db", "Path to SQLite database")
var NodeID = flag.Uint64("node-id", rand.Uint64(), "Node ID")
var NatsAddr = flag.String("nats-url", nats.DefaultURL, "NATS server URL")
Expand Down
16 changes: 9 additions & 7 deletions logstream/replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ func (r *Replicator) Publish(hash uint64, payload []byte) error {
return err
}

snapshotEntries := uint64(*cfg.MaxLogEntries) / r.shards
if snapshotEntries != 0 && ack.Sequence%snapshotEntries == 0 && shardID == SnapshotShardID {
log.Debug().
Uint64("seq", ack.Sequence).
Str("stream", ack.Stream).
Msg("Initiating save snapshot")
go r.SaveSnapshot()
if *cfg.EnableSnapshot {
snapshotEntries := uint64(*cfg.MaxLogEntries) / r.shards
if snapshotEntries != 0 && ack.Sequence%snapshotEntries == 0 && shardID == SnapshotShardID {
log.Debug().
Uint64("seq", ack.Sequence).
Str("stream", ack.Stream).
Msg("Initiating save snapshot")
go r.SaveSnapshot()
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion marmot.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
return
}

if *cfg.RestoreSnapshot {
if *cfg.EnableSnapshot {
err = rep.RestoreSnapshot()
if err != nil {
log.Panic().Err(err).Msg("Unable to restore snapshot")
Expand Down

0 comments on commit d933ac9

Please sign in to comment.