lockanalyzer

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectBlockedTransactions

func DetectBlockedTransactions(db *bun.DB) []string

DetectBlockedTransactions detects blocked transactions in real-time

Types

type Block

type Block struct {
	bun.BaseModel `bun:"table:blocks"`
	ID            string `bun:",pk,type:uuid,default:gen_random_uuid()"`
	ModelID       string `bun:",type:uuid,notnull,on_delete:CASCADE"`
	Model         *Model `bun:"rel:belongs-to,join:model_id=id"`
	Type          string `bun:",notnull"`
	Name          string
}

type BlockedTransaction

type BlockedTransaction struct {
	PID       string
	Duration  string
	Query     string
	WaitEvent string
}

BlockedTransaction contains information about a blocked transaction

type DeadlockInfo

type DeadlockInfo struct {
	Transaction1   LockInfo
	Transaction2   LockInfo
	ConflictType   string
	Recommendation string
}

DeadlockInfo contains information about a potential deadlock

type File

type File struct {
	bun.BaseModel `bun:"table:files"`
	ID            string   `bun:",pk,type:uuid,default:gen_random_uuid()"`
	ProjectID     string   `bun:",type:uuid,notnull,on_delete:CASCADE"`
	Project       *Project `bun:"rel:belongs-to,join:project_id=id"`
	Content       string
}

type IndexInfo

type IndexInfo struct {
	Name  string
	Table string
	Size  string
	Usage string
}

IndexInfo contains information about an index

type LockInfo

type LockInfo struct {
	PID           int
	Mode          string
	Granted       bool
	ObjectType    string
	ObjectName    string
	Page          string
	Tuple         string
	VirtualXID    string
	TransactionID string
	WaitTime      time.Duration
	Query         string
	Type          string
	Object        string
}

LockInfo contains detailed information about a lock

type LockReportFormatter

type LockReportFormatter interface {
	Format(data *ReportData, output io.Writer) error
	GetFileExtension() string
}

LockReportFormatter defines the interface for report formatters

type LongTransaction

type LongTransaction struct {
	PID      string
	Duration string
	Query    string
}

LongTransaction contains information about a long transaction

type Model

type Model struct {
	bun.BaseModel `bun:"table:models"`
	ID            string   `bun:",pk,type:uuid,default:gen_random_uuid()"`
	ProjectID     string   `bun:",type:uuid,notnull,on_delete:CASCADE"`
	Project       *Project `bun:"rel:belongs-to,join:project_id=id"`
	State         string
}

type ObjectConflict

type ObjectConflict struct {
	Object         string
	PIDs           []string
	Mode           string
	Recommendation string
}

ObjectConflict contains information about an object conflict

type Parameter

type Parameter struct {
	bun.BaseModel `bun:"table:parameters"`
	ID            string `bun:",pk,type:uuid,default:gen_random_uuid()"`
	BlockID       string `bun:",type:uuid,notnull,on_delete:CASCADE"`
	Block         *Block `bun:"rel:belongs-to,join:block_id=id"`
	Key           string `bun:",column:key"`
	FileID        string `bun:",type:uuid,notnull,on_delete:CASCADE"`
	File          *File  `bun:"rel:belongs-to,join:file_id=id"`
}

type Project

type Project struct {
	bun.BaseModel `bun:"table:projects"`
	ID            string `bun:",pk,type:uuid,default:gen_random_uuid()"`
	Name          string
	ModifiedAt    time.Time `bun:",default:now()"`
}

type ReportData

type ReportData struct {
	Timestamp       time.Time
	Locks           []LockInfo
	RowLocks        []RowLockInfo
	Deadlocks       []DeadlockInfo
	BlockedTxns     []BlockedTransaction
	LongTxns        []LongTransaction
	ObjectConflicts []ObjectConflict
	IndexAnalysis   []IndexInfo
	Suggestions     []string
	Summary         ReportSummary
}

ReportData contains all data needed to generate a report

func GenerateLocksReport

func GenerateLocksReport(db *bun.DB) (*ReportData, error)

GenerateLocksReport generates a complete locks report and returns the data

type ReportSummary

type ReportSummary struct {
	TotalLocks      int
	BlockedTxns     int
	LongTxns        int
	Deadlocks       int
	ObjectConflicts int
	CriticalIssues  int
	Warnings        int
	Recommendations int
}

ReportSummary contains a summary of detected issues

type RowLockInfo

type RowLockInfo struct {
	PID     int
	Table   string
	Page    string
	Tuple   string
	Mode    string
	Granted bool
}

RowLockInfo contains information about row locks

type TestDB

type TestDB struct {
	DB *bun.DB
}

TestDB contains a test database with fixtures

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址