Skip to content

Commit

Permalink
Renaming variables for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
marco6 committed Jan 10, 2025
1 parent bc182e3 commit cb544d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions pkg/kine/drivers/dqlite/dqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func NewVariant(ctx context.Context, datasourceName string, connectionPoolConfig
logrus.Printf("New kine for dqlite")

// Driver name will be extracted from query parameters
generic, err := sqlite.NewVariant(ctx, "", datasourceName, connectionPoolConfig)
driver_, err := sqlite.NewVariant(ctx, "", datasourceName, connectionPoolConfig)
if err != nil {
return nil, errors.Wrap(err, "sqlite client")
}

conn, err := generic.DB.Conn(ctx)
conn, err := driver_.DB.Conn(ctx)
if err != nil {
return nil, err
}
Expand All @@ -47,8 +47,8 @@ func NewVariant(ctx context.Context, datasourceName string, connectionPoolConfig
if err := migrate(ctx, conn); err != nil {
return nil, errors.Wrap(err, "failed to migrate DB from sqlite")
}
generic.LockWrites = true
generic.Retry = func(err error) bool {
driver_.LockWrites = true
driver_.Retry = func(err error) bool {
// get the inner-most error if possible
err = errors.Cause(err)

Expand Down Expand Up @@ -78,14 +78,14 @@ func NewVariant(ctx context.Context, datasourceName string, connectionPoolConfig

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

return generic, nil
return driver_, nil
}

func migrate(ctx context.Context, newDB *sql.Conn) (exitErr error) {
Expand Down
16 changes: 8 additions & 8 deletions pkg/kine/drivers/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func NewVariant(ctx context.Context, driverName, dataSourceName string, connecti
opts.dsn = "./db/state.db?_journal=WAL&_synchronous=FULL&_foreign_keys=1"
}

dialect, err := generic.Open(ctx, driverName, opts.dsn, connectionPoolConfig)
driver, err := generic.Open(ctx, driverName, opts.dsn, connectionPoolConfig)
if err != nil {
return nil, err
}
for i := 0; i < retryAttempts; i++ {
err = func() error {
conn, err := dialect.DB.Conn(ctx)
conn, err := driver.DB.Conn(ctx)
if err != nil {
return err
}
Expand All @@ -83,27 +83,27 @@ func NewVariant(ctx context.Context, driverName, dataSourceName string, connecti
time.Sleep(time.Second)
}

dialect.TranslateErr = func(err error) error {
driver.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
driver.CompactInterval = opts.compactInterval
driver.PollInterval = opts.pollInterval
driver.WatchQueryTimeout = opts.watchQueryTimeout

if driverName == "sqlite3" {
dialect.Retry = func(err error) bool {
driver.Retry = func(err error) bool {
if err, ok := err.(sqlite3.Error); ok {
return err.Code == sqlite3.ErrBusy
}
return false
}
}

return dialect, nil
return driver, nil
}

// setup performs table setup, which may include creation of the Kine table if
Expand Down

0 comments on commit cb544d3

Please sign in to comment.