Skip to content

Commit

Permalink
Merge pull request #83 from kbase/dev-mongo7_upgrade
Browse files Browse the repository at this point in the history
Mongo7 upgrade
  • Loading branch information
Xiangs18 authored Nov 13, 2024
2 parents 2b83deb + 389ca25 commit 1484e37
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
include:
- python: '3.7.13'
mongo: 'mongodb-linux-x86_64-3.6.2'
- python: '3.7.13'
mongo: 'mongodb-linux-x86_64-ubuntu2204-7.0.4'

steps:
- name: Check out GitHub repo
Expand Down
2 changes: 1 addition & 1 deletion feeds/storage/mongodb/timeline_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_unseen_count(self) -> int:
"unseen": self._user_doc(),
"expires": {"$gt": now}
}
return coll.find(query).count()
return coll.count_documents(query)

def _user_doc(self) -> Dict[str, str]:
return {
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ requests==2.20.0
gunicorn==19.9.0
gevent==1.3.7
cachetools==2.1.0
pymongo==3.7.2
pymongo==4.7.2
redis==2.10.6
flask-cors==3.0.6
46 changes: 36 additions & 10 deletions test/mongo_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import semver
import test.util as test_util

# semver parser
sver = semver.VersionInfo.parse


class MongoController:
"""
Expand Down Expand Up @@ -50,27 +53,50 @@ def __init__(self, mongoexe: Path, root_temp_dir: Path, use_wired_tiger: bool=Fa
os.makedirs(data_dir)

self.port = test_util.find_free_port()
mongodb_ver = self.get_mongodb_version(mongoexe)

command = [str(mongoexe), '--port', str(self.port), '--dbpath', str(data_dir)]

if sver(mongodb_ver) < sver('6.1.0'):
command.extend(['--nojournal'])

command = [str(mongoexe), '--port', str(self.port), '--dbpath', str(data_dir),
'--nojournal']
if use_wired_tiger:
command.extend(['--storageEngine', 'wiredTiger'])

self._outfile = open(self.temp_dir.joinpath('mongo.log'), 'w')

self._proc = subprocess.Popen(command, stdout=self._outfile, stderr=subprocess.STDOUT)
time.sleep(1) # wait for server to start up
self.client = MongoClient('localhost', self.port)
# check that the server is up. See
# https://api.mongodb.com/python/3.7.0/api/pymongo/mongo_client.html
# #pymongo.mongo_client.MongoClient
self.client.admin.command('ismaster')

try:
self.client: MongoClient = MongoClient('localhost', self.port)
# This line will raise an exception if the server is down
server_info = self.client.server_info()
except Exception as e:
raise ValueError("MongoDB server is down") from e

# get some info about the db
self.db_version = self.client.server_info()['version']
self.db_version = server_info['version']
self.index_version = 2 if (semver.compare(self.db_version, '3.4.0') >= 0) else 1
self.includes_system_indexes = (semver.compare(self.db_version, '3.2.0') < 0
and not use_wired_tiger)
self.includes_system_indexes = (
semver.compare(self.db_version, '3.2.0') < 0 and not use_wired_tiger
)

def get_mongodb_version(self, mongoexe: Path) -> str:
try:
process = subprocess.Popen(
[str(mongoexe), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
stdout, stderr = process.communicate()

if process.returncode == 0:
version_line = stdout.decode().split('\n')[0]
mongodb_version = version_line.split()[2][1:]
return mongodb_version.strip()
else:
raise ValueError(f"Error: {stderr.decode()}")
except Exception as e:
raise ValueError("Failed to get MongoDB version") from e

def destroy(self, delete_temp_files: bool) -> None:
"""
Expand Down

0 comments on commit 1484e37

Please sign in to comment.