diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2015-12-21 16:16:49 -0500 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2016-01-11 17:07:15 -0500 |
commit | 1c28e37982441275cc127853985b30f2c6e74ff5 (patch) | |
tree | 91df17a54ebd236f7621c27c148c9741b417f2b2 /src/mongo/bson/oid.cpp | |
parent | 7ac8ef6631e8797213255159b1485423eeceaf15 (diff) | |
download | mongo-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.cpp | 9 |
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); } |