@@ -58,7 +58,7 @@ def __init__(self, client, group, topic, auto_commit=True,
58
58
# Set up the auto-commit timer
59
59
if auto_commit is True and auto_commit_every_t is not None :
60
60
self .commit_timer = ReentrantTimer (auto_commit_every_t ,
61
- self ._timed_commit )
61
+ self .commit )
62
62
self .commit_timer .start ()
63
63
64
64
def get_or_init_offset_callback (resp ):
@@ -150,15 +150,6 @@ def pending(self, partitions=[]):
150
150
151
151
return total
152
152
153
- def _timed_commit (self ):
154
- """
155
- Commit offsets as part of timer
156
- """
157
- self .commit ()
158
-
159
- # Once the commit is done, start the timer again
160
- self .commit_timer .start ()
161
-
162
153
def commit (self , partitions = []):
163
154
"""
164
155
Commit offsets for this consumer
@@ -167,11 +158,17 @@ def commit(self, partitions=[]):
167
158
all of them
168
159
"""
169
160
170
- # short circuit if nothing happened
161
+ # short circuit if nothing happened. This check is kept outside
162
+ # to prevent un-necessarily acquiring a lock for checking the state
171
163
if self .count_since_commit == 0 :
172
164
return
173
165
174
166
with self .commit_lock :
167
+ # Do this check again, just in case the state has changed
168
+ # during the lock acquiring timeout
169
+ if self .count_since_commit == 0 :
170
+ return
171
+
175
172
reqs = []
176
173
if len (partitions ) == 0 : # commit all partitions
177
174
partitions = self .offsets .keys ()
@@ -201,12 +198,7 @@ def _auto_commit(self):
201
198
return
202
199
203
200
if self .count_since_commit > self .auto_commit_every_n :
204
- if self .commit_timer is not None :
205
- self .commit_timer .stop ()
206
- self .commit ()
207
- self .commit_timer .start ()
208
- else :
209
- self .commit ()
201
+ self .commit ()
210
202
211
203
def __iter__ (self ):
212
204
"""
0 commit comments