Skip to content

Commit 6b3563c

Browse files
authored
Merge pull request #85 from kbase/dev-add_retryWirtes
add retryWrites
2 parents 1484e37 + e2c67ae commit 6b3563c

File tree

8 files changed

+46
-4
lines changed

8 files changed

+46
-4
lines changed

RELEASE_NOTES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
KBase Feeds Service
22

3+
### Version 1.0.3
4+
* The MongoDB clients have been updated to the most recent version.
5+
* Added the mongo-retrywrites configuration setting in deployment.cfg.templ, defaulting to false.
6+
* Migrated from Travis CI to GitHub Actions workflows.
7+
* Updated Python version to 3.7.13.
8+
39
### Version 1.0.2
410
- Add a cache for bad tokens so they aren't looked up over and over. Maxes out at 10000, then throws out the oldest bad token.
511

deployment/conf/.templates/deploy.cfg.templ

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ db-host = {{ default .Env.db_host "ci-mongo" }}
1111
db-port = {{ default .Env.db_port "27017" }}
1212
db-user = {{ default .Env.db_user "feedsserv" }}
1313
db-pw = {{ default .Env.db_pw "fake_password" }}
14+
db-retrywrites={{ default .Env.db_retrywrites "false" }}
1415

1516
# admins are allowed to use their auth tokens to create global notifications.
1617
# examples would be notices about KBase downtime or events.

deployment/deploy.cfg.example

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ db-port=6379
1212
db-user=
1313
db-pw=
1414

15+
# Whether to enable ('true') the MongoDB retryWrites parameter or not (anything other than 'true').
16+
# See https://www.mongodb.com/docs/manual/core/retryable-writes/
17+
db-retrywrites=false
18+
1519
# Service urls
1620
auth-url=https://ci.kbase.us/services/auth
1721
workspace-url=https://ci.kbase.us/services/ws

feeds/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
KEY_DB_PW = "db-pw"
1616
KEY_DB_NAME = "db-name"
1717
KEY_DB_ENGINE = "db-engine"
18+
KEY_DB_RETRYWRITES = "db-retrywrites"
1819
KEY_GLOBAL_FEED = "global-feed"
1920
KEY_DEBUG = "debug"
2021
KEY_LIFESPAN = "lifespan"
@@ -60,6 +61,7 @@ def __init__(self):
6061
self.db_user = self._get_line(cfg, KEY_DB_USER, required=False)
6162
self.db_pw = self._get_line(cfg, KEY_DB_PW, required=False)
6263
self.db_name = self._get_line(cfg, KEY_DB_NAME, required=False)
64+
self.db_retrywrites = self._get_line(cfg, KEY_DB_RETRYWRITES, required=False) == "true"
6365
self.global_feed = self._get_line(cfg, KEY_GLOBAL_FEED)
6466
self.global_feed_type = "user" # doesn't matter, need a valid Entity type...
6567
try:

feeds/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
log_error
3434
)
3535

36-
VERSION = "1.0.2"
36+
VERSION = "1.0.3"
3737

3838
try:
3939
from feeds import gitcommit

feeds/storage/mongodb/connection.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ def __init__(self):
9999
port=self.cfg.db_port,
100100
username=self.cfg.db_user,
101101
password=self.cfg.db_pw,
102+
retryWrites=self.cfg.db_retrywrites,
102103
authSource=self.cfg.db_name
103-
)
104+
)
104105
self.db = self.conn[self.cfg.db_name]
105106
self._setup_indexes()
106107
self._setup_schema()

test/test.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ service-narrative=narrativeservice
2020
service-jobs=jobsservice
2121
service-kbase=kbase
2222

23+
# Whether to enable ('true') the MongoDB retryWrites parameter or not (anything other than 'true').
24+
# See https://www.mongodb.com/docs/manual/core/retryable-writes/
25+
db-retrywrites=false
26+
2327
[test]
2428
mongo-exe=/usr/local/bin/mongod
2529
test-temp-dir=./test-temp-dir

test/test_config.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'db-engine=redis',
1616
'db-host=foo',
1717
'db-port=5',
18+
'db-retrywrites=false',
1819
'auth-url=baz',
1920
'njs-url=njs',
2021
'workspace-url=ws',
@@ -69,7 +70,7 @@ def test_config_bad_port(dummy_config, dummy_auth_token, bad_val):
6970
@pytest.mark.parametrize("bad_val", [("foo"), (-100), (0), (0.5)])
7071
def test_config_bad_lifespan(dummy_config, dummy_auth_token, bad_val):
7172
cfg_text = GOOD_CONFIG.copy()
72-
cfg_text[10] = "lifespan=wrong"
73+
cfg_text[11] = "lifespan=wrong"
7374
cfg_path = dummy_config(cfg_text)
7475
feeds_config_backup = os.environ.get('FEEDS_CONFIG')
7576
os.environ['FEEDS_CONFIG'] = cfg_path
@@ -84,7 +85,7 @@ def test_config_bad_lifespan(dummy_config, dummy_auth_token, bad_val):
8485
@pytest.mark.parametrize("bad_val", [("foo"), (-100), (0), (0.5)])
8586
def test_config_bad_note_count(dummy_config, dummy_auth_token, bad_val):
8687
cfg_text = GOOD_CONFIG.copy()
87-
cfg_text[11] = "default-note-count={}".format(bad_val)
88+
cfg_text[12] = "default-note-count={}".format(bad_val)
8889
cfg_path = dummy_config(cfg_text)
8990
feeds_config_backup = os.environ.get('FEEDS_CONFIG')
9091
os.environ['FEEDS_CONFIG'] = cfg_path
@@ -221,6 +222,29 @@ def test_get_config(dummy_config, dummy_auth_token):
221222
cfg = config.get_config()
222223
assert cfg.db_host == 'foo'
223224
assert cfg.db_port == 5
225+
assert cfg.db_retrywrites == False
226+
assert cfg.auth_url == 'baz'
227+
assert cfg.auth_token == FAKE_AUTH_TOKEN
228+
del os.environ['FEEDS_CONFIG']
229+
if path_backup is not None:
230+
os.environ['FEEDS_CONFIG'] = path_backup
231+
config.__config = None
232+
233+
234+
def test_config_retryWrites_is_true(dummy_config, dummy_auth_token):
235+
# set db-retrywrites=true
236+
cfg_text = GOOD_CONFIG.copy()
237+
cfg_text[4] = 'db-retrywrites=true'
238+
cfg_path = dummy_config(cfg_text)
239+
240+
path_backup = os.environ.get('FEEDS_CONFIG')
241+
os.environ['FEEDS_CONFIG'] = cfg_path
242+
config.__config = None
243+
244+
cfg = config.get_config()
245+
assert cfg.db_host == 'foo'
246+
assert cfg.db_port == 5
247+
assert cfg.db_retrywrites == True
224248
assert cfg.auth_url == 'baz'
225249
assert cfg.auth_token == FAKE_AUTH_TOKEN
226250
del os.environ['FEEDS_CONFIG']

0 commit comments

Comments
 (0)