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: record flush_wait_ms in TxnInfo #1342

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions internal/unionstore/pipelined_memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type PipelinedMemDB struct {
// Some([]) -> delete
batchGetCache map[string]util.Option[[]byte]
memChangeHook func(uint64)

// metrics
flushWaitDuration time.Duration
}

const (
Expand Down Expand Up @@ -358,12 +361,14 @@ func (p *PipelinedMemDB) needFlush() bool {
// FlushWait will wait for all flushing tasks are done and return the error if there is a failure.
func (p *PipelinedMemDB) FlushWait() error {
if p.flushingMemDB != nil {
now := time.Now()
err := <-p.errCh
if err != nil {
err = p.handleAlreadyExistErr(err)
}
// cleanup the flushingMemDB so the next call of FlushWait will not wait for the error channel.
p.flushingMemDB = nil
p.flushWaitDuration += time.Since(now)
return err
}
return nil
Expand Down Expand Up @@ -513,3 +518,10 @@ func (p *PipelinedMemDB) Checkpoint() *MemDBCheckpoint {
func (p *PipelinedMemDB) RevertToCheckpoint(*MemDBCheckpoint) {
panic("RevertToCheckpoint is not supported for PipelinedMemDB")
}

// GetFlushMetrics implements MemBuffer interface.
func (p *PipelinedMemDB) GetFlushMetrics() FlushMetrics {
return FlushMetrics{
WaitDuration: p.flushWaitDuration,
}
}
10 changes: 10 additions & 0 deletions internal/unionstore/union_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ package unionstore
import (
"context"
"math"
"time"

tikverr "github.com/tikv/client-go/v2/error"
"github.com/tikv/client-go/v2/kv"
Expand Down Expand Up @@ -236,6 +237,12 @@ type MemBuffer interface {
Flush(force bool) (bool, error)
// FlushWait waits for the flushing task done and return error.
FlushWait() error
// GetFlushDetails returns the metrics related to flushing
GetFlushMetrics() FlushMetrics
}

type FlushMetrics struct {
WaitDuration time.Duration
}

var (
Expand Down Expand Up @@ -287,3 +294,6 @@ func (db *MemDBWithContext) BatchGet(ctx context.Context, keys [][]byte) (map[st
}
return m, nil
}

// GetFlushMetrisc implements the MemBuffer interface.
func (db *MemDBWithContext) GetFlushMetrics() FlushMetrics { return FlushMetrics{} }
2 changes: 2 additions & 0 deletions txnkv/transaction/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ type TxnInfo struct {
OnePCFallback bool `json:"one_pc_fallback"`
ErrMsg string `json:"error,omitempty"`
Pipelined bool `json:"pipelined"`
FlushWaitMs int64 `json:"flush_wait_ms"`
}

func (txn *KVTxn) onCommitted(err error) {
Expand All @@ -875,6 +876,7 @@ func (txn *KVTxn) onCommitted(err error) {
AsyncCommitFallback: txn.committer.hasTriedAsyncCommit && !isAsyncCommit,
OnePCFallback: txn.committer.hasTriedOnePC && !isOnePC,
Pipelined: txn.IsPipelined(),
FlushWaitMs: txn.GetMemBuffer().GetFlushMetrics().WaitDuration.Milliseconds(),
}
if err != nil {
info.ErrMsg = err.Error()
Expand Down
Loading