Esempio n. 1
0
# 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)

Esempio n. 2
0
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."""
        self.calls.append('abort')
    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."""
        self.calls.append('abort')
Esempio n. 4
0
    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)
Esempio n. 5
0
#
# 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)