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

fix(stmtlogger): lets gemini work with empty 'test-statement-log-file' option #416

Merged
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
30 changes: 22 additions & 8 deletions pkg/stmtlogger/filelogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ const (
errorsOnFileLimit = 5
)

type FileLogger struct {
type StmtToFile interface {
LogStmt(*typedef.Stmt)
LogStmtWithTimeStamp(stmt *typedef.Stmt, ts time.Time)
Close() error
}

type fileLogger struct {
fd *os.File
activeChannel atomic.Pointer[loggerChan]
channel loggerChan
Expand All @@ -46,7 +52,7 @@ type logRec struct {
ts time.Time
}

func (fl *FileLogger) LogStmt(stmt *typedef.Stmt) {
func (fl *fileLogger) LogStmt(stmt *typedef.Stmt) {
ch := fl.activeChannel.Load()
if ch != nil {
*ch <- logRec{
Expand All @@ -55,7 +61,7 @@ func (fl *FileLogger) LogStmt(stmt *typedef.Stmt) {
}
}

func (fl *FileLogger) LogStmtWithTimeStamp(stmt *typedef.Stmt, ts time.Time) {
func (fl *fileLogger) LogStmtWithTimeStamp(stmt *typedef.Stmt, ts time.Time) {
ch := fl.activeChannel.Load()
if ch != nil {
*ch <- logRec{
Expand All @@ -65,11 +71,11 @@ func (fl *FileLogger) LogStmtWithTimeStamp(stmt *typedef.Stmt, ts time.Time) {
}
}

func (fl *FileLogger) Close() error {
func (fl *fileLogger) Close() error {
return fl.fd.Close()
}

func (fl *FileLogger) committer() {
func (fl *fileLogger) committer() {
var err2 error

defer func() {
Expand Down Expand Up @@ -114,16 +120,16 @@ func (fl *FileLogger) committer() {
}
}

func NewFileLogger(filename string) (*FileLogger, error) {
func NewFileLogger(filename string) (StmtToFile, error) {
if filename == "" {
return nil, nil
return &nopFileLogger{}, nil
}
fd, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
return nil, err
}

out := &FileLogger{
out := &fileLogger{
filename: filename,
fd: fd,
channel: make(loggerChan, defaultChanSize),
Expand All @@ -133,3 +139,11 @@ func NewFileLogger(filename string) (*FileLogger, error) {
go out.committer()
return out, nil
}

type nopFileLogger struct{}

func (n *nopFileLogger) LogStmtWithTimeStamp(_ *typedef.Stmt, _ time.Time) {}

func (n *nopFileLogger) Close() error { return nil }

func (n *nopFileLogger) LogStmt(_ *typedef.Stmt) {}
3 changes: 2 additions & 1 deletion pkg/store/cqlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/scylladb/gocqlx/v2/qb"
"go.uber.org/zap"

"github.com/scylladb/gemini/pkg/stmtlogger"
"github.com/scylladb/gemini/pkg/typedef"
)

Expand All @@ -39,7 +40,7 @@ type cqlStore struct { //nolint:govet
maxRetriesMutate int
maxRetriesMutateSleep time.Duration
useServerSideTimestamps bool
stmtLogger stmtLogger
stmtLogger stmtlogger.StmtToFile
}

func (cs *cqlStore) name() string {
Expand Down
8 changes: 1 addition & 7 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ type storeLoader interface {
name() string
}

type stmtLogger interface {
LogStmt(*typedef.Stmt)
LogStmtWithTimeStamp(stmt *typedef.Stmt, ts time.Time)
Close() error
}

type Store interface {
Create(context.Context, *typedef.Stmt, *typedef.Stmt) error
Mutate(context.Context, *typedef.Stmt) error
Expand Down Expand Up @@ -132,7 +126,7 @@ func (n *noOpStore) close() error {
type delegatingStore struct {
oracleStore storeLoader
testStore storeLoader
statementLogger stmtLogger
statementLogger stmtlogger.StmtToFile
logger *zap.Logger
validations bool
}
Expand Down
Loading