MCPcopy
hub / github.com/dgraph-io/dgraph / commit

Method commit

dgraph/cmd/zero/oracle.go:341–415  ·  view source on GitHub ↗
(ctx context.Context, src *api.TxnContext)

Source from the content-addressed store, hash-verified

339}
340
341func (s *Server) commit(ctx context.Context, src *api.TxnContext) error {
342 span := trace.SpanFromContext(ctx)
343 span.SetAttributes(attribute.Int64("startTs", int64(src.StartTs)))
344 if src.Aborted {
345 return s.proposeTxn(ctx, src)
346 }
347
348 // Use the start timestamp to check if we have a conflict, before we need to assign a commit ts.
349 s.orc.RLock()
350 conflict := s.orc.hasConflict(src)
351 s.orc.RUnlock()
352 if conflict {
353 span.SetAttributes(attribute.Bool("abort", true))
354 src.Aborted = true
355 return s.proposeTxn(ctx, src)
356 }
357
358 checkPreds := func() error {
359 // Check if any of these tablets is being moved. If so, abort the transaction.
360 for _, pkey := range src.Preds {
361 splits := strings.SplitN(pkey, "-", 2)
362 if len(splits) < 2 {
363 return errors.Errorf("Unable to find group id in %s", pkey)
364 }
365 gid, err := strconv.Atoi(splits[0])
366 if err != nil {
367 return errors.Wrapf(err, "unable to parse group id from %s", pkey)
368 }
369 pred := splits[1]
370 if strings.Contains(pred, hnsw.VecKeyword) {
371 pred = pred[0:strings.Index(pred, hnsw.VecKeyword)]
372 }
373 tablet := s.ServingTablet(pred)
374 if tablet == nil {
375 return errors.Errorf("Tablet for %s is nil", pred)
376 }
377 if tablet.GroupId != uint32(gid) {
378 return errors.Errorf("Mutation done in group: %d. Predicate %s assigned to %d",
379 gid, pred, tablet.GroupId)
380 }
381 if s.isBlocked(pred) {
382 return errors.Errorf("Commits on predicate %s are blocked due to predicate move", pred)
383 }
384 }
385 return nil
386 }
387 if err := checkPreds(); err != nil {
388 span.SetAttributes(attribute.Bool("abort", true))
389 src.Aborted = true
390 return s.proposeTxn(ctx, src)
391 }
392
393 num := pb.Num{Val: 1, Type: pb.Num_TXN_TS}
394 assigned, err := s.lease(ctx, &num)
395 if err != nil {
396 return err
397 }
398 src.CommitTs = assigned.StartId

Callers 1

CommitOrAbortMethod · 0.95

Calls 11

proposeTxnMethod · 0.95
ServingTabletMethod · 0.95
isBlockedMethod · 0.95
leaseMethod · 0.95
RLockMethod · 0.80
hasConflictMethod · 0.80
RUnlockMethod · 0.80
IndexMethod · 0.80
ErrorfMethod · 0.45
DoneMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected