Skip to content

Commit 5afeb6c

Browse files
Merge pull request pandas-dev#154 from manahl/re-cache-the-library-quota-periodically
Re-cache the library quota periodically
2 parents dec4f3d + 1829ebf commit 5afeb6c

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Bugfix: Faster TickStore querying for multiple symbols simultaneously
66
* Bugfix: TickStore.read now respects `allow_secondary=True`
77
* Bugfix: #147 Add get_info method to ChunkStore
8+
* Bugfix: Periodically re-cache the library.quota to pick up any changes
89

910
### 1.25 (2016-05-23)
1011

arctic/arctic.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -398,20 +398,17 @@ def check_quota(self):
398398
every write. Will raise() if the library has exceeded its allotted
399399
quota.
400400
"""
401-
# Don't check on every write
402-
if self.quota is None:
403-
self.quota = self.get_library_metadata(ArcticLibraryBinding.QUOTA)
404-
if self.quota is None:
405-
self.quota = 0
406-
407-
if self.quota == 0:
408-
return
409-
410401
# Don't check on every write, that would be slow
411402
if self.quota_countdown > 0:
412403
self.quota_countdown -= 1
413404
return
414405

406+
# Re-cache the quota after the countdown
407+
self.quota = self.get_library_metadata(ArcticLibraryBinding.QUOTA)
408+
if self.quota is None or self.quota == 0:
409+
self.quota = 0
410+
return
411+
415412
# Figure out whether the user has exceeded their quota
416413
library = self.arctic[self.get_name()]
417414
stats = library.stats()
@@ -439,6 +436,7 @@ def to_gigabytes(bytes_):
439436
to_gigabytes(self.quota)))
440437

441438
# Set-up a timer to prevent us for checking for a few writes.
439+
# This will check every average half-life
442440
self.quota_countdown = int(max(remaining_count // 2, 1))
443441

444442
def get_library_type(self):

tests/unit/test_arctic.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ def test_get_quota():
162162

163163
def test_check_quota_Zero():
164164
self = create_autospec(ArcticLibraryBinding)
165-
self.quota = 0
165+
self.get_library_metadata.return_value = 0
166+
self.quota_countdown = 0
166167
ArcticLibraryBinding.check_quota(self)
167168

168169

169170
def test_check_quota_None():
170171
m = Mock(spec=ArcticLibraryBinding)
171172
m.quota = None
173+
m.quota_countdown = 0
172174
m.get_library_metadata.return_value = None
173175
ArcticLibraryBinding.check_quota(m)
174176
m.get_library_metadata.assert_called_once_with('QUOTA')
@@ -178,6 +180,7 @@ def test_check_quota_None():
178180
def test_check_quota_Zero2():
179181
m = Mock(spec=ArcticLibraryBinding)
180182
m.quota = None
183+
m.quota_countdown = 0
181184
m.get_library_metadata.return_value = 0
182185
ArcticLibraryBinding.check_quota(m)
183186
m.get_library_metadata.assert_called_once_with('QUOTA')
@@ -186,7 +189,7 @@ def test_check_quota_Zero2():
186189

187190
def test_check_quota_countdown():
188191
self = create_autospec(ArcticLibraryBinding)
189-
self.quota = 10
192+
self.get_library_metadata.return_value = 10
190193
self.quota_countdown = 10
191194
ArcticLibraryBinding.check_quota(self)
192195
assert self.quota_countdown == 9
@@ -195,7 +198,7 @@ def test_check_quota_countdown():
195198
def test_check_quota():
196199
self = create_autospec(ArcticLibraryBinding)
197200
self.arctic = create_autospec(Arctic)
198-
self.quota = 1024 * 1024 * 1024
201+
self.get_library_metadata.return_value = 1024 * 1024 * 1024
199202
self.quota_countdown = 0
200203
self.arctic.__getitem__.return_value = Mock(stats=Mock(return_value={'totals':
201204
{'size': 900 * 1024 * 1024,
@@ -212,7 +215,7 @@ def test_check_quota():
212215
def test_check_quota_info():
213216
self = create_autospec(ArcticLibraryBinding)
214217
self.arctic = create_autospec(Arctic)
215-
self.quota = 1024 * 1024 * 1024
218+
self.get_library_metadata.return_value = 1024 * 1024 * 1024
216219
self.quota_countdown = 0
217220
self.arctic.__getitem__.return_value = Mock(stats=Mock(return_value={'totals':
218221
{'size': 1 * 1024 * 1024,
@@ -229,7 +232,7 @@ def test_check_quota_info():
229232
def test_check_quota_exceeded():
230233
self = create_autospec(ArcticLibraryBinding)
231234
self.arctic = create_autospec(Arctic)
232-
self.quota = 1024 * 1024 * 1024
235+
self.get_library_metadata.return_value = 1024 * 1024 * 1024
233236
self.quota_countdown = 0
234237
self.arctic.__getitem__.return_value = Mock(stats=Mock(return_value={'totals':
235238
{'size': 1024 * 1024 * 1024,

0 commit comments

Comments
 (0)