Skip to content

Commit

Permalink
test: add server version filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Sep 28, 2022
1 parent 3bb7c70 commit b0377f4
Show file tree
Hide file tree
Showing 265 changed files with 10,372 additions and 565 deletions.
66 changes: 48 additions & 18 deletions src/sdam/topology_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,26 +373,56 @@ function updateRsFromPrimary(
return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
}

const electionIdComparison = compareObjectId(maxElectionId, serverDescription.electionId);
const maxElectionIdIsEqual = electionIdComparison === 0;
const maxElectionIdIsLess = electionIdComparison === -1;
const maxSetVersionIsLessOrEqual = (maxSetVersion ?? -1) <= (serverDescription.setVersion ?? -1);

if (maxElectionIdIsLess || (maxElectionIdIsEqual && maxSetVersionIsLessOrEqual)) {
// The reported electionId was greater
// or the electionId was equal and reported setVersion was greater
// Always update both values, they are a tuple
maxElectionId = serverDescription.electionId;
maxSetVersion = serverDescription.setVersion;
if (serverDescription.maxWireVersion >= 17) {
const electionIdComparison = compareObjectId(maxElectionId, serverDescription.electionId);
const maxElectionIdIsEqual = electionIdComparison === 0;
const maxElectionIdIsLess = electionIdComparison === -1;
const maxSetVersionIsLessOrEqual =
(maxSetVersion ?? -1) <= (serverDescription.setVersion ?? -1);

if (maxElectionIdIsLess || (maxElectionIdIsEqual && maxSetVersionIsLessOrEqual)) {
// The reported electionId was greater
// or the electionId was equal and reported setVersion was greater
// Always update both values, they are a tuple
maxElectionId = serverDescription.electionId;
maxSetVersion = serverDescription.setVersion;
} else {
// Stale primary
// replace serverDescription with a default ServerDescription of type "Unknown"
serverDescriptions.set(
serverDescription.address,
new ServerDescription(serverDescription.address)
);

return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
}
} else {
// Stale primary
// replace serverDescription with a default ServerDescription of type "Unknown"
serverDescriptions.set(
serverDescription.address,
new ServerDescription(serverDescription.address)
);
const electionId = serverDescription.electionId ? serverDescription.electionId : null;
if (serverDescription.setVersion && electionId) {
if (maxSetVersion && maxElectionId) {
if (
maxSetVersion > serverDescription.setVersion ||
compareObjectId(maxElectionId, electionId) > 0
) {
// this primary is stale, we must remove it
serverDescriptions.set(
serverDescription.address,
new ServerDescription(serverDescription.address)
);

return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
}
}

return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
maxElectionId = serverDescription.electionId;
}

if (
serverDescription.setVersion != null &&
(maxSetVersion == null || serverDescription.setVersion > maxSetVersion)
) {
maxSetVersion = serverDescription.setVersion;
}
}

// We've heard from the primary. Is it the same primary as before?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"description": "Replica set member with large maxWireVersion",
"uri": "mongodb://a,b/?replicaSet=rs",
"phases": [
{
"responses": [
[
"a:27017",
{
"ok": 1,
"helloOk": true,
"isWritablePrimary": true,
"setName": "rs",
"hosts": [
"a:27017",
"b:27017"
],
"minWireVersion": 0,
"maxWireVersion": 6
}
],
[
"b:27017",
{
"ok": 1,
"helloOk": true,
"isWritablePrimary": false,
"secondary": true,
"setName": "rs",
"hosts": [
"a:27017",
"b:27017"
],
"minWireVersion": 0,
"maxWireVersion": 1000
}
]
],
"outcome": {
"servers": {
"a:27017": {
"type": "RSPrimary",
"setName": "rs"
},
"b:27017": {
"type": "RSSecondary",
"setName": "rs"
}
},
"topologyType": "ReplicaSetWithPrimary",
"setName": "rs",
"logicalSessionTimeoutMinutes": null,
"compatible": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
description: "Replica set member with large maxWireVersion"

uri: "mongodb://a,b/?replicaSet=rs"

phases: [
{
responses: [
["a:27017", {
ok: 1,
helloOk: true,
isWritablePrimary: true,
setName: "rs",
hosts: ["a:27017", "b:27017"],
minWireVersion: 0,
maxWireVersion: 6
}],
["b:27017", {
ok: 1,
helloOk: true,
isWritablePrimary: false,
secondary: true,
setName: "rs",
hosts: ["a:27017", "b:27017"],
minWireVersion: 0,
maxWireVersion: 1000
}]
],
outcome: {
servers: {
"a:27017": {
type: "RSPrimary",
setName: "rs"
},
"b:27017": {
type: "RSSecondary",
setName: "rs"
}
},
topologyType: "ReplicaSetWithPrimary",
setName: "rs",
logicalSessionTimeoutMinutes: null,
compatible: true
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"description": "Replica set member and an unknown server",
"uri": "mongodb://a,b/?replicaSet=rs",
"phases": [
{
"responses": [
[
"a:27017",
{
"ok": 1,
"helloOk": true,
"isWritablePrimary": true,
"setName": "rs",
"hosts": [
"a:27017",
"b:27017"
],
"minWireVersion": 0,
"maxWireVersion": 6
}
]
],
"outcome": {
"servers": {
"a:27017": {
"type": "RSPrimary",
"setName": "rs"
},
"b:27017": {
"type": "Unknown"
}
},
"topologyType": "ReplicaSetWithPrimary",
"setName": "rs",
"logicalSessionTimeoutMinutes": null,
"compatible": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
description: "Replica set member and an unknown server"

uri: "mongodb://a,b/?replicaSet=rs"

phases: [
{
responses: [
["a:27017", {
ok: 1,
helloOk: true,
isWritablePrimary: true,
setName: "rs",
hosts: ["a:27017", "b:27017"],
minWireVersion: 0,
maxWireVersion: 6
}],
],
outcome: {
servers: {
"a:27017": {
type: "RSPrimary",
setName: "rs"
},
"b:27017": {
type: "Unknown",
}
},
topologyType: "ReplicaSetWithPrimary",
setName: "rs",
logicalSessionTimeoutMinutes: null,
compatible: true
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"description": "Discover arbiters with directConnection URI option",
"uri": "mongodb://a/?directConnection=false",
"phases": [
{
"responses": [
[
"a:27017",
{
"ok": 1,
"helloOk": true,
"isWritablePrimary": true,
"hosts": [
"a:27017"
],
"arbiters": [
"b:27017"
],
"setName": "rs",
"minWireVersion": 0,
"maxWireVersion": 6
}
]
],
"outcome": {
"servers": {
"a:27017": {
"type": "RSPrimary",
"setName": "rs"
},
"b:27017": {
"type": "Unknown",
"setName": null
}
},
"topologyType": "ReplicaSetWithPrimary",
"logicalSessionTimeoutMinutes": null,
"setName": "rs"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
description: "Discover arbiters with directConnection URI option"

uri: "mongodb://a/?directConnection=false"

phases: [

{
responses: [

["a:27017", {

ok: 1,
helloOk: true,
isWritablePrimary: true,
hosts: ["a:27017"],
arbiters: ["b:27017"],
setName: "rs",
minWireVersion: 0,
maxWireVersion: 6
}]
],

outcome: {

servers: {

"a:27017": {

type: "RSPrimary",
setName: "rs"
},

"b:27017": {

type: "Unknown",
setName:
}
},
topologyType: "ReplicaSetWithPrimary",
logicalSessionTimeoutMinutes: null,
setName: "rs"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"description": "Discover arbiters with replicaSet URI option",
"uri": "mongodb://a/?replicaSet=rs",
"phases": [
{
"responses": [
[
"a:27017",
{
"ok": 1,
"helloOk": true,
"isWritablePrimary": true,
"hosts": [
"a:27017"
],
"arbiters": [
"b:27017"
],
"setName": "rs",
"minWireVersion": 0,
"maxWireVersion": 6
}
]
],
"outcome": {
"servers": {
"a:27017": {
"type": "RSPrimary",
"setName": "rs"
},
"b:27017": {
"type": "Unknown",
"setName": null
}
},
"topologyType": "ReplicaSetWithPrimary",
"logicalSessionTimeoutMinutes": null,
"setName": "rs"
}
}
]
}
Loading

0 comments on commit b0377f4

Please sign in to comment.