(canard?) Big Bos of Random Fails is ChainedFastBackend::markAsOutdated()

Created on 2 November 2017, over 7 years ago
Updated 28 April 2023, almost 2 years ago

Problem/Motivation

In #2907728-37: Installer: Convert system functional tests to phpunit we are faced with random fail. Looks like that occurs due to incorrect works of ChainedFastBackend::markAsOutdated(). This is the code:

  /**
   * Marks the fast cache bin as outdated because of a write.
   */
  protected function markAsOutdated() {
    // Clocks on a single server can drift. Multiple servers may have slightly
    // differing opinions about the current time. Given that, do not assume
    // 'now' on this server is always later than our stored timestamp.
    // Also add 1 millisecond, to ensure that caches written earlier in the same
    // millisecond are invalidated. It is possible that caches will be later in
    // the same millisecond and are then incorrectly invalidated, but that only
    // costs one additional roundtrip to the persistent cache.
    $now = round(microtime(TRUE) + .001, 3);
    if ($now > $this->getLastWriteTimestamp()) {
      $this->lastWriteTimestamp = $now;
      $this->consistentBackend->set(self::LAST_WRITE_TIMESTAMP_PREFIX . $this->bin, $this->lastWriteTimestamp);
    }
  }

Here are some examples of last_write_timestamp_BIN_NAME values, when random fail appears.

d:1509618497.0820000171661376953125;
d:1509618497.131000041961669921875;

Modeling a possible situation:

  • server1 wrote last_write_timestamp_BIN_NAME in 1500000000.08200001
  • After 0.00001 seconds server2 call markAsOutdated()
  • If the server2 is behind by 0.00056789 seconds from server1, we get the following:
$now = round(microtime(TRUE) + .001, 3);
microtime(TRUE)= 1500000000.08200001 - 0.00056789 + 0.00001= 1500000000.08144212
microtime(TRUE) + .001 = 1500000000.08244212
round(microtime(TRUE) + .001, 3) = 1500000000.082

As result:
(server2) 1500000000.082 < 1500000000.08200001 (server1)
Despite the fact, that the code on the server2 was executed later.

Remaining tasks

Increase the percision in markAsOutdated() from 3 to 4.

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

10.1

Component
Cache 

Last updated about 7 hours ago

Created by

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024