summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2022-04-13 09:42:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-13 10:27:36 +0000
commit19f6bf91662cc08edb0bd8d3b12390cae96036b3 (patch)
tree6c90df0f65c6f9d06afa27cb3f215b0ec5384501
parent5966f1395bca6147ef0322b7cda7e84121f4bf98 (diff)
downloadmongo-19f6bf91662cc08edb0bd8d3b12390cae96036b3.tar.gz
SERVER-65491 Use the new ChunkVersion format in the positional paths
-rw-r--r--src/mongo/base/error_codes.yml2
-rw-r--r--src/mongo/db/ops/write_ops.cpp4
-rw-r--r--src/mongo/db/ops/write_ops.idl1
-rw-r--r--src/mongo/db/ops/write_ops_parsers.h2
-rw-r--r--src/mongo/s/chunk_version.cpp38
-rw-r--r--src/mongo/s/chunk_version.h7
-rw-r--r--src/mongo/s/chunk_version.idl10
-rw-r--r--src/mongo/s/write_ops/batch_write_exec.cpp2
-rw-r--r--src/mongo/s/write_ops/batched_command_response_test.cpp1
-rw-r--r--src/mongo/s/write_ops/write_op.cpp6
10 files changed, 49 insertions, 24 deletions
diff --git a/src/mongo/base/error_codes.yml b/src/mongo/base/error_codes.yml
index 45e5aff44a0..0283537e251 100644
--- a/src/mongo/base/error_codes.yml
+++ b/src/mongo/base/error_codes.yml
@@ -98,7 +98,7 @@ error_codes:
- {code: 62,name: OplogOperationUnsupported}
# This error code is obsolete as of version 6.0 and no new places where it is thrown should be
# added. Use StaleConfig.
- # TODO (SERVER-63327): Retire this code once 6.0 becomes LTS
+ # TODO (SERVER-64449): Retire this code once 6.0 becomes LTS
- {code: 63,name: OBSOLETE_StaleShardVersion,categories: [StaleShardVersionError,NeedRetargettingError]}
- {code: 64,name: WriteConcernFailed,categories: [WriteConcernError]}
- {code: 65,name: MultipleErrorsOccurred, extra: MultipleErrorsOccurredInfo}
diff --git a/src/mongo/db/ops/write_ops.cpp b/src/mongo/db/ops/write_ops.cpp
index 4c520a82015..54cef4d3d2a 100644
--- a/src/mongo/db/ops/write_ops.cpp
+++ b/src/mongo/db/ops/write_ops.cpp
@@ -299,7 +299,7 @@ WriteError WriteError::parse(const BSONObj& obj) {
// into StaleShardVersion and store the extra info of StaleConfig in a sub-field called
// "errInfo".
//
- // TODO (SERVER-63327): This special parsing should be removed in the stable version
+ // TODO (SERVER-64449): This special parsing should be removed in the stable version
// following the resolution of this ticket.
if (code == ErrorCodes::OBSOLETE_StaleShardVersion) {
return Status(ErrorCodes::StaleConfig,
@@ -323,7 +323,7 @@ BSONObj WriteError::serialize() const {
// StaleShardVersion and store the extra info of StaleConfig in a sub-field called "errInfo".
// This logic preserves this for backwards compatibility.
//
- // TODO (SERVER-63327): This special serialisation should be removed in the stable version
+ // TODO (SERVER-64449): This special serialisation should be removed in the stable version
// following the resolution of this ticket.
if (_status == ErrorCodes::StaleConfig &&
!feature_flags::gFeatureFlagNewWriteErrorExceptionFormat.isEnabled(
diff --git a/src/mongo/db/ops/write_ops.idl b/src/mongo/db/ops/write_ops.idl
index 4a5dda8aaf3..83f9b43359b 100644
--- a/src/mongo/db/ops/write_ops.idl
+++ b/src/mongo/db/ops/write_ops.idl
@@ -65,6 +65,7 @@ types:
serializer: "::mongo::write_ops::opTimeSerializerWithTermCheck"
deserializer: "::mongo::write_ops::opTimeParser"
+ # TODO (SERVER-64449): Use IDL directly instead of this custom parser/serialiser
write_error:
bson_serialization_type: object
description: "Structure used to report a single error entry resulting from a batch write
diff --git a/src/mongo/db/ops/write_ops_parsers.h b/src/mongo/db/ops/write_ops_parsers.h
index 8a012d19eeb..5cb248a7b49 100644
--- a/src/mongo/db/ops/write_ops_parsers.h
+++ b/src/mongo/db/ops/write_ops_parsers.h
@@ -210,7 +210,7 @@ private:
* their extraInfo in a field called errInfo, which is not consistent with how Status(es) are
* serialised and parsed.
*
- * TODO (SERVER-63327): The purpose of this class is to unify that reporting in subsequent versions
+ * TODO (SERVER-64449): The purpose of this class is to unify that reporting in subsequent versions
* after which it can become a proper IDL type.
*/
class WriteError {
diff --git a/src/mongo/s/chunk_version.cpp b/src/mongo/s/chunk_version.cpp
index 380d9834723..c2d757c8c39 100644
--- a/src/mongo/s/chunk_version.cpp
+++ b/src/mongo/s/chunk_version.cpp
@@ -210,22 +210,36 @@ void ChunkVersion::serializeToPositionalWronlyEcondedOr60AsBSON(StringData field
}
void ChunkVersion::serializeToBSON(StringData field, BSONObjBuilder* builder) const {
- BSONArrayBuilder arr(builder->subarrayStart(field));
- arr.appendTimestamp(_combined);
- arr.append(_epoch);
- arr.append(_timestamp);
+ if (feature_flags::gFeatureFlagNewPersistedChunkVersionFormat.isEnabled(
+ serverGlobalParams.featureCompatibility)) {
+ ChunkVersion60Format chunkVersion(
+ _timestamp, _epoch, Timestamp(majorVersion(), minorVersion()));
+ builder->append(field, chunkVersion.toBSON());
+ } else {
+ BSONArrayBuilder arr(builder->subarrayStart(field));
+ arr.appendTimestamp(_combined);
+ arr.append(_epoch);
+ arr.append(_timestamp);
+ }
}
void ChunkVersion::serializeToPositionalFormatWronglyEncodedAsBSON(StringData field,
BSONObjBuilder* builder) const {
- BSONObjBuilder subObjBuilder(builder->subobjStart(field));
- subObjBuilder.appendElements([&] {
- BSONArrayBuilder arr;
- arr.appendTimestamp(_combined);
- arr.append(_epoch);
- arr.append(_timestamp);
- return arr.obj();
- }());
+ if (feature_flags::gFeatureFlagNewPersistedChunkVersionFormat.isEnabled(
+ serverGlobalParams.featureCompatibility)) {
+ ChunkVersion60Format chunkVersion(
+ _timestamp, _epoch, Timestamp(majorVersion(), minorVersion()));
+ builder->append(field, chunkVersion.toBSON());
+ } else {
+ BSONObjBuilder subObjBuilder(builder->subobjStart(field));
+ subObjBuilder.appendElements([&] {
+ BSONArrayBuilder arr;
+ arr.appendTimestamp(_combined);
+ arr.append(_epoch);
+ arr.append(_timestamp);
+ return arr.obj();
+ }());
+ }
}
void ChunkVersion::appendLegacyWithField(BSONObjBuilder* out, StringData field) const {
diff --git a/src/mongo/s/chunk_version.h b/src/mongo/s/chunk_version.h
index ecc26431496..e96cf923160 100644
--- a/src/mongo/s/chunk_version.h
+++ b/src/mongo/s/chunk_version.h
@@ -45,6 +45,7 @@ namespace mongo {
* 3. (n, 0), n > 0 - invalid configuration.
* 4. (n, m), n > 0, m > 0 - normal sharded collection version.
*
+ * TODO (SERVER-65530): Get rid of all the legacy format parsers/serialisers
*/
struct ChunkVersion {
public:
@@ -201,7 +202,7 @@ public:
* Serializes the version held by this object to 'out' in the form:
* {..., <field>: {0:<combined major/minor, 1: <epoch>, 2: <Timestamp>}}
* or
- * { ..., <field> : {t: <Timestamp>, e: <OID>, v: <major/minor>}}.
+ * { ..., <field> : {t: <Timestamp>, e: <OID>, v: <major/minor> }}.
*
* Depending on the FCV version
*/
@@ -211,6 +212,10 @@ public:
/**
* Serializes the version held by this object to 'out' in the form:
* { ..., <field>: [ <combined major/minor>, <OID epoch>, <Timestamp> ], ... }.
+ * or
+ * { ..., <field> : {t: <Timestamp>, e: <OID>, v: <major/minor> }}.
+ *
+ * Depending on the FCV version
*/
void serializeToBSON(StringData fieldName, BSONObjBuilder* builder) const;
void serializeToPositionalFormatWronglyEncodedAsBSON(StringData fieldName,
diff --git a/src/mongo/s/chunk_version.idl b/src/mongo/s/chunk_version.idl
index 1c8d388a9c0..90bd596056f 100644
--- a/src/mongo/s/chunk_version.idl
+++ b/src/mongo/s/chunk_version.idl
@@ -38,9 +38,8 @@ imports:
structs:
ChunkVersion60Format:
- description: >
- New chunk version format to be parsed on 6.0 binaries but only
- generated on 6.1 binaries. DO NOT USE.
+ description: New chunk version format with is parsed by 6.0 binaries but only generated
+ starting with the 6.0 binaries when the FCV is 6.0.
strict: false
fields:
t:
@@ -57,8 +56,9 @@ structs:
cpp_name: Version
types:
- # The canonical serialisation format for ChunkVersions, which is written as:
- # [ <major/minor>, <epoch>, <timestamp> ]
+ # The canonical serialisation format for ChunkVersions
+ #
+ # TODO (SERVER-65530): Use IDL directly instead of this custom parser/serialiser
ChunkVersion:
bson_serialization_type: any
description: An object representing a chunk version for a collection.
diff --git a/src/mongo/s/write_ops/batch_write_exec.cpp b/src/mongo/s/write_ops/batch_write_exec.cpp
index b61b8e01dbd..45b89579dbb 100644
--- a/src/mongo/s/write_ops/batch_write_exec.cpp
+++ b/src/mongo/s/write_ops/batch_write_exec.cpp
@@ -280,6 +280,7 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
if (responseStatus.isOK()) {
TrackedErrors trackedErrors;
trackedErrors.startTracking(ErrorCodes::StaleConfig);
+ // TODO (SERVER-64449): Get rid of this exception
trackedErrors.startTracking(ErrorCodes::OBSOLETE_StaleShardVersion);
trackedErrors.startTracking(ErrorCodes::StaleDbVersion);
trackedErrors.startTracking(ErrorCodes::TenantMigrationAborted);
@@ -320,6 +321,7 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
// Note if anything was stale
auto staleConfigErrors = trackedErrors.getErrors(ErrorCodes::StaleConfig);
{
+ // TODO (SERVER-64449): Get rid of this exception
const auto& staleShardVersionErrors =
trackedErrors.getErrors(ErrorCodes::OBSOLETE_StaleShardVersion);
staleConfigErrors.insert(staleConfigErrors.begin(),
diff --git a/src/mongo/s/write_ops/batched_command_response_test.cpp b/src/mongo/s/write_ops/batched_command_response_test.cpp
index 8e3a7157f6c..f17637ade04 100644
--- a/src/mongo/s/write_ops/batched_command_response_test.cpp
+++ b/src/mongo/s/write_ops/batched_command_response_test.cpp
@@ -67,6 +67,7 @@ TEST(BatchedCommandResponseTest, Basic) {
ASSERT_BSONOBJ_EQ(origResponseObj, genResponseObj);
}
+// TODO (SERVER-64449): Get rid of this entire test case
TEST(BatchedCommandResponseTest, StaleErrorAsStaleShardVersionCompatibility) {
OID epoch = OID::gen();
diff --git a/src/mongo/s/write_ops/write_op.cpp b/src/mongo/s/write_ops/write_op.cpp
index c14af8181bc..236c7efbc94 100644
--- a/src/mongo/s/write_ops/write_op.cpp
+++ b/src/mongo/s/write_ops/write_op.cpp
@@ -36,8 +36,10 @@ namespace mongo {
namespace {
bool isRetryErrCode(int errCode) {
- return errCode == ErrorCodes::OBSOLETE_StaleShardVersion ||
- errCode == ErrorCodes::StaleConfig || errCode == ErrorCodes::StaleDbVersion ||
+ return
+ // TODO (SERVER-64449): Get rid of this exception
+ errCode == ErrorCodes::OBSOLETE_StaleShardVersion || errCode == ErrorCodes::StaleConfig ||
+ errCode == ErrorCodes::StaleDbVersion ||
errCode == ErrorCodes::ShardCannotRefreshDueToLocksHeld ||
errCode == ErrorCodes::TenantMigrationAborted;
}