# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # For further info, check http://launchpad.net/filesync-server """Manage database connections and stores to the storage database.""" from backends.db.store import get_filesync_store from backends.db.dbtransaction import ( get_storm_commit, get_storm_readonly, storage_tm, ) from backends.db.dbtransaction import retryable_transaction # NOQA from config import config fsync_commit = get_storm_commit(storage_tm) fsync_readonly = get_storm_readonly(storage_tm) fsync_readonly_slave = get_storm_readonly(storage_tm, use_ro_store=True) class InvalidShardId(Exception): """Raised when an invalid shard ID is passed""" def get_shard_store(shard_id): """Return the Storm.Store for the given shard_id""" try: return get_filesync_store(shard_id) except KeyError: raise InvalidShardId("Invalid Shard ID: %s" % shard_id)
from zope.interface.verify import verifyObject from ubuntuone.devtools.handlers import MementoHandler from backends.testing import testcase from backends.db import errors from backends.db.store import get_store from backends.db.dbtransaction import ( _check_stores_and_invalidate, retryable_transaction, get_storm_commit, get_storm_readonly, RetryLimitReached, TransactionTimer, disable_timeout_tracer, enable_timeout_tracer, current_timeout_tracer, db_timeout, timer, StorageTimeoutTracer, on_timeout, storage_zstorm) storm_commit = get_storm_commit(transaction) storm_readonly = get_storm_readonly(transaction) storm_readonly_ro_store = get_storm_readonly(transaction, use_ro_store=True) class LoggingDataManager(object): """An IDataManager implementation that logs calls.""" implements(IDataManager) def __init__(self, transaction_manager): super(LoggingDataManager, self).__init__() self.transaction_manager = transaction_manager self.calls = [] def abort(self, txn): """See IDataManager."""
store_settings = settings[store_name] uri = get_postgres_uri(store_settings) return zstorm.get(store_name, default_uri=uri) def get_filesync_store(store_name): """get a store using the storage_tm.""" return get_store(store_name, zstorm=storage_zstorm) def get_user_store(): """Get the main store used for users and common dataobjects""" return get_filesync_store('storage') @contextlib.contextmanager def implicit_flushes_blocked_on(store): try: store.block_implicit_flushes() yield finally: store.unblock_implicit_flushes() # # The default decorators use the account_tm # account_commit = get_storm_commit(account_tm) account_readonly = get_storm_readonly(account_tm) account_readonly_slave = get_storm_readonly(account_tm, use_ro_store=True)
retryable_transaction, get_storm_commit, get_storm_readonly, RetryLimitReached, TransactionTimer, disable_timeout_tracer, enable_timeout_tracer, current_timeout_tracer, db_timeout, timer, StorageTimeoutTracer, on_timeout, storage_zstorm ) storm_commit = get_storm_commit(transaction) storm_readonly = get_storm_readonly(transaction) storm_readonly_ro_store = get_storm_readonly(transaction, use_ro_store=True) class LoggingDataManager(object): """An IDataManager implementation that logs calls.""" implements(IDataManager) def __init__(self, transaction_manager): super(LoggingDataManager, self).__init__() self.transaction_manager = transaction_manager self.calls = [] def abort(self, txn): """See IDataManager."""
def get_filesync_store(): """Get a store using the filesync_tm.""" store_name = 'filesync' # get the current transaction and see if it has the ro_store flag set txn = filesync_zstorm.transaction_manager.get() if getattr(txn, 'use_ro_store', False): # only use it if there is a config for it. ro_store_name = 'ro-%s' % store_name if ro_store_name in settings.DATABASES: store_name = ro_store_name uri = settings.STORM_STORES[store_name] return filesync_zstorm.get(store_name, default_uri=uri) @contextlib.contextmanager def implicit_flushes_blocked_on(store): try: store.block_implicit_flushes() yield finally: store.unblock_implicit_flushes() # # The default decorators use the filesync_tm # account_commit = get_storm_commit(filesync_tm) account_readonly = get_storm_readonly(filesync_tm) account_readonly_slave = get_storm_readonly(filesync_tm, use_ro_store=True)
# along with this program. If not, see <http://www.gnu.org/licenses/>. # # For further info, check http://launchpad.net/filesync-server """Manage database connections and stores to the storage database.""" from backends.db.store import get_filesync_store from backends.db.dbtransaction import ( get_storm_commit, get_storm_readonly, storage_tm, ) from backends.db.dbtransaction import retryable_transaction # NOQA from config import config fsync_commit = get_storm_commit(storage_tm) fsync_readonly = get_storm_readonly(storage_tm) fsync_readonly_slave = get_storm_readonly(storage_tm, use_ro_store=True) class InvalidShardId(Exception): """Raised when an invalid shard ID is passed""" def get_shard_store(shard_id): """Return the Storm.Store for the given shard_id""" try: return get_filesync_store(shard_id) except KeyError: raise InvalidShardId("Invalid Shard ID: %s" % shard_id)