Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use same timestamp for end and start of adjacent versions

  • Loading branch information...
commit c353ba8ea93a36cc02ff8de776a231695f30cad9 1 parent adb59ac
@stefankoegl authored
View
4 src/mongo/db/instance.cpp
@@ -108,10 +108,10 @@ namespace mongo {
mongo::mutex OpTime::m("optime");
// OpTime::now() uses mutex, thus it is in this file not in the cpp files used by drivers and such
- void BSONElementManipulator::initTimestamp(bool reInit) {
+ void BSONElementManipulator::initTimestamp() {
massert( 10332 , "Expected CurrentTime type", _element.type() == Timestamp );
unsigned long long &timestamp = *( reinterpret_cast< unsigned long long* >( value() ) );
- if ( timestamp == 0 || reInit) {
+ if ( timestamp == 0) {
mutex::scoped_lock lk(OpTime::m);
timestamp = OpTime::now(lk).asDate();
}
View
2  src/mongo/db/jsobjmanipulator.h
@@ -35,7 +35,7 @@ namespace mongo {
/** Replace a Timestamp type with a Date type initialized to
OpTime::now().asDate()
*/
- void initTimestamp(bool reInit=false);
+ void initTimestamp();
// Note the ones with a capital letter call getDur().writing and journal
View
11 src/mongo/db/ops/update.cpp
@@ -391,7 +391,8 @@ namespace mongo {
debug);
- setTransactionStartTimestamp(newObj);
+ newObj = setTransactionStartTimestamp(newObj, existingObj);
+
checkTooLarge(newObj);
verify(nsdt);
theDataFileMgr.insert(ns, newObj.objdata(), newObj.objsize());
@@ -465,13 +466,7 @@ namespace mongo {
checkTooLarge(existingObj);
verify(nsdt);
- /* clone document and with existing (non-temporal) _id */
- BSONElement idValue = onDisk.getFieldDotted("_id._id");
- BSONObjBuilder bb;
- bb.append(idValue);
- bb.appendElementsUnique(updateobj);
- BSONObj newObj = bb.obj();
-
+ BSONObj newObj = setTransactionStartTimestamp(updateobj, existingObj);
/* update existing version */
theDataFileMgr.updateRecord(ns,
View
18 src/mongo/db/ttime.cpp
@@ -20,7 +20,7 @@ namespace mongo {
* {_id: ObjectId(1234), a: 1} =>
* {_id: {_id: ObjectId(1234), transaction_start: Timestamp(789456, 1), transaction_end: null}, a: 1}
*/
- BSONObj wrapObjectId(BSONObj obj) {
+ BSONObj wrapObjectId(BSONObj obj, unsigned long long int val, unsigned int inc) {
/* only do all that, if we are not dealing with a temporal object already */
if ( !obj.getFieldDotted("_id.transaction_start").eoo() ) {
@@ -32,7 +32,7 @@ namespace mongo {
/* move original _id into an transaction-time _id object */
BSONObjBuilder bb;
bb.append(idField);
- bb.appendTimestamp("transaction_start");
+ bb.appendTimestamp("transaction_start", val, inc);
bb.appendNull("transaction_end");
BSONObj temporalId = bb.obj();
@@ -57,10 +57,16 @@ namespace mongo {
return obj.replaceField("_id", idField);
}
- void setTransactionStartTimestamp(BSONObj obj) {
- BSONElement startTimestamp = obj.getFieldDotted(
- "_id.transaction_start");
- BSONElementManipulator(startTimestamp).initTimestamp(true);
+ BSONObj setTransactionStartTimestamp(BSONObj newObj, BSONObj prevObj)
+ {
+ Date_t endTimestampTime = prevObj.getFieldDotted("_id.transaction_end").timestampTime();
+ unsigned int endTimestampInc = prevObj.getFieldDotted("_id.transaction_end").timestampInc();
+
+ BSONElement idValue = prevObj.getFieldDotted("_id._id");
+ BSONObjBuilder bb;
+ bb.append(idValue);
+ bb.appendElementsUnique(newObj);
+ return wrapObjectId(bb.obj(), endTimestampTime, endTimestampInc);
}
}
View
4 src/mongo/db/ttime.h
@@ -14,13 +14,13 @@
namespace mongo {
- BSONObj wrapObjectId(BSONObj obj);
+ BSONObj wrapObjectId(BSONObj obj, unsigned long long int val = 0, unsigned inc = 0);
BSONObj addCurrentVersionCriterion(BSONObj pattern);
BSONObj setTransactionEndTimestamp(BSONObj obj);
- void setTransactionStartTimestamp(BSONObj obj);
+ BSONObj setTransactionStartTimestamp(BSONObj newObj, BSONObj prevObj);
}
#endif /* TTIME_H_ */
Please sign in to comment.
Something went wrong with that request. Please try again.