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

« back to all changes in this revision

Viewing changes to grackle/cassandra.py

  • Committer: Aaron Bentley
  • Date: 2012-01-10 10:46:26 UTC
  • Revision ID: aaron@canonical.com-20120110104626-39ehw9nhnzdzggtw
Add README and LICENSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
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