Skip to content

Commit 714625e

Browse files
committed
add log messages
1 parent 5689627 commit 714625e

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

leader/leader.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,29 @@ func New(factory repository.Factory, log *zap.SugaredLogger) leader.Elector {
2828
func (e *elector) tryAdvisoryLock(ctx context.Context, lockKey uint32) (*sql.Tx, bool) {
2929
db, err := e.factory.PublicDB().DB()
3030
if err != nil {
31+
e.log.Errorf("failed to get database connection: %v", err)
3132
return nil, false
3233
}
3334

3435
// Use background context so transaction isn't auto-cancelled.
3536
// Very unlikely, but we don't want another instance to acquire the lock and begin work before we have exited.
3637
tx, err := db.BeginTx(context.Background(), nil)
3738
if err != nil {
39+
e.log.Errorf("failed to begin transaction: %v", err)
3840
return nil, false
3941
}
4042

4143
var hasLock bool
4244
err = tx.QueryRowContext(ctx, "SELECT pg_try_advisory_xact_lock($1)", lockKey).Scan(&hasLock)
4345
if err != nil {
4446
tx.Rollback()
47+
e.log.Errorf("failed to acquire advisory lock: %v", err)
4548
return nil, false
4649
}
4750

4851
if !hasLock {
4952
tx.Rollback()
53+
e.log.Errorf("failed to acquire advisory lock: %v", err)
5054
return nil, false
5155
}
5256
return tx, true

0 commit comments

Comments
 (0)