Skip to content

Commit 588e0a6

Browse files
authored
GODRIVER-2006 Use 'hello' command for monitoring if supported (#714)
1 parent 9397df1 commit 588e0a6

File tree

399 files changed

+6206
-1827
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

399 files changed

+6206
-1827
lines changed

data/server-discovery-and-monitoring/README.rst

Lines changed: 365 additions & 24 deletions
Large diffs are not rendered by default.

data/server-discovery-and-monitoring/errors/error_handling_handshake.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

data/server-discovery-and-monitoring/errors/error_handling_handshake.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ phases:
55
responses:
66
- - a:27017
77
- ok: 1
8-
ismaster: true
8+
helloOk: true
9+
isWritablePrimary: true
910
hosts:
1011
- a:27017
1112
setName: rs
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import itertools
2+
import os
3+
import subprocess
4+
import sys
5+
6+
# Require Python 3.7+ for ordered dictionaries so that the order of the
7+
# generated tests remain the same.
8+
if sys.version_info[:2] < (3, 7):
9+
print('ERROR: This script requires Python >= 3.7, not:')
10+
print(sys.version)
11+
print('Usage: python3 %s' % (sys.argv[0]))
12+
exit(1)
13+
14+
15+
dirname = os.path.dirname
16+
DIR = dirname(os.path.realpath(__file__))
17+
SOURCE = dirname(dirname(dirname(DIR)))
18+
19+
20+
def template(filename):
21+
fullpath = os.path.join(DIR, filename)
22+
with open(fullpath, 'r') as f:
23+
return f.read()
24+
25+
26+
def write_test(filename, data):
27+
fullpath = os.path.join(DIR, filename + '.yml')
28+
with open(fullpath, 'w') as f:
29+
f.write(data)
30+
31+
print(f"Generated {fullpath}")
32+
33+
34+
# Maps from error_name to (error_code,)
35+
ERR_CODES = {
36+
'InterruptedAtShutdown': (11600,),
37+
'InterruptedDueToReplStateChange': (11602,),
38+
'NotPrimaryOrSecondary': (13436,),
39+
'PrimarySteppedDown': (189,),
40+
'ShutdownInProgress': (91,),
41+
'NotWritablePrimary': (10107,),
42+
'NotPrimaryNoSecondaryOk': (13435,),
43+
'LegacyNotPrimary': (10058,),
44+
}
45+
46+
47+
def create_stale_tests():
48+
tmp = template('stale-topologyVersion.yml.template')
49+
for error_name in ERR_CODES:
50+
test_name = f'stale-topologyVersion-{error_name}'
51+
error_code, = ERR_CODES[error_name]
52+
data = tmp.format(**locals())
53+
write_test(test_name, data)
54+
55+
TV_GREATER = '''
56+
topologyVersion:
57+
processId:
58+
"$oid": '000000000000000000000001'
59+
counter:
60+
"$numberLong": "2"'''
61+
TV_GREATER_FINAL = '''
62+
processId:
63+
"$oid": '000000000000000000000001'
64+
counter:
65+
"$numberLong": "2"'''
66+
TV_CHANGED = '''
67+
topologyVersion:
68+
processId:
69+
"$oid": '000000000000000000000002'
70+
counter:
71+
"$numberLong": "1"'''
72+
TV_CHANGED_FINAL = '''
73+
processId:
74+
"$oid": '000000000000000000000002'
75+
counter:
76+
"$numberLong": "1"'''
77+
78+
# Maps non-stale error description to:
79+
# (error_topology_version, final_topology_version)
80+
NON_STALE_CASES = {
81+
'topologyVersion missing': ('', ' null'),
82+
'topologyVersion greater': (TV_GREATER, TV_GREATER_FINAL),
83+
'topologyVersion proccessId changed': (TV_CHANGED, TV_CHANGED_FINAL),
84+
}
85+
86+
87+
def create_non_stale_tests():
88+
tmp = template('non-stale-topologyVersion.yml.template')
89+
for error_name, description in itertools.product(
90+
ERR_CODES, NON_STALE_CASES):
91+
test_name = f'non-stale-{description.replace(" ", "-")}-{error_name}'
92+
error_code, = ERR_CODES[error_name]
93+
error_topology_version, final_topology_version = NON_STALE_CASES[description]
94+
# On 4.2+, only ShutdownInProgress and InterruptedAtShutdown will
95+
# clear the pool.
96+
if error_name in ("ShutdownInProgress", "InterruptedAtShutdown"):
97+
final_pool_generation = 1
98+
else:
99+
final_pool_generation = 0
100+
101+
data = tmp.format(**locals())
102+
write_test(test_name, data)
103+
104+
105+
WHEN = ['beforeHandshakeCompletes', 'afterHandshakeCompletes']
106+
STALE_GENERATION_COMMAND_ERROR = '''
107+
type: command
108+
response:
109+
ok: 0
110+
errmsg: {error_name}
111+
code: {error_code}
112+
topologyVersion:
113+
processId:
114+
"$oid": '000000000000000000000001'
115+
counter:
116+
"$numberLong": "2"'''
117+
STALE_GENERATION_NETWORK_ERROR = '''
118+
type: {network_error_type}'''
119+
120+
121+
def create_stale_generation_tests():
122+
tmp = template('stale-generation.yml.template')
123+
# Stale command errors
124+
for error_name, when in itertools.product(ERR_CODES, WHEN):
125+
test_name = f'stale-generation-{when}-{error_name}'
126+
error_code, = ERR_CODES[error_name]
127+
stale_error = STALE_GENERATION_COMMAND_ERROR.format(**locals())
128+
data = tmp.format(**locals())
129+
write_test(test_name, data)
130+
# Stale network errors
131+
for network_error_type, when in itertools.product(
132+
['network', 'timeout'], WHEN):
133+
error_name = network_error_type
134+
test_name = f'stale-generation-{when}-{network_error_type}'
135+
stale_error = STALE_GENERATION_NETWORK_ERROR.format(**locals())
136+
data = tmp.format(**locals())
137+
write_test(test_name, data)
138+
139+
140+
def create_pre_42_tests():
141+
tmp = template('pre-42.yml.template')
142+
# All "not writable primary"/"node is recovering" clear the pool on <4.2
143+
for error_name in ERR_CODES:
144+
test_name = f'pre-42-{error_name}'
145+
error_code, = ERR_CODES[error_name]
146+
data = tmp.format(**locals())
147+
write_test(test_name, data)
148+
149+
150+
def create_post_42_tests():
151+
tmp = template('post-42.yml.template')
152+
for error_name in ERR_CODES:
153+
test_name = f'post-42-{error_name}'
154+
error_code, = ERR_CODES[error_name]
155+
# On 4.2+, only ShutdownInProgress and InterruptedAtShutdown will
156+
# clear the pool.
157+
if error_name in ("ShutdownInProgress", "InterruptedAtShutdown"):
158+
final_pool_generation = 1
159+
else:
160+
final_pool_generation = 0
161+
data = tmp.format(**locals())
162+
write_test(test_name, data)
163+
164+
165+
create_stale_tests()
166+
create_non_stale_tests()
167+
create_stale_generation_tests()
168+
create_pre_42_tests()
169+
create_post_42_tests()
170+
171+
print('Running make')
172+
subprocess.run(f'cd {SOURCE} && make', shell=True, check=True)

data/server-discovery-and-monitoring/errors/non-stale-network-error.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

data/server-discovery-and-monitoring/errors/non-stale-network-error.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ phases:
55
responses:
66
- - a:27017
77
- ok: 1
8-
ismaster: true
8+
helloOk: true
9+
isWritablePrimary: true
910
hosts:
1011
- a:27017
1112
setName: rs

data/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

data/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ phases:
55
responses:
66
- - a:27017
77
- ok: 1
8-
ismaster: true
8+
helloOk: true
9+
isWritablePrimary: true
910
hosts:
1011
- a:27017
1112
setName: rs

data/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

data/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ phases:
66
responses:
77
- - a:27017
88
- ok: 1
9-
ismaster: true
9+
helloOk: true
10+
isWritablePrimary: true
1011
hosts:
1112
- a:27017
1213
setName: rs

data/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

data/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ phases:
66
responses:
77
- - a:27017
88
- ok: 1
9-
ismaster: true
9+
helloOk: true
10+
isWritablePrimary: true
1011
hosts:
1112
- a:27017
1213
setName: rs

0 commit comments

Comments
 (0)