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

Ludicrous Mode #4872

Merged
merged 26 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
59dc4b9
Add ludicrous mode and use it for startTs
animesh2049 Feb 20, 2020
ca9e94e
Stop syncing to disc
animesh2049 Feb 20, 2020
26314a9
Don't wait for mutations to be applied
animesh2049 Feb 21, 2020
6182e71
Remove Transactions
animesh2049 Feb 24, 2020
0703f73
apply mutations in background
animesh2049 Feb 24, 2020
6e80851
added logic for batching requests
Feb 25, 2020
8c8fdfa
minor changes
Feb 25, 2020
29a3e54
temp
Feb 25, 2020
0ae09e0
Hanlde graceful shutdown in worker
animesh2049 Feb 26, 2020
65e63dd
merged some code
Feb 26, 2020
25113cc
Don't abort old transaction in lud mode
animesh2049 Feb 26, 2020
d5813ce
Merge branch 'animesh2049/ludicrous-mode' of github.com:dgraph-io/dgr…
animesh2049 Feb 26, 2020
c0c8e0e
Changed back somethings
Feb 27, 2020
0474608
Merge branch 'animesh2049/ludicrous-mode' of github.com:dgraph-io/dgr…
Feb 27, 2020
82e3ebc
Skip group checksum
animesh2049 Feb 27, 2020
fe910b6
Temp
animesh2049 Feb 27, 2020
02fa91e
Merge branch 'animesh2049/ludicrous-mode' into animesh2049/lud-mode-2
animesh2049 Feb 27, 2020
e7cf9ed
Some cleanup
animesh2049 Feb 28, 2020
8e1ccd6
Address PR comments
animesh2049 Feb 28, 2020
a2bfc8c
Flush data in background when applying mutation.
Feb 28, 2020
169af3f
Address PR comments
animesh2049 Mar 4, 2020
f627bf7
Address PR comments
animesh2049 Mar 4, 2020
792b934
Simplify the timestamp allocation logic
manishrjain Mar 4, 2020
2b229f4
Address PR comments
animesh2049 Mar 5, 2020
99df3c6
Address PR comments
animesh2049 Mar 5, 2020
79528bc
minor fix
animesh2049 Mar 5, 2020
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
3 changes: 2 additions & 1 deletion dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ they form a Raft group and provide synchronous replication.
grpc.EnableTracing = false

flag.Bool("graphql_introspection", true, "Set to false for no GraphQL schema introspection")

flag.Bool("ludicrous-mode", false, "Run alpha in ludicrous mode")
}

func setupCustomTokenizers() {
Expand Down Expand Up @@ -578,6 +578,7 @@ func run() {
SnapshotAfter: Alpha.Conf.GetInt("snapshot_after"),
AbortOlderThan: abortDur,
StartTime: startTime,
LudicrousMode: Alpha.Conf.GetBool("ludicrous-mode"),
}

setupCustomTokenizers()
Expand Down
1 change: 1 addition & 0 deletions dgraph/cmd/live/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ func fingerprintEdge(t *pb.DirectedEdge, pred *predicate) uint64 {
}

func (l *loader) conflictKeysForNQuad(nq *api.NQuad) ([]uint64, error) {
return nil, nil
pred, found := l.schema.preds[nq.Predicate]

// We dont' need to generate conflict keys for predicate with noconflict directive.
Expand Down
14 changes: 8 additions & 6 deletions dgraph/cmd/zero/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,14 +675,16 @@ func (n *node) Run() {
}
}
n.SaveToStorage(&rd.HardState, rd.Entries, &rd.Snapshot)
timer.Record("disk")
if rd.MustSync {
if err := n.Store.Sync(); err != nil {
glog.Errorf("Error while calling Store.Sync: %v", err)
if !x.WorkerConfig.LudicrousMode {
timer.Record("disk")
if rd.MustSync {
if err := n.Store.Sync(); err != nil {
glog.Errorf("Error while calling Store.Sync: %v", err)
}
timer.Record("sync")
}
timer.Record("sync")
span.Annotatef(nil, "Saved to storage")
}
span.Annotatef(nil, "Saved to storage")

if !raft.IsEmptySnap(rd.Snapshot) {
var state pb.MembershipState
Expand Down
28 changes: 26 additions & 2 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ func (s *Server) doMutate(ctx context.Context, qc *queryContext, resp *api.Respo
qc.span.Annotatef(nil, "Applying mutations: %+v", m)
resp.Txn, err = query.ApplyMutations(ctx, m)
qc.span.Annotatef(nil, "Txn Context: %+v. Err=%v", resp.Txn, err)

if x.WorkerConfig.LudicrousMode {
return err
}

// what are the cases in which a transaction could be aborted. Doesn it make sense
// to abort txn in ludicrous mode ??
if !qc.req.CommitNow {
if err == zero.ErrConflict {
err = status.Error(codes.FailedPrecondition, err.Error())
Expand Down Expand Up @@ -794,15 +801,28 @@ func (s *Server) doQuery(ctx context.Context, req *api.Request, doAuth AuthMode)
// assigned in the processQuery function called below.
defer annotateStartTs(qc.span, qc.req.StartTs)
// For mutations, we update the startTs if necessary.
var startTs uint64
if isMutation && req.StartTs == 0 {
start := time.Now()
req.StartTs = worker.State.GetTimestamp(false)
if !x.WorkerConfig.LudicrousMode {
startTs = worker.State.GetTimestamp(false)
req.StartTs = startTs
} else {
req.StartTs = posting.Oracle().MaxAssigned()
if len(qc.req.GetMutations()) > 0 {
startTs = worker.State.GetTimestamp(false)
}
}
qc.latency.AssignTimestamp = time.Since(start)
}

if resp, rerr = processQuery(ctx, qc); rerr != nil {
return
}

if x.WorkerConfig.LudicrousMode {
req.StartTs = startTs
}
if rerr = s.doMutate(ctx, qc, resp); rerr != nil {
return
}
Expand Down Expand Up @@ -856,7 +876,11 @@ func processQuery(ctx context.Context, qc *queryContext) (*api.Response, error)

if qc.req.StartTs == 0 {
assignTimestampStart := time.Now()
qc.req.StartTs = worker.State.GetTimestamp(qc.req.ReadOnly)
if !x.WorkerConfig.LudicrousMode {
qc.req.StartTs = worker.State.GetTimestamp(qc.req.ReadOnly)
} else {
qc.req.StartTs = posting.Oracle().MaxAssigned()
}
qc.latency.AssignTimestamp = time.Since(assignTimestampStart)
}

Expand Down
4 changes: 4 additions & 0 deletions posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ func (l *List) addMutationInternal(ctx context.Context, txn *Txn, t *pb.Directed
}
l.updateMutationLayer(mpost)

if x.WorkerConfig.LudicrousMode {
return nil
}

// We ensure that commit marks are applied to posting lists in the right
// order. We can do so by proposing them in the same order as received by the Oracle delta
// stream from Zero, instead of in goroutines.
Expand Down
51 changes: 37 additions & 14 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,14 @@ func (n *node) applyCommitted(proposal *pb.Proposal) error {
span.Annotatef(nil, "While applying mutations: %v", err)
return err
}
if x.WorkerConfig.LudicrousMode {
txnTimeStamp := proposal.Mutations.StartTs
return n.commitOrAbort(proposal.Key, &pb.OracleDelta{
Txns: []*pb.TxnStatus{
{StartTs: txnTimeStamp, CommitTs: txnTimeStamp},
},
})
}
span.Annotate(nil, "Done")
return nil
}
Expand Down Expand Up @@ -554,12 +562,20 @@ func (n *node) commitOrAbort(pkey string, delta *pb.OracleDelta) error {
for _, status := range delta.Txns {
toDisk(status.StartTs, status.CommitTs)
}
if err := writer.Flush(); err != nil {
return errors.Wrapf(err, "while flushing to disk")
if x.WorkerConfig.LudicrousMode {
go func() {
writer.Flush()
}()
} else {
if err := writer.Flush(); err != nil {
return errors.Wrapf(err, "while flushing to disk")
}
}

g := groups()
atomic.StoreUint64(&g.deltaChecksum, delta.GroupChecksums[g.groupId()])
if delta.GroupChecksums != nil {
atomic.StoreUint64(&g.deltaChecksum, delta.GroupChecksums[g.groupId()])
}

// Now advance Oracle(), so we can service waiting reads.
posting.Oracle().ProcessDelta(delta)
Expand Down Expand Up @@ -906,18 +922,20 @@ func (n *node) Run() {

// Store the hardstate and entries. Note that these are not CommittedEntries.
n.SaveToStorage(&rd.HardState, rd.Entries, &rd.Snapshot)
timer.Record("disk")
if rd.MustSync {
if err := n.Store.Sync(); err != nil {
glog.Errorf("Error while calling Store.Sync: %+v", err)
if !x.WorkerConfig.LudicrousMode {
timer.Record("disk")
if rd.MustSync {
if err := n.Store.Sync(); err != nil {
glog.Errorf("Error while calling Store.Sync: %+v", err)
}
timer.Record("sync")
}
if span != nil {
span.Annotatef(nil, "Saved %d entries. Snapshot, HardState empty? (%v, %v)",
len(rd.Entries),
raft.IsEmptySnap(rd.Snapshot),
raft.IsEmptyHardState(rd.HardState))
}
timer.Record("sync")
}
if span != nil {
span.Annotatef(nil, "Saved %d entries. Snapshot, HardState empty? (%v, %v)",
len(rd.Entries),
raft.IsEmptySnap(rd.Snapshot),
raft.IsEmptyHardState(rd.HardState))
}

// Now schedule or apply committed entries.
Expand Down Expand Up @@ -953,6 +971,11 @@ func (n *node) Run() {
if span := otrace.FromContext(pctx.Ctx); span != nil {
span.Annotate(nil, "Proposal found in CommittedEntries")
}
if x.WorkerConfig.LudicrousMode {
// Assuming that there will be no error
// while proposing.
n.Proposals.Done(proposal.Key, nil)
}
}
proposal.Index = entry.Index
proposals = append(proposals, proposal)
Expand Down
2 changes: 2 additions & 0 deletions x/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type WorkerOptions struct {
ProposedGroupId uint32
// StartTime is the start time of the alpha
StartTime time.Time
// LudicrousMode is super fast mode with fewer guarantees.
LudicrousMode bool
}

// WorkerConfig stores the global instance of the worker package's options.
Expand Down