Skip to content

Commit

Permalink
Invalidate cache entry on rm. (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtopper authored Jan 27, 2022
1 parent 1eb25c0 commit 7e7ff8f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@pytest.fixture
def fs():
fs = V3ioFS(cache_validity_seconds=0)
fs = V3ioFS()
yield fs
fs._client.close()

Expand Down
8 changes: 1 addition & 7 deletions v3iofs/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,4 @@ def _upload_chunk(self, final=False):

def _initiate_upload(self):
""" Create remote file/upload """
client: Client = self.fs._client
container, path = split_container(self.path)
client.object.delete(
container=container,
path=path,
raise_for_status=v3io.dataplane.RaiseForStatus.never,
)
self.fs.rm_file(self.path)
18 changes: 15 additions & 3 deletions v3iofs/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ def get(self, key):

return None

def delete_if_exists(self, key):
self._cache.pop(key, None)

def _gc(self, until):
for key_time, key in self._time_to_key:
num_removed = 0
if key_time > until + self._cache_validity_seconds or len(self._cache) > self._capacity:
del self._cache[key]
result = self._cache.get(key, None)
if result:
cache_time, value = result
# cache entry may have been deleted and re-added
if cache_time == key_time:
del self._cache[key]

num_removed += 1
else:
break
Expand Down Expand Up @@ -178,13 +187,13 @@ def copy(self, path1, path2, **kwargs):
... # FIXME

def _rm(self, path):
container, path = split_container(path)
container, path_without_container = split_container(path)
if not container:
raise ValueError(f'bad path: {path:r}')

resp = self._client.delete_object(
container=container,
path=path,
path=path_without_container,
raise_for_status=v3io.dataplane.RaiseForStatus.never,
)

Expand All @@ -193,6 +202,9 @@ def _rm(self, path):
raise Exception(
f'{resp.status_code} received while accessing {path!r}')

if self._cache:
self._cache.delete_if_exists(path)

def touch(self, path, truncate=True, **kwargs):
if not truncate: # TODO
raise ValueError('only truncate touch supported')
Expand Down

0 comments on commit 7e7ff8f

Please sign in to comment.