summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/s/database_version.cpp31
-rw-r--r--src/mongo/s/database_version.h4
2 files changed, 23 insertions, 12 deletions
diff --git a/src/mongo/s/database_version.cpp b/src/mongo/s/database_version.cpp
index e2043e39299..b2797ba4c87 100644
--- a/src/mongo/s/database_version.cpp
+++ b/src/mongo/s/database_version.cpp
@@ -66,23 +66,30 @@ BSONObj ComparableDatabaseVersion::toBSONForLogging() const {
}
bool ComparableDatabaseVersion::operator==(const ComparableDatabaseVersion& other) const {
- if (!_dbVersion && !other._dbVersion)
- return true; // Default constructed value
- if (_dbVersion.is_initialized() != other._dbVersion.is_initialized())
- return false; // One side is default constructed value
-
- return *_dbVersion == *other._dbVersion;
+ return _dbVersion == other._dbVersion;
}
bool ComparableDatabaseVersion::operator<(const ComparableDatabaseVersion& other) const {
- if (!_dbVersion && !other._dbVersion)
- return false; // Default constructed value
+ // 1. If both versions are valid and have timestamps
+ // 1.1. if their timestamps are the same -> rely on lastMod to define the order
+ // 1.2. Otherwise -> rely on the timestamps values to define order
+ // 2. If both versions are valid and have the same uuid -> rely on lastMod to define the order
+ // 3. Any other scenario -> rely on disambiguating sequence number
+ if (_dbVersion && other._dbVersion) {
+ const auto timestamp = _dbVersion->getTimestamp();
+ const auto otherTimestamp = other._dbVersion->getTimestamp();
+ if (timestamp && otherTimestamp) {
+ if (*timestamp == *otherTimestamp)
+ return _dbVersion->getLastMod() < other._dbVersion->getLastMod();
+ else
+ return *timestamp < *otherTimestamp;
- if (_dbVersion && other._dbVersion && _dbVersion->getUuid() == other._dbVersion->getUuid()) {
- return _dbVersion->getLastMod() < other._dbVersion->getLastMod();
- } else {
- return _uuidDisambiguatingSequenceNum < other._uuidDisambiguatingSequenceNum;
+ } else if (_dbVersion->getUuid() == other._dbVersion->getUuid()) {
+ return _dbVersion->getLastMod() < other._dbVersion->getLastMod();
+ }
}
+
+ return _uuidDisambiguatingSequenceNum < other._uuidDisambiguatingSequenceNum;
}
} // namespace mongo
diff --git a/src/mongo/s/database_version.h b/src/mongo/s/database_version.h
index adaa1ff3963..82fe6c9bab7 100644
--- a/src/mongo/s/database_version.h
+++ b/src/mongo/s/database_version.h
@@ -46,6 +46,7 @@ namespace mongo {
class DatabaseVersion : private DatabaseVersionBase {
public:
using DatabaseVersionBase::getLastMod;
+ using DatabaseVersionBase::getTimestamp;
using DatabaseVersionBase::toBSON;
// It returns a new DatabaseVersion marked as fixed. A fixed database version is used to
@@ -76,6 +77,9 @@ public:
DatabaseVersion makeUpdated() const;
+ /**
+ * It returns true if the uuid and lastmod of both versions are the same.
+ */
bool operator==(const DatabaseVersion& other) const {
return getUuid() == other.getUuid() && getLastMod() == other.getLastMod();
}