~daisy-pluckers/oops-repository/trunk

« back to all changes in this revision

Viewing changes to oopsrepository/cassandra.py

  • Committer: Robert Collins
  • Date: 2011-02-26 19:47:58 UTC
  • Revision ID: robert@canonical.com-20110226194758-u0i9ppdqcpsjifo6
Schema creation is possible.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# oops-repository is Copyright 2011 Canonical Ltd.
 
2
#
 
3
# Canonical Ltd ("Canonical") distributes the oops-repository source code under
 
4
# the GNU Affero General Public License, version 3 ("AGPLv3"). See the file
 
5
# LICENSE in the source tree for more information.
 
6
 
 
7
"""Things to ease working with cassandra."""
 
8
 
 
9
from pycassa.cassandra.Cassandra import InvalidRequestException
 
10
 
 
11
def workaround_1779(callable, *args, **kwargs):
 
12
    """Workaround cassandra not being able to do concurrent schema edits.
 
13
 
 
14
    The callable is tried until it does not raised InvalidRequestException
 
15
    with why = "Previous version mismatch. cannot apply."
 
16
    
 
17
    :param callable: The callable to call.
 
18
    :param args: The args for it.
 
19
    :param kwargs: The kwargs for it.
 
20
    :return: The result of calling the callable.
 
21
    """
 
22
    while True:
 
23
        # Workaround https://issues.apache.org/jira/browse/CASSANDRA-1779:
 
24
        # Cassandra cannot do concurrent schema changes.
 
25
        try:
 
26
            return callable(*args, **kwargs)
 
27
            break
 
28
        except InvalidRequestException as e:
 
29
            if e.why != 'Previous version mismatch. cannot apply.':
 
30
                raise