Skip to content

Commit

Permalink
Avoid grabbing lock in rduckdb.localDBMonitor if local is already in …
Browse files Browse the repository at this point in the history
…sync with remote (#6436)

* avoid grabbing lock in localDBMonitor if local is already in sync with remote

* comments change

* just use TryAcquire
  • Loading branch information
k-anshul authored Jan 16, 2025
1 parent c52984b commit d2ac620
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions runtime/pkg/rduckdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,19 +644,17 @@ func (d *db) localDBMonitor() {
case <-d.ctx.Done():
return
case <-ticker.C:
err := d.writeSem.Acquire(d.ctx, 1)
if err != nil {
if !errors.Is(err, context.Canceled) {
d.logger.Error("localDBMonitor: error in acquiring write sem", slog.String("error", err.Error()))
}
// We do not want the localDBMonitor to compete with write operations so we return early if writeSem is not available.
// Anyways if a write operation is in progress it will sync the local db
if !d.writeSem.TryAcquire(1) {
continue
}
if !d.localDirty {
d.writeSem.Release(1)
// all good
continue
}
err = d.pullFromRemote(d.ctx, true)
err := d.pullFromRemote(d.ctx, true)
if err != nil && !errors.Is(err, context.Canceled) {
d.logger.Error("localDBMonitor: error in pulling from remote", slog.String("error", err.Error()))
}
Expand Down

0 comments on commit d2ac620

Please sign in to comment.