mirror of
https://github.com/rancher/steve.git
synced 2025-09-13 13:59:40 +00:00
Better gc (#717)
* More error wrapping for SQL cache * Use context.Context instead of stopCh * Move CacheFor to Info log level * Implement time-based GC * Set default GC param when running standalone steve
This commit is contained in:
@@ -63,6 +63,13 @@ type Client interface {
|
||||
//
|
||||
// The transaction is committed if f returns nil, otherwise it is rolled back.
|
||||
func (c *client) WithTransaction(ctx context.Context, forWriting bool, f WithTransactionFunction) error {
|
||||
if err := c.withTransaction(ctx, forWriting, f); err != nil {
|
||||
return fmt.Errorf("transaction: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *client) withTransaction(ctx context.Context, forWriting bool, f WithTransactionFunction) error {
|
||||
c.connLock.RLock()
|
||||
// note: this assumes _txlock=immediate in the connection string, see NewConnection
|
||||
tx, err := c.conn.BeginTx(ctx, &sql.TxOptions{
|
||||
@@ -70,7 +77,7 @@ func (c *client) WithTransaction(ctx context.Context, forWriting bool, f WithTra
|
||||
})
|
||||
c.connLock.RUnlock()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("begin tx: %w", err)
|
||||
}
|
||||
|
||||
if err = f(transaction.NewClient(tx)); err != nil {
|
||||
|
Reference in New Issue
Block a user