MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / write

Method write

xenomint/state.go:358–478  ·  view source on GitHub ↗
(
	ctx context.Context, req *types.Request, isLeader bool)

Source from the content-addressed store, hash-verified

356}
357
358func (s *State) write(
359 ctx context.Context, req *types.Request, isLeader bool) (ref *QueryTracker, resp *types.Response, err error,
360) {
361 var (
362 lastSeq uint64
363 query = &QueryTracker{Req: req}
364 totalAffectedRows int64
365 curAffectedRows int64
366 lastInsertID int64
367 start = time.Now()
368
369 lockAcquired, writeDone, enqueued, lockReleased, respBuilt time.Duration
370 )
371
372 defer func() {
373 var fields = log.Fields{}
374 fields["lastSeq"] = lastSeq
375 fields["1#lockAcquired"] = float64(lockAcquired.Nanoseconds()) / 1000
376 if writeDone > 0 {
377 fields["2#writeDone"] = float64((writeDone - lockAcquired).Nanoseconds()) / 1000
378 }
379 if enqueued > 0 {
380 fields["3#enqueued"] = float64((enqueued - writeDone).Nanoseconds()) / 1000
381 }
382 if lockReleased > 0 {
383 fields["4#lockReleased"] = float64((lockReleased - enqueued).Nanoseconds()) / 1000
384 }
385 if respBuilt > 0 {
386 fields["5#respBuilt"] = float64((respBuilt - lockReleased).Nanoseconds()) / 1000
387 }
388 log.WithFields(fields).Debug("Write duration stat (us)")
389 if ctx.Err() != nil {
390 log.WithError(err).WithField("req", req).Warning("write query canceled")
391 }
392 }()
393
394 if err = func() (err error) {
395 var (
396 ierr error
397 qcnt = len(req.Payload.Queries)
398 )
399 s.Lock()
400 lockAcquired = time.Since(start)
401 defer func() {
402 s.Unlock()
403 lockReleased = time.Since(start)
404 }()
405 lastSeq = s.getSeq()
406 if qcnt > 1 && s.level == sql.LevelReadUncommitted {
407 // Set savepoint
408 if _, ierr = s.handler.Exec(`SAVEPOINT "?"`, lastSeq); ierr != nil {
409 err = errors.Wrapf(ierr, "failed to create savepoint %d", lastSeq)
410 return
411 }
412 defer func() {
413 _, _ = s.handler.Exec(`ROLLBACK TO "?"`, lastSeq)
414 }()
415 }

Callers 1

QueryWithContextMethod · 0.95

Calls 15

getSeqMethod · 0.95
writeSingleMethod · 0.95
getLastCommitPointMethod · 0.95
flushHandlerMethod · 0.95
getLocalTimeMethod · 0.95
WithFieldsFunction · 0.92
WithErrorFunction · 0.92
DebugMethod · 0.80
WarningMethod · 0.80
WithFieldMethod · 0.80
setFailedMethod · 0.80
enqueueMethod · 0.80

Tested by

no test coverage detected