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

Remove TranslateErr from Generic #220

Merged
merged 2 commits into from
Jan 14, 2025
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
6 changes: 0 additions & 6 deletions pkg/kine/drivers/dqlite/dqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ func NewVariant(ctx context.Context, datasourceName string, connectionPoolConfig

return false
}
generic.TranslateErr = func(err error) error {
if strings.Contains(err.Error(), "UNIQUE constraint") {
return server.ErrKeyExists
}
return err
}

return backend, generic, nil
}
Expand Down
24 changes: 6 additions & 18 deletions pkg/kine/drivers/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,15 @@ func (s Stripped) String() string {
}

type ErrRetry func(error) bool
type TranslateErr func(error) error
type ErrCode func(error) string

type Generic struct {
sync.Mutex

LockWrites bool
DB *prepared.DB
Retry ErrRetry
TranslateErr TranslateErr
ErrCode ErrCode
LockWrites bool
DB *prepared.DB
Retry ErrRetry
ErrCode ErrCode

// CompactInterval is interval between database compactions performed by kine.
CompactInterval time.Duration
Expand Down Expand Up @@ -451,12 +449,7 @@ func (d *Generic) Create(ctx context.Context, key string, value []byte, ttl int6
ctx, span := otelTracer.Start(ctx, fmt.Sprintf("%s.Create", otelName))

defer func() {
if err != nil {
if d.TranslateErr != nil {
err = d.TranslateErr(err)
}
span.RecordError(err)
}
span.RecordError(err)
span.SetAttributes(attribute.Int64("revision", rev))
span.End()
}()
Expand All @@ -483,12 +476,7 @@ func (d *Generic) Create(ctx context.Context, key string, value []byte, ttl int6
func (d *Generic) Update(ctx context.Context, key string, value []byte, preRev, ttl int64) (rev int64, updated bool, err error) {
ctx, span := otelTracer.Start(ctx, fmt.Sprintf("%s.Update", otelName))
defer func() {
if err != nil {
if d.TranslateErr != nil {
err = d.TranslateErr(err)
}
span.RecordError(err)
}
span.RecordError(err)
span.End()
}()

Expand Down
7 changes: 0 additions & 7 deletions pkg/kine/drivers/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ func NewVariant(ctx context.Context, driverName, dataSourceName string, connecti
time.Sleep(time.Second)
}

dialect.TranslateErr = func(err error) error {
if err, ok := err.(sqlite3.Error); ok && err.ExtendedCode == sqlite3.ErrConstraintUnique {
return server.ErrKeyExists
}
return err
}

dialect.CompactInterval = opts.compactInterval
dialect.PollInterval = opts.pollInterval
dialect.WatchQueryTimeout = opts.watchQueryTimeout
Expand Down
1 change: 0 additions & 1 deletion pkg/kine/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

var (
ErrKeyExists = rpctypes.ErrGRPCDuplicateKey
ErrCompacted = rpctypes.ErrGRPCCompacted
ErrGRPCUnhealthy = rpctypes.ErrGRPCUnhealthy
)
Expand Down
Loading