-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Sharding
-
Fully Compatible
Instead provide an accessor for each Component in VectorTime. This will make external usage less clunky:
Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
auto now = VectorClock::get(opCtx)->getTime(); -auto clusterTime = now[VectorClock::Component::ClusterTime]; +auto clusterTime = now.clusterTime();
The accessors can also use an lvalue ref-qualifier to ensure that the current time is properly stored somewhere, ie. prevent the anti-pattern of:
auto clusterTime = VectorClock::get(opCtx)->getTime().clusterTime();
auto configTime = VectorClock::get(opCtx)->getTime().configTime();
// Cannot assume that configTime <= clusterTime.
which is potentially incorrect, relative to:
auto now = VectorClock::get(opCtx)->getTime();
auto clusterTime = now.clusterTime();
auto configTime = now.configTime();
// Must be true that configTime <= clusterTime.
The advanceTime_forTest will also need some consideration, likely by returning a temporary object that provides a mutator for each Component.