summaryrefslogtreecommitdiff
path: root/src/mongo/bson/oid.cpp
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2015-12-21 16:16:49 -0500
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2016-01-11 17:07:15 -0500
commit1c28e37982441275cc127853985b30f2c6e74ff5 (patch)
tree91df17a54ebd236f7621c27c148c9741b417f2b2 /src/mongo/bson/oid.cpp
parent7ac8ef6631e8797213255159b1485423eeceaf15 (diff)
downloadmongo-1c28e37982441275cc127853985b30f2c6e74ff5.tar.gz
SERVER-21744 ElectionID always increases under PV0 and PV1.
Reset election id on PV upgrade and downgrade.
Diffstat (limited to 'src/mongo/bson/oid.cpp')
-rw-r--r--src/mongo/bson/oid.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/mongo/bson/oid.cpp b/src/mongo/bson/oid.cpp
index a8ef6bb56ef..26d90d97bad 100644
--- a/src/mongo/bson/oid.cpp
+++ b/src/mongo/bson/oid.cpp
@@ -32,6 +32,7 @@
#include "mongo/bson/oid.h"
#include <boost/functional/hash.hpp>
+#include <limits>
#include "mongo/base/init.h"
#include "mongo/bson/bsonobjbuilder.h"
@@ -138,9 +139,11 @@ void OID::init() {
setIncrement(Increment::next());
}
-void OID::init(int64_t term) {
- // each set* method handles endianness
- setTimestamp(time(0));
+void OID::initFromTermNumber(int64_t term) {
+ // Each set* method handles endianness.
+ // Set max timestamp because the drivers compare ElectionId's to determine valid new primaries,
+ // and we want ElectionId's with terms to supercede ones without terms.
+ setTimestamp(std::numeric_limits<Timestamp>::max());
_view().write<BigEndian<int64_t>>(term, kInstanceUniqueOffset);
}