Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
fix: Adjust big segments logic to prevent duplicate polls. (#225)
Browse files Browse the repository at this point in the history
The contract tests attempt to determine that the SDK is not making
redundant polls, and sometimes this test would fail.

Theoretically this could also affect a server handling requests on many
threads which concurrently request status before the first request has
completed.
  • Loading branch information
kinyoklion authored May 31, 2024
1 parent 6efa8d7 commit 4202165
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class BigSegmentStoreWrapper : IDisposable
private readonly CancellationTokenSource _pollCanceller;
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
private readonly Logger _logger;
private readonly Task<BigSegmentStoreStatus> _initialPoll;

private BigSegmentStoreStatus? _lastStatus;

Expand All @@ -43,8 +44,9 @@ Logger logger
_taskExecutor = taskExecutor;
_logger = logger;

_initialPoll = Task.Run(PollStoreAndUpdateStatusAsync);
_pollCanceller = taskExecutor.StartRepeatingTask(
TimeSpan.Zero,
config.StatusPollInterval,
config.StatusPollInterval,
PollStoreAndUpdateStatusAsync
);
Expand Down Expand Up @@ -119,11 +121,7 @@ internal BigSegmentStoreStatus GetStatus()
{
_lock.ExitReadLock();
}
if (ret.HasValue)
{
return ret.Value;
}
return AsyncUtils.WaitSafely(() => PollStoreAndUpdateStatusAsync());
return ret ?? _initialPoll.GetAwaiter().GetResult();
}

private async Task<BigSegmentStoreStatus> PollStoreAndUpdateStatusAsync()
Expand Down

0 comments on commit 4202165

Please sign in to comment.