Skip to content

Commit

Permalink
Remove TranslateErr from Generic
Browse files Browse the repository at this point in the history
  • Loading branch information
marco6 committed Jan 9, 2025
1 parent 0d2b3cc commit c56d815
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
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

0 comments on commit c56d815

Please sign in to comment.