Skip to content
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

feat(Flags): [Breaking] Add flag for snapshot duration frequency #7675

Merged
merged 6 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func getAlpha(idx int, raft string) service {
}

if opts.SnapshotAfter != "" {
raft = fmt.Sprintf("%s; snapshot-after=%s", raft, opts.SnapshotAfter)
raft = fmt.Sprintf("%s; snapshot-after-entries=%s", raft, opts.SnapshotAfter)
}
svc.Command += fmt.Sprintf(` --raft "%s"`, raft)

Expand Down
10 changes: 8 additions & 2 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,15 @@ they form a Raft group and provide synchronous replication.
Flag("learner",
`Make this Alpha a "learner" node. In learner mode, this Alpha will not participate `+
"in Raft elections. This can be used to achieve a read-only replica.").
Flag("snapshot-after",
Flag("snapshot-after-entries",
"Create a new Raft snapshot after N number of Raft entries. The lower this number, "+
"the more frequent snapshot creation will be.").
"the more frequent snapshot creation will be. Snapshots are created if either "+
"snapshot-after-duration or snapshot-after-entries threshold is crossed.").
Flag("snapshot-after-duration",
"Frequency at which we should create a new raft snapshots. Set "+
"to 0 to disable duration based snapshot. Snapshots are "+
"created if either snapshot-after-duration or "+
"snapshot-after-entries threshold is crossed.").
Flag("pending-proposals",
"Number of pending mutation proposals. Useful for rate limiting.").
String())
Expand Down
19 changes: 13 additions & 6 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,10 +997,13 @@ func (n *node) updateRaftProgress() error {

func (n *node) checkpointAndClose(done chan struct{}) {
slowTicker := time.NewTicker(time.Minute)
lastSnapshotTime := time.Now()
defer slowTicker.Stop()

snapshotAfter := x.WorkerConfig.Raft.GetUint64("snapshot-after")
x.AssertTruef(snapshotAfter > 10, "raft.snapshot-after must be a number greater than 10")
snapshotAfterEntries := x.WorkerConfig.Raft.GetUint64("snapshot-after-entries")
x.AssertTruef(snapshotAfterEntries > 10, "raft.snapshot-after must be a number greater than 10")

snapshotAfterDuration := x.WorkerConfig.Raft.GetDuration("snapshot-after-duration")
rohanprasad marked this conversation as resolved.
Show resolved Hide resolved

for {
select {
Expand All @@ -1026,16 +1029,19 @@ func (n *node) checkpointAndClose(done chan struct{}) {

// If we don't have a snapshot, or if there are too many log files in Raft,
// calculate a new snapshot.
calculate := raft.IsEmptySnap(snap) || n.Store.NumLogFiles() > 4
// For snapshotAfterDuration, 0 is a special value used to
// disable time based snapshots.
rohanprasad marked this conversation as resolved.
Show resolved Hide resolved
calculate := raft.IsEmptySnap(snap) || n.Store.NumLogFiles() > 4 ||
(snapshotAfterDuration != 0 && time.Since(lastSnapshotTime) > snapshotAfterDuration)
NamanJain8 marked this conversation as resolved.
Show resolved Hide resolved

if chk, err := n.Store.Checkpoint(); err == nil {
if first, err := n.Store.FirstIndex(); err == nil {
// Save some cycles by only calculating snapshot if the checkpoint has gone
// quite a bit further than the first index.
calculate = calculate || chk >= first+snapshotAfter
calculate = calculate || chk >= first+snapshotAfterEntries
glog.V(3).Infof("Evaluating snapshot first:%d chk:%d (chk-first:%d) "+
"snapshotAfter:%d snap:%v", first, chk, chk-first,
snapshotAfter, calculate)
"snapshotAfterEntries:%d snap:%v", first, chk, chk-first,
snapshotAfterEntries, calculate)
}
}
// We keep track of the applied index in the p directory. Even if we don't take
Expand All @@ -1056,6 +1062,7 @@ func (n *node) checkpointAndClose(done chan struct{}) {
if err := n.proposeSnapshot(); err != nil {
glog.Errorf("While calculating and proposing snapshot: %v", err)
}
lastSnapshotTime = time.Now()
NamanJain8 marked this conversation as resolved.
Show resolved Hide resolved
}
go n.abortOldTransactions()
}
Expand Down
9 changes: 5 additions & 4 deletions worker/server_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ const (
// For easy readability, keep the options without default values (if any) at the end of
// the *Defaults string. Also, since these strings are printed in --help text, avoid line
// breaks.
AclDefaults = `access-ttl=6h; refresh-ttl=30d; secret-file=;`
AuditDefaults = `compress=false; days=10; size=100; dir=; output=; encrypt-file=;`
BadgerDefaults = `compression=snappy; goroutines=8; max-retries=-1;`
RaftDefaults = `learner=false; snapshot-after=10000; pending-proposals=256; idx=; group=;`
AclDefaults = `access-ttl=6h; refresh-ttl=30d; secret-file=;`
AuditDefaults = `compress=false; days=10; size=100; dir=; output=; encrypt-file=;`
BadgerDefaults = `compression=snappy; goroutines=8; max-retries=-1;`
RaftDefaults = `learner=false; snapshot-after-entries=10000; ` +
`snapshot-after-duration=30m; pending-proposals=256; idx=; group=;`
SecurityDefaults = `token=; whitelist=;`
LudicrousDefaults = `enabled=false; concurrency=2000;`
CDCDefaults = `file=; kafka=; sasl_user=; sasl_password=; ca_cert=; client_cert=; ` +
Expand Down