~ubuntu-branches/ubuntu/trusty/python-happybase/trusty

« back to all changes in this revision

Viewing changes to happybase/batch.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2013-10-19 22:59:58 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20131019225958-faqk2cdna6ykbgu6
Tags: 0.7-1
* New upstream release (Closes: #730368).
* Drops python-nosexcover as its not being used by the tests.
* Do not build-depends on openstack-pkg-tools anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
    instead.
19
19
    """
20
20
    def __init__(self, table, timestamp=None, batch_size=None,
21
 
                 transaction=False):
 
21
                 transaction=False, wal=True):
22
22
        """Initialise a new Batch instance."""
23
23
        if not (timestamp is None or isinstance(timestamp, Integral)):
24
24
            raise TypeError("'timestamp' must be an integer or None")
34
34
        self._batch_size = batch_size
35
35
        self._timestamp = timestamp
36
36
        self._transaction = transaction
 
37
        self._wal = wal
37
38
        self._families = None
38
39
        self._reset_mutations()
39
40
 
51
52
        logger.debug("Sending batch for '%s' (%d mutations on %d rows)",
52
53
                     self._table.name, self._mutation_count, len(bms))
53
54
        if self._timestamp is None:
54
 
            self._table.connection.client.mutateRows(self._table.name, bms)
 
55
            self._table.connection.client.mutateRows(self._table.name, bms, {})
55
56
        else:
56
57
            self._table.connection.client.mutateRowsTs(
57
 
                self._table.name, bms, self._timestamp)
 
58
                self._table.name, bms, self._timestamp, {})
58
59
 
59
60
        self._reset_mutations()
60
61
 
62
63
    # Mutation methods
63
64
    #
64
65
 
65
 
    def put(self, row, data):
 
66
    def put(self, row, data, wal=None):
66
67
        """Store data in the table.
67
68
 
68
 
        See :py:meth:`Table.put` for a description of the `row` and `data`
69
 
        arguments.
 
69
        See :py:meth:`Table.put` for a description of the `row`, `data`,
 
70
        and `wal` arguments. The `wal` argument should normally not be
 
71
        used; its only use is to override the batch-wide value passed to
 
72
        :py:meth:`Table.batch`.
70
73
        """
 
74
        if wal is None:
 
75
            wal = self._wal
 
76
 
71
77
        self._mutations[row].extend(
72
 
            Mutation(isDelete=False, column=column, value=value)
 
78
            Mutation(
 
79
                isDelete=False,
 
80
                column=column,
 
81
                value=value,
 
82
                writeToWAL=wal)
73
83
            for column, value in data.iteritems())
74
84
 
75
85
        self._mutation_count += len(data)
76
86
        if self._batch_size and self._mutation_count >= self._batch_size:
77
87
            self.send()
78
88
 
79
 
    def delete(self, row, columns=None):
 
89
    def delete(self, row, columns=None, wal=None):
80
90
        """Delete data from the table.
81
91
 
82
 
        See :py:meth:`Table.delete` for a description of the `row` and
83
 
        `columns` arguments.
 
92
        See :py:meth:`Table.put` for a description of the `row`, `data`,
 
93
        and `wal` arguments. The `wal` argument should normally not be
 
94
        used; its only use is to override the batch-wide value passed to
 
95
        :py:meth:`Table.batch`.
84
96
        """
85
97
        # Work-around Thrift API limitation: the mutation API can only
86
98
        # delete specified columns, not complete rows, so just list the
87
 
        # column families once and cache them for later use in the same
88
 
        # transaction.
 
99
        # column families once and cache them for later use by the same
 
100
        # batch instance.
89
101
        if columns is None:
90
102
            if self._families is None:
91
103
                self._families = self._table._column_family_names()
92
104
            columns = self._families
93
105
 
 
106
        if wal is None:
 
107
            wal = self._wal
 
108
 
94
109
        self._mutations[row].extend(
95
 
            Mutation(isDelete=True, column=column) for column in columns)
 
110
            Mutation(isDelete=True, column=column, writeToWAL=wal)
 
111
            for column in columns)
96
112
 
97
113
        self._mutation_count += len(columns)
98
114
        if self._batch_size and self._mutation_count >= self._batch_size: