~unity-2d-team/unity-2d/Shell-MultiMonitor

8 by William Grant
A little bit of server.
1
# Copyright (c) 2011 Canonical Ltd
2
#
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU Affero General Public License for more details.
12
#
13
# You should have received a copy of the GNU Affero General Public
14
# License along with this program. If not, see
15
# <http://www.gnu.org/licenses/>.
16
17
"""Things to ease working with cassandra."""
18
19
from pycassa.pool import InvalidRequestError
20
21
22
def workaround_1779(callable, *args, **kwargs):
23
    """Workaround cassandra not being able to do concurrent schema edits.
24
25
    The callable is tried until it does not raised InvalidRequestException
26
    with why = "Previous version mismatch. cannot apply."
27
28
    :param callable: The callable to call.
29
    :param args: The args for it.
30
    :param kwargs: The kwargs for it.
31
    :return: The result of calling the callable.
32
    """
33
    while True:
34
        # Workaround https://issues.apache.org/jira/browse/CASSANDRA-1779:
35
        # Cassandra cannot do concurrent schema changes.
36
        try:
37
            return callable(*args, **kwargs)
38
            break
39
        except InvalidRequestError as e:
40
            if e.why != 'Previous version mismatch. cannot apply.':
41
                raise