Skip to content

Commit 7fb2faa

Browse files
authored
Merge pull request #420 from martindurant/fix_blockcache
Fix blockcache
2 parents 67f52fe + 81907c2 commit 7fb2faa

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

fsspec/caching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def _fetch(self, start, end):
218218

219219
# these are cached, so safe to do multiple calls for the same start and end.
220220
for block_number in range(start_block_number, end_block_number + 1):
221-
self._fetch_block(block_number)
221+
self._fetch_block_cached(block_number)
222222

223223
return self._read_cache(
224224
start,

fsspec/implementations/http.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import aiohttp
44
import asyncio
5+
import logging
56
import re
67
import requests
78
import weakref
@@ -14,6 +15,7 @@
1415
# https://stackoverflow.com/a/15926317/3821154
1516
ex = re.compile(r"""<a\s+(?:[^>]*?\s+)?href=(["'])(.*?)\1""")
1617
ex2 = re.compile(r"""(http[s]?://[-a-zA-Z0-9@:%_+.~#?&/=]+)""")
18+
logger = logging.getLogger("fsspec.http")
1719

1820

1921
async def get_client(**kwargs):
@@ -101,6 +103,7 @@ async def _ls(self, url, detail=True, **kwargs):
101103
# ignoring URL-encoded arguments
102104
kw = self.kwargs.copy()
103105
kw.update(kwargs)
106+
logger.debug(url)
104107
async with self.session.get(url, **self.kwargs) as r:
105108
r.raise_for_status()
106109
text = await r.text()
@@ -145,6 +148,7 @@ async def _ls(self, url, detail=True, **kwargs):
145148
async def _cat_file(self, url, **kwargs):
146149
kw = self.kwargs.copy()
147150
kw.update(kwargs)
151+
logger.debug(url)
148152
async with self.session.get(url, **kw) as r:
149153
if r.status == 404:
150154
raise FileNotFoundError(url)
@@ -155,6 +159,7 @@ async def _cat_file(self, url, **kwargs):
155159
async def _get_file(self, rpath, lpath, chunk_size=5 * 2 ** 20, **kwargs):
156160
kw = self.kwargs.copy()
157161
kw.update(kwargs)
162+
logger.debug(rpath)
158163
async with self.session.get(rpath, **self.kwargs) as r:
159164
if r.status == 404:
160165
raise FileNotFoundError(rpath)
@@ -169,6 +174,7 @@ async def _exists(self, path, **kwargs):
169174
kw = self.kwargs.copy()
170175
kw.update(kwargs)
171176
try:
177+
logger.debug(path)
172178
r = await self.session.get(path, **kw)
173179
async with r:
174180
return r.status < 400
@@ -370,6 +376,7 @@ async def async_fetch_range(self, start, end):
370376
kwargs = self.kwargs.copy()
371377
headers = kwargs.pop("headers", {}).copy()
372378
headers["Range"] = "bytes=%i-%i" % (start, end - 1)
379+
logger.debug(self.url + " : " + headers["Range"])
373380
r = await self.session.get(self.url, headers=headers, **kwargs)
374381
async with r:
375382
if r.status == 416:

fsspec/tests/test_caches.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,21 @@ def test_block_cache_lru():
1616
cache = BlockCache(4, letters_fetcher, len(string.ascii_letters), maxblocks=2)
1717
# miss
1818
cache._fetch(0, 2)
19-
assert cache.cache_info().hits == 0
2019
assert cache.cache_info().misses == 1
2120
assert cache.cache_info().currsize == 1
2221

2322
# hit
2423
cache._fetch(0, 2)
25-
assert cache.cache_info().hits == 1
2624
assert cache.cache_info().misses == 1
2725
assert cache.cache_info().currsize == 1
2826

2927
# miss
3028
cache._fetch(4, 6)
31-
assert cache.cache_info().hits == 1
3229
assert cache.cache_info().misses == 2
3330
assert cache.cache_info().currsize == 2
3431

3532
# miss & evict
3633
cache._fetch(12, 13)
37-
assert cache.cache_info().hits == 1
3834
assert cache.cache_info().misses == 3
3935
assert cache.cache_info().currsize == 2
4036

fsspec/tests/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
read_block,
88
common_prefix,
99
other_paths,
10+
setup_logger,
1011
)
1112

1213

@@ -284,3 +285,10 @@ def test_common_prefix(paths, out):
284285
)
285286
def test_other_paths(paths, other, is_dir, expected):
286287
assert other_paths(paths, other, is_dir) == expected
288+
289+
290+
def test_log():
291+
import logging
292+
293+
logger = setup_logger("fsspec.test")
294+
assert logger.level == logging.DEBUG

fsspec/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,17 @@ def other_paths(paths, path2, is_dir=None):
363363

364364
def is_exception(obj):
365365
return isinstance(obj, BaseException)
366+
367+
368+
def setup_logger(logname, level="DEBUG"):
369+
import logging
370+
371+
logger = logging.getLogger(logname)
372+
handle = logging.StreamHandler()
373+
formatter = logging.Formatter(
374+
"%(asctime)s - %(name)s - %(levelname)s " "- %(message)s"
375+
)
376+
handle.setFormatter(formatter)
377+
logger.addHandler(handle)
378+
logger.setLevel(level)
379+
return logger

0 commit comments

Comments
 (0)