Commit 6d7944fa by Calen Pennington Committed by John Eskew

Allow specification of ReadPreference via DOC_STORE_CONFIG.

Use a MongoReplicaSetClient for Split modulestore, but only
if replicaSet config is set.
parent b5c6eb78
...@@ -26,6 +26,10 @@ class MongoContentStore(ContentStore): ...@@ -26,6 +26,10 @@ class MongoContentStore(ContentStore):
:param collection: ignores but provided for consistency w/ other doc_store_config patterns :param collection: ignores but provided for consistency w/ other doc_store_config patterns
""" """
logging.debug('Using MongoDB for static content serving at host={0} port={1} db={2}'.format(host, port, db)) logging.debug('Using MongoDB for static content serving at host={0} port={1} db={2}'.format(host, port, db))
# Remove the replicaSet parameter.
kwargs.pop('replicaSet', None)
_db = pymongo.database.Database( _db = pymongo.database.Database(
pymongo.MongoClient( pymongo.MongoClient(
host=host, host=host,
......
...@@ -20,6 +20,8 @@ if not settings.configured: ...@@ -20,6 +20,8 @@ if not settings.configured:
from django.core.cache import get_cache, InvalidCacheBackendError from django.core.cache import get_cache, InvalidCacheBackendError
import django.dispatch import django.dispatch
import django.utils import django.utils
from pymongo import ReadPreference
from xmodule.contentstore.django import contentstore from xmodule.contentstore.django import contentstore
from xmodule.modulestore.draft_and_published import BranchSettingMixin from xmodule.modulestore.draft_and_published import BranchSettingMixin
from xmodule.modulestore.mixed import MixedModuleStore from xmodule.modulestore.mixed import MixedModuleStore
...@@ -156,6 +158,9 @@ def create_modulestore_instance( ...@@ -156,6 +158,9 @@ def create_modulestore_instance(
else: else:
xb_user_service = None xb_user_service = None
if 'read_preference' in doc_store_config:
doc_store_config['read_preference'] = getattr(ReadPreference, doc_store_config['read_preference'])
return class_( return class_(
contentstore=content_store, contentstore=content_store,
metadata_inheritance_cache_subsystem=metadata_inheritance_cache, metadata_inheritance_cache_subsystem=metadata_inheritance_cache,
......
...@@ -552,6 +552,9 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -552,6 +552,9 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
""" """
Create & open the connection, authenticate, and provide pointers to the collection Create & open the connection, authenticate, and provide pointers to the collection
""" """
# Remove the replicaSet parameter.
kwargs.pop('replicaSet', None)
self.database = MongoProxy( self.database = MongoProxy(
pymongo.database.Database( pymongo.database.Database(
pymongo.MongoClient( pymongo.MongoClient(
......
...@@ -81,16 +81,19 @@ class MongoConnection(object): ...@@ -81,16 +81,19 @@ class MongoConnection(object):
""" """
Create & open the connection, authenticate, and provide pointers to the collections Create & open the connection, authenticate, and provide pointers to the collections
""" """
if kwargs.get('replicaSet') is None:
kwargs.pop('replicaSet', None)
mongo_class = pymongo.MongoClient
else:
mongo_class = pymongo.MongoReplicaSetClient
_client = mongo_class(
host=host,
port=port,
tz_aware=tz_aware,
**kwargs
)
self.database = MongoProxy( self.database = MongoProxy(
pymongo.database.Database( pymongo.database.Database(_client, db),
pymongo.MongoClient(
host=host,
port=port,
tz_aware=tz_aware,
**kwargs
),
db
),
wait_time=retry_wait_time wait_time=retry_wait_time
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment