Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ boolean useLatestSnapshotIfWithinDelay()
void forceOrWaitOngoingDatabasePoll()
{
long checkStartTime = System.currentTimeMillis();
long checkStartTimeNanos = System.nanoTime();
ReentrantReadWriteLock.WriteLock lock = startStopPollLock.writeLock();
lock.lock();
try {
Expand All @@ -569,7 +570,6 @@ void forceOrWaitOngoingDatabasePoll()
}
// Verify if there was a on-demand poll completed while we were waiting for the lock
if (latestDatabasePoll instanceof OnDemandDatabasePoll) {
long checkStartTimeNanos = TimeUnit.MILLISECONDS.toNanos(checkStartTime);
Comment thread
vivek807 marked this conversation as resolved.
OnDemandDatabasePoll latestOnDemandPoll = (OnDemandDatabasePoll) latestDatabasePoll;
if (latestOnDemandPoll.initiationTimeNanos > checkStartTimeNanos) {
Comment thread
vivek807 marked this conversation as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Contended force calls still miss the poll they waited for

This still compares the existing on-demand poll's initiation time with the caller's check start. In the common contended path, thread A creates the OnDemandDatabasePoll and holds the write lock while polling; thread B enters forceOrWaitOngoingDatabasePoll after that initiation, waits for the same write lock until A's poll completes, then sees initiationTimeNanos <= checkStartTimeNanos and starts another database poll. That means the PR still serializes duplicate forced polls for callers that arrived during the actual poll, even though the previous poll completed after their call. Track and compare completion time, or otherwise record that the caller waited behind the in-progress on-demand poll, before returning/forcing a new poll.

return;
Expand Down
Loading