summaryrefslogtreecommitdiff
path: root/src/mongo/s/write_ops
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-08-14 15:31:31 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-08-14 15:31:31 -0400
commit1cee34ee3907b7652abdfc7f75ca27ef421a46c4 (patch)
tree54b3e59b4a066e3b3acf4b1bc44998cebf7f6fe5 /src/mongo/s/write_ops
parentcec89b290906adb7d36507d20d619aaa5a6f6c16 (diff)
downloadmongo-1cee34ee3907b7652abdfc7f75ca27ef421a46c4.tar.gz
Revert "SERVER-19855 Include min OpTime with shard version"
This reverts commit cec89b290906adb7d36507d20d619aaa5a6f6c16.
Diffstat (limited to 'src/mongo/s/write_ops')
-rw-r--r--src/mongo/s/write_ops/batch_write_op.cpp9
-rw-r--r--src/mongo/s/write_ops/batched_delete_request_test.cpp32
-rw-r--r--src/mongo/s/write_ops/batched_insert_request_test.cpp32
-rw-r--r--src/mongo/s/write_ops/batched_request_metadata.cpp45
-rw-r--r--src/mongo/s/write_ops/batched_request_metadata.h28
-rw-r--r--src/mongo/s/write_ops/batched_request_metadata_test.cpp16
-rw-r--r--src/mongo/s/write_ops/batched_update_request_test.cpp32
-rw-r--r--src/mongo/s/write_ops/write_op.cpp3
-rw-r--r--src/mongo/s/write_ops/write_op_test.cpp6
9 files changed, 124 insertions, 79 deletions
diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp
index ba7ddae8d95..113dd9133f8 100644
--- a/src/mongo/s/write_ops/batch_write_op.cpp
+++ b/src/mongo/s/write_ops/batch_write_op.cpp
@@ -87,13 +87,11 @@ static int compareEndpoints(const ShardEndpoint* endpointA, const ShardEndpoint*
if (shardNameDiff != 0)
return shardNameDiff;
- long shardVersionDiff = endpointA->shardVersion.getVersion().toLong() -
- endpointB->shardVersion.getVersion().toLong();
+ long shardVersionDiff = endpointA->shardVersion.toLong() - endpointB->shardVersion.toLong();
if (shardVersionDiff != 0)
return shardVersionDiff;
- int shardEpochDiff = endpointA->shardVersion.getVersion().epoch().compare(
- endpointB->shardVersion.getVersion().epoch());
+ int shardEpochDiff = endpointA->shardVersion.epoch().compare(endpointB->shardVersion.epoch());
return shardEpochDiff;
}
@@ -458,8 +456,7 @@ void BatchWriteOp::buildBatchRequest(const TargetedWriteBatch& targetedBatch,
unique_ptr<BatchedRequestMetadata> requestMetadata(new BatchedRequestMetadata());
requestMetadata->setShardName(targetedBatch.getEndpoint().shardName);
- requestMetadata->setShardVersion(
- ChunkVersionAndOpTime(targetedBatch.getEndpoint().shardVersion));
+ requestMetadata->setShardVersion(targetedBatch.getEndpoint().shardVersion);
requestMetadata->setSession(0);
request->setMetadata(requestMetadata.release());
}
diff --git a/src/mongo/s/write_ops/batched_delete_request_test.cpp b/src/mongo/s/write_ops/batched_delete_request_test.cpp
index c8f71652599..87d883f1b0b 100644
--- a/src/mongo/s/write_ops/batched_delete_request_test.cpp
+++ b/src/mongo/s/write_ops/batched_delete_request_test.cpp
@@ -46,24 +46,32 @@ TEST(BatchedDeleteRequest, Basic) {
BSON(BatchedDeleteDocument::query(BSON("a" << 1)) << BatchedDeleteDocument::limit(1))
<< BSON(BatchedDeleteDocument::query(BSON("b" << 1)) << BatchedDeleteDocument::limit(1)));
- BSONObj origDeleteRequestObj = BSON(
- BatchedDeleteRequest::collName("test")
- << BatchedDeleteRequest::deletes() << deleteArray
- << BatchedDeleteRequest::writeConcern(BSON("w" << 1)) << BatchedDeleteRequest::ordered(true)
- << BatchedDeleteRequest::metadata() << BSON("shardName"
- << "shard000"
- << "shardVersion"
- << BSON_ARRAY(Timestamp(1, 2) << OID::gen())
- << "ts" << Timestamp(3, 4) << "t" << 5
- << "session" << 0LL));
+ BSONObj writeConcernObj = BSON("w" << 1);
+
+ // The BSON_ARRAY macro doesn't support Timestamps.
+ BSONArrayBuilder arrBuilder;
+ arrBuilder.append(Timestamp(1, 1));
+ arrBuilder.append(OID::gen());
+ BSONArray shardVersionArray = arrBuilder.arr();
+
+ BSONObj origDeleteRequestObj =
+ BSON(BatchedDeleteRequest::collName("test")
+ << BatchedDeleteRequest::deletes() << deleteArray
+ << BatchedDeleteRequest::writeConcern(writeConcernObj)
+ << BatchedDeleteRequest::ordered(true) << BatchedDeleteRequest::metadata()
+ << BSON(BatchedRequestMetadata::shardName("shard000")
+ << BatchedRequestMetadata::shardVersion() << shardVersionArray
+ << BatchedRequestMetadata::session(0)));
string errMsg;
BatchedDeleteRequest request;
- ASSERT_TRUE(request.parseBSON("foo", origDeleteRequestObj, &errMsg));
+ bool ok = request.parseBSON("foo", origDeleteRequestObj, &errMsg);
+ ASSERT_TRUE(ok);
ASSERT_EQ("foo.test", request.getNS().ns());
- ASSERT_EQUALS(origDeleteRequestObj, request.toBSON());
+ BSONObj genDeleteRequestObj = request.toBSON();
+ ASSERT_EQUALS(0, genDeleteRequestObj.woCompare(origDeleteRequestObj));
}
} // namespace
diff --git a/src/mongo/s/write_ops/batched_insert_request_test.cpp b/src/mongo/s/write_ops/batched_insert_request_test.cpp
index 09e8e950c08..e31503d431f 100644
--- a/src/mongo/s/write_ops/batched_insert_request_test.cpp
+++ b/src/mongo/s/write_ops/batched_insert_request_test.cpp
@@ -45,24 +45,32 @@ namespace {
TEST(BatchedInsertRequest, Basic) {
BSONArray insertArray = BSON_ARRAY(BSON("a" << 1) << BSON("b" << 1));
- BSONObj origInsertRequestObj = BSON(
- BatchedInsertRequest::collName("test")
- << BatchedInsertRequest::documents() << insertArray
- << BatchedInsertRequest::writeConcern(BSON("w" << 1)) << BatchedInsertRequest::ordered(true)
- << BatchedInsertRequest::metadata() << BSON("shardName"
- << "shard000"
- << "shardVersion"
- << BSON_ARRAY(Timestamp(1, 2) << OID::gen())
- << "ts" << Timestamp(3, 4) << "t" << 5
- << "session" << 0LL));
+ BSONObj writeConcernObj = BSON("w" << 1);
+
+ // The BSON_ARRAY macro doesn't support Timestamps.
+ BSONArrayBuilder arrBuilder;
+ arrBuilder.append(Timestamp(1, 1));
+ arrBuilder.append(OID::gen());
+ BSONArray shardVersionArray = arrBuilder.arr();
+
+ BSONObj origInsertRequestObj =
+ BSON(BatchedInsertRequest::collName("test")
+ << BatchedInsertRequest::documents() << insertArray
+ << BatchedInsertRequest::writeConcern(writeConcernObj)
+ << BatchedInsertRequest::ordered(true) << BatchedInsertRequest::metadata()
+ << BSON(BatchedRequestMetadata::shardName("shard0000")
+ << BatchedRequestMetadata::shardVersion() << shardVersionArray
+ << BatchedRequestMetadata::session(0)));
string errMsg;
BatchedInsertRequest request;
- ASSERT_TRUE(request.parseBSON("foo", origInsertRequestObj, &errMsg));
+ bool ok = request.parseBSON("foo", origInsertRequestObj, &errMsg);
+ ASSERT_TRUE(ok);
ASSERT_EQ("foo.test", request.getNS().ns());
- ASSERT_EQUALS(origInsertRequestObj, request.toBSON());
+ BSONObj genInsertRequestObj = request.toBSON();
+ ASSERT_EQUALS(0, genInsertRequestObj.woCompare(origInsertRequestObj));
}
TEST(BatchedInsertRequest, GenIDAll) {
diff --git a/src/mongo/s/write_ops/batched_request_metadata.cpp b/src/mongo/s/write_ops/batched_request_metadata.cpp
index 78ecefbb9df..a2e21f99e4c 100644
--- a/src/mongo/s/write_ops/batched_request_metadata.cpp
+++ b/src/mongo/s/write_ops/batched_request_metadata.cpp
@@ -26,8 +26,6 @@
* it in the license file.
*/
-#include "mongo/platform/basic.h"
-
#include "mongo/s/write_ops/batched_request_metadata.h"
#include "mongo/db/field_parser.h"
@@ -57,8 +55,9 @@ BSONObj BatchedRequestMetadata::toBSON() const {
if (_isShardNameSet)
metadataBuilder << shardName(_shardName);
- if (_shardVersion) {
- _shardVersion.get().appendForCommands(&metadataBuilder);
+ if (_shardVersion.get()) {
+ // ChunkVersion wants to be an array.
+ metadataBuilder.append(shardVersion(), static_cast<BSONArray>(_shardVersion->toBSON()));
}
if (_isSessionSet)
@@ -81,12 +80,12 @@ bool BatchedRequestMetadata::parseBSON(const BSONObj& source, string* errMsg) {
_isShardNameSet = fieldState == FieldParser::FIELD_SET;
{
- auto verAndOpTStatus = ChunkVersionAndOpTime::parseFromBSONForCommands(source);
- if (!verAndOpTStatus.isOK()) {
+ std::unique_ptr<ChunkVersion> tempChunkVersion(new ChunkVersion);
+ fieldState = FieldParser::extract(source, shardVersion, tempChunkVersion.get(), errMsg);
+ if (fieldState == FieldParser::FIELD_INVALID)
return false;
- }
-
- _shardVersion = verAndOpTStatus.getValue();
+ if (fieldState == FieldParser::FIELD_SET)
+ _shardVersion.swap(tempChunkVersion);
}
fieldState = FieldParser::extract(source, session, &_session, errMsg);
@@ -114,7 +113,10 @@ string BatchedRequestMetadata::toString() const {
void BatchedRequestMetadata::cloneTo(BatchedRequestMetadata* other) const {
other->_shardName = _shardName;
other->_isShardNameSet = _isShardNameSet;
- other->_shardVersion = _shardVersion;
+
+ if (other->_shardVersion.get())
+ _shardVersion->cloneTo(other->_shardVersion.get());
+
other->_session = _session;
other->_isSessionSet = _isSessionSet;
}
@@ -124,21 +126,36 @@ void BatchedRequestMetadata::setShardName(StringData shardName) {
_isShardNameSet = true;
}
+void BatchedRequestMetadata::unsetShardName() {
+ _isShardNameSet = false;
+}
+
+bool BatchedRequestMetadata::isShardNameSet() const {
+ return _isShardNameSet;
+}
+
const string& BatchedRequestMetadata::getShardName() const {
dassert(_isShardNameSet);
return _shardName;
}
-void BatchedRequestMetadata::setShardVersion(const ChunkVersionAndOpTime& shardVersion) {
- _shardVersion = shardVersion;
+void BatchedRequestMetadata::setShardVersion(const ChunkVersion& shardVersion) {
+ unique_ptr<ChunkVersion> temp(new ChunkVersion);
+ shardVersion.cloneTo(temp.get());
+ _shardVersion.reset(temp.release());
+}
+
+void BatchedRequestMetadata::unsetShardVersion() {
+ _shardVersion.reset();
}
bool BatchedRequestMetadata::isShardVersionSet() const {
- return _shardVersion.is_initialized();
+ return _shardVersion.get() != NULL;
}
const ChunkVersion& BatchedRequestMetadata::getShardVersion() const {
- return _shardVersion.get().getVersion();
+ dassert(_shardVersion.get());
+ return *_shardVersion;
}
void BatchedRequestMetadata::setSession(long long session) {
diff --git a/src/mongo/s/write_ops/batched_request_metadata.h b/src/mongo/s/write_ops/batched_request_metadata.h
index 2b885e9018d..6e31cb60713 100644
--- a/src/mongo/s/write_ops/batched_request_metadata.h
+++ b/src/mongo/s/write_ops/batched_request_metadata.h
@@ -28,33 +28,34 @@
#pragma once
-#include <boost/optional.hpp>
#include <string>
+#include "mongo/base/disallow_copying.h"
#include "mongo/db/jsobj.h"
#include "mongo/s/bson_serializable.h"
#include "mongo/s/chunk_version.h"
namespace mongo {
+class BatchedRequestMetadata : public BSONSerializable {
+ MONGO_DISALLOW_COPYING(BatchedRequestMetadata);
-class BatchedRequestMetadata {
public:
static const BSONField<std::string> shardName;
static const BSONField<ChunkVersion> shardVersion;
static const BSONField<long long> session;
BatchedRequestMetadata();
- ~BatchedRequestMetadata();
+ virtual ~BatchedRequestMetadata();
//
// bson serializable interface implementation
//
- bool isValid(std::string* errMsg) const;
- BSONObj toBSON() const;
- bool parseBSON(const BSONObj& source, std::string* errMsg);
- void clear();
- std::string toString() const;
+ virtual bool isValid(std::string* errMsg) const;
+ virtual BSONObj toBSON() const;
+ virtual bool parseBSON(const BSONObj& source, std::string* errMsg);
+ virtual void clear();
+ virtual std::string toString() const;
void cloneTo(BatchedRequestMetadata* other) const;
@@ -63,12 +64,14 @@ public:
//
void setShardName(StringData shardName);
+ void unsetShardName();
+ bool isShardNameSet() const;
const std::string& getShardName() const;
- void setShardVersion(const ChunkVersionAndOpTime& shardVersion);
+ void setShardVersion(const ChunkVersion& shardVersion);
+ void unsetShardVersion();
bool isShardVersionSet() const;
const ChunkVersion& getShardVersion() const;
- const repl::OpTime& getOpTime() const;
void setSession(long long session);
void unsetSession();
@@ -81,11 +84,10 @@ private:
bool _isShardNameSet;
// (O) version for this collection on a given shard
- boost::optional<ChunkVersionAndOpTime> _shardVersion;
+ std::unique_ptr<ChunkVersion> _shardVersion;
// (O) session number the inserts belong to
long long _session;
bool _isSessionSet;
};
-
-} // namespace mongo
+}
diff --git a/src/mongo/s/write_ops/batched_request_metadata_test.cpp b/src/mongo/s/write_ops/batched_request_metadata_test.cpp
index 978ee865045..f35bcee4ef9 100644
--- a/src/mongo/s/write_ops/batched_request_metadata_test.cpp
+++ b/src/mongo/s/write_ops/batched_request_metadata_test.cpp
@@ -40,16 +40,22 @@ using std::string;
namespace {
TEST(BatchedRequestMetadata, Basic) {
- BSONObj metadataObj(BSON("shardName"
- << "shard0000"
- << "shardVersion" << BSON_ARRAY(Timestamp(1, 2) << OID::gen()) << "ts"
- << Timestamp(3, 4) << "t" << 5 << "session" << 0LL));
+ // The BSON_ARRAY macro doesn't support Timestamps.
+ BSONArrayBuilder arrBuilder;
+ arrBuilder.append(Timestamp(1, 1));
+ arrBuilder.append(OID::gen());
+ BSONArray shardVersionArray = arrBuilder.arr();
+
+ BSONObj metadataObj(BSON(BatchedRequestMetadata::shardName("shard0000")
+ << BatchedRequestMetadata::shardVersion() << shardVersionArray
+ << BatchedRequestMetadata::session(100)));
string errMsg;
BatchedRequestMetadata metadata;
ASSERT_TRUE(metadata.parseBSON(metadataObj, &errMsg));
- ASSERT_EQUALS(metadataObj, metadata.toBSON());
+ BSONObj genMetadataObj = metadata.toBSON();
+ ASSERT_EQUALS(metadataObj, genMetadataObj);
}
} // namespace
diff --git a/src/mongo/s/write_ops/batched_update_request_test.cpp b/src/mongo/s/write_ops/batched_update_request_test.cpp
index af7bb5aadfb..04994733537 100644
--- a/src/mongo/s/write_ops/batched_update_request_test.cpp
+++ b/src/mongo/s/write_ops/batched_update_request_test.cpp
@@ -50,24 +50,32 @@ TEST(BatchedUpdateRequest, Basic) {
<< BatchedUpdateDocument::updateExpr(BSON("$set" << BSON("b" << 2)))
<< BatchedUpdateDocument::multi(false) << BatchedUpdateDocument::upsert(false)));
- BSONObj origUpdateRequestObj = BSON(
- BatchedUpdateRequest::collName("test")
- << BatchedUpdateRequest::updates() << updateArray
- << BatchedUpdateRequest::writeConcern(BSON("w" << 1)) << BatchedUpdateRequest::ordered(true)
- << BatchedUpdateRequest::metadata() << BSON("shardName"
- << "shard000"
- << "shardVersion"
- << BSON_ARRAY(Timestamp(1, 2) << OID::gen())
- << "ts" << Timestamp(3, 4) << "t" << 5
- << "session" << 0LL));
+ BSONObj writeConcernObj = BSON("w" << 1);
+
+ // The BSON_ARRAY macro doesn't support Timestamps.
+ BSONArrayBuilder arrBuilder;
+ arrBuilder.append(Timestamp(1, 1));
+ arrBuilder.append(OID::gen());
+ BSONArray shardVersionArray = arrBuilder.arr();
+
+ BSONObj origUpdateRequestObj =
+ BSON(BatchedUpdateRequest::collName("test")
+ << BatchedUpdateRequest::updates() << updateArray
+ << BatchedUpdateRequest::writeConcern(writeConcernObj)
+ << BatchedUpdateRequest::ordered(true) << BatchedUpdateRequest::metadata()
+ << BSON(BatchedRequestMetadata::shardName("shard0000")
+ << BatchedRequestMetadata::shardVersion() << shardVersionArray
+ << BatchedRequestMetadata::session(0)));
string errMsg;
BatchedUpdateRequest request;
- ASSERT_TRUE(request.parseBSON("foo", origUpdateRequestObj, &errMsg));
+ bool ok = request.parseBSON("foo", origUpdateRequestObj, &errMsg);
+ ASSERT_TRUE(ok);
ASSERT_EQ("foo.test", request.getNS().ns());
- ASSERT_EQUALS(origUpdateRequestObj, request.toBSON());
+ BSONObj genUpdateRequestObj = request.toBSON();
+ ASSERT_EQUALS(0, genUpdateRequestObj.woCompare(origUpdateRequestObj));
}
} // namespace
diff --git a/src/mongo/s/write_ops/write_op.cpp b/src/mongo/s/write_ops/write_op.cpp
index 8cd20fa4865..25f9f13b3aa 100644
--- a/src/mongo/s/write_ops/write_op.cpp
+++ b/src/mongo/s/write_ops/write_op.cpp
@@ -127,8 +127,7 @@ Status WriteOp::targetWrites(OperationContext* txn,
if (endpoints.size() == 1u) {
targetedWrites->push_back(new TargetedWrite(*endpoint, ref));
} else {
- ShardEndpoint broadcastEndpoint(endpoint->shardName,
- ChunkVersionAndOpTime(ChunkVersion::IGNORED()));
+ ShardEndpoint broadcastEndpoint(endpoint->shardName, ChunkVersion::IGNORED());
targetedWrites->push_back(new TargetedWrite(broadcastEndpoint, ref));
}
diff --git a/src/mongo/s/write_ops/write_op_test.cpp b/src/mongo/s/write_ops/write_op_test.cpp
index 233aa824337..e488c068e47 100644
--- a/src/mongo/s/write_ops/write_op_test.cpp
+++ b/src/mongo/s/write_ops/write_op_test.cpp
@@ -218,11 +218,11 @@ TEST(WriteOpTests, TargetMultiAllShards) {
ASSERT_EQUALS(targeted.size(), 3u);
sortByEndpoint(&targeted);
ASSERT_EQUALS(targeted[0]->endpoint.shardName, endpointA.shardName);
- ASSERT(ChunkVersion::isIgnoredVersion(targeted[0]->endpoint.shardVersion.getVersion()));
+ ASSERT(ChunkVersion::isIgnoredVersion(targeted[0]->endpoint.shardVersion));
ASSERT_EQUALS(targeted[1]->endpoint.shardName, endpointB.shardName);
- ASSERT(ChunkVersion::isIgnoredVersion(targeted[1]->endpoint.shardVersion.getVersion()));
+ ASSERT(ChunkVersion::isIgnoredVersion(targeted[1]->endpoint.shardVersion));
ASSERT_EQUALS(targeted[2]->endpoint.shardName, endpointC.shardName);
- ASSERT(ChunkVersion::isIgnoredVersion(targeted[2]->endpoint.shardVersion.getVersion()));
+ ASSERT(ChunkVersion::isIgnoredVersion(targeted[2]->endpoint.shardVersion));
writeOp.noteWriteComplete(*targeted[0]);
writeOp.noteWriteComplete(*targeted[1]);