summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2015-04-09 08:02:20 -0400
committerEric Milkie <milkie@10gen.com>2015-04-09 08:02:20 -0400
commit48f14493a3751483b67144897a44ed3297720f8c (patch)
tree596e6a9a7993de99622cd8d17cbc549a5a217704 /src/mongo/db/ops
parent04a120d6dc50d6bb1fd5073ea28a6c8ddc07fecd (diff)
downloadmongo-48f14493a3751483b67144897a44ed3297720f8c.tar.gz
Revert "SERVER-15047 Remove undefined behavior from Timestamp"
This reverts commit e87716a9286b6aa6f63a513012e55f6e42f634a2.
Diffstat (limited to 'src/mongo/db/ops')
-rw-r--r--src/mongo/db/ops/modifier_object_replace.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/mongo/db/ops/modifier_object_replace.cpp b/src/mongo/db/ops/modifier_object_replace.cpp
index 292a1534498..5ebbb4bd342 100644
--- a/src/mongo/db/ops/modifier_object_replace.cpp
+++ b/src/mongo/db/ops/modifier_object_replace.cpp
@@ -28,7 +28,6 @@
#include "mongo/db/ops/modifier_object_replace.h"
-#include "mongo/base/data_cursor.h"
#include "mongo/base/error_codes.h"
#include "mongo/bson/mutable/document.h"
#include "mongo/db/global_timestamp.h"
@@ -48,14 +47,16 @@ namespace mongo {
BSONElement e = i.next();
// Skip _id field -- we do not replace it
- if (e.type() == bsonTimestamp &&
- e.fieldNameStringData() != idFieldName &&
- e.timestamp().getSecs() == 0 &&
- e.timestamp().getInc() == 0) {
- Timestamp ts(getNextGlobalTimestamp());
- DataCursor(const_cast<char*>(e.value()))
- .writeLEAndAdvance<uint32_t>(ts.getInc())
- .writeLE<uint32_t>(ts.getSecs());
+ if (e.type() == bsonTimestamp && e.fieldNameStringData() != idFieldName) {
+ // TODO(emilkie): This is not endian-safe.
+ unsigned long long &timestamp =
+ *(reinterpret_cast<unsigned long long*>(
+ const_cast<char *>(e.value())));
+ if (timestamp == 0) {
+ // performance note, this locks a mutex:
+ Timestamp ts(getNextGlobalTimestamp());
+ timestamp = ts.asULL();
+ }
}
}