Skip to content

Commit c2680d2

Browse files
committed
Track servers by host:port instead of serverConnectionId
The server's connection ID is unique within the context of a single server and is only reported by MongoDB 4.2+. It should not be used to uniquely identify a server. This reverts recent changes from 50d1db7.
1 parent 50d1db7 commit c2680d2

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

tests/SpecTests/RetryableReads/Prose2_RetryOnMongosTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testRetryOnDifferentMongos(): void
6464

6565
// Step 4: Enable failed command event monitoring for client
6666
$subscriber = new class implements CommandSubscriber {
67-
/** @var int[] */
67+
/** @var string[] */
6868
public array $commandFailedServers = [];
6969

7070
public function commandStarted(CommandStartedEvent $event): void
@@ -77,7 +77,7 @@ public function commandSucceeded(CommandSucceededEvent $event): void
7777

7878
public function commandFailed(CommandFailedEvent $event): void
7979
{
80-
$this->commandFailedServers[] = $event->getServerConnectionId();
80+
$this->commandFailedServers[] = $event->getHost() . ':' . $event->getPort();
8181
}
8282
};
8383

@@ -130,21 +130,21 @@ public function testRetryOnSameMongos(): void
130130

131131
// Step 4: Enable succeeded and failed command event monitoring
132132
$subscriber = new class implements CommandSubscriber {
133-
public ?int $commandSucceededServer = null;
134-
public ?int $commandFailedServer = null;
133+
public ?string $commandSucceededServer = null;
134+
public ?string $commandFailedServer = null;
135135

136136
public function commandStarted(CommandStartedEvent $event): void
137137
{
138138
}
139139

140140
public function commandSucceeded(CommandSucceededEvent $event): void
141141
{
142-
$this->commandSucceededServer = $event->getServerConnectionId();
142+
$this->commandSucceededServer = $event->getHost() . ':' . $event->getPort();
143143
}
144144

145145
public function commandFailed(CommandFailedEvent $event): void
146146
{
147-
$this->commandFailedServer = $event->getServerConnectionId();
147+
$this->commandFailedServer = $event->getHost() . ':' . $event->getPort();
148148
}
149149
};
150150

tests/SpecTests/RetryableWrites/Prose4_RetryOnDifferentMongosTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testRetryOnDifferentMongos(): void
6767

6868
// Step 4: Enable failed command event monitoring for client
6969
$subscriber = new class implements CommandSubscriber {
70-
/** @var int[] */
70+
/** @var string[] */
7171
public array $commandFailedServers = [];
7272

7373
public function commandStarted(CommandStartedEvent $event): void
@@ -80,7 +80,7 @@ public function commandSucceeded(CommandSucceededEvent $event): void
8080

8181
public function commandFailed(CommandFailedEvent $event): void
8282
{
83-
$this->commandFailedServers[] = $event->getServerConnectionId();
83+
$this->commandFailedServers[] = $event->getHost() . ':' . $event->getPort();
8484
}
8585
};
8686

tests/SpecTests/RetryableWrites/Prose5_RetryOnSameMongosTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ public function testRetryOnSameMongos(): void
4949

5050
// Step 4: Enable succeeded and failed command event monitoring
5151
$subscriber = new class implements CommandSubscriber {
52-
public ?int $commandSucceededServer = null;
53-
public ?int $commandFailedServer = null;
52+
public ?string $commandSucceededServer = null;
53+
public ?string $commandFailedServer = null;
5454

5555
public function commandStarted(CommandStartedEvent $event): void
5656
{
5757
}
5858

5959
public function commandSucceeded(CommandSucceededEvent $event): void
6060
{
61-
$this->commandSucceededServer = $event->getServerConnectionId();
61+
$this->commandSucceededServer = $event->getHost() . ':' . $event->getPort();
6262
}
6363

6464
public function commandFailed(CommandFailedEvent $event): void
6565
{
66-
$this->commandFailedServer = $event->getServerConnectionId();
66+
$this->commandFailedServer = $event->getHost() . ':' . $event->getPort();
6767
}
6868
};
6969

tests/UnifiedSpecTests/EventCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private function handleCommandMonitoringEvent($event): void
119119
'name' => self::getEventName($event),
120120
'observedAt' => microtime(true),
121121
'commandName' => $event->getCommandName(),
122-
'connectionId' => $event->getServerConnectionId(),
122+
'connectionId' => $event->getHost() . ':' . $event->getPort(),
123123
'requestId' => $event->getRequestId(),
124124
'operationId' => $event->getOperationId(),
125125
];

0 commit comments

Comments
 (0)