-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1642 from pbiering/storage-cache-separation
Storage cache separation
- Loading branch information
Showing
12 changed files
with
64 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# This file is part of Radicale - CalDAV and CardDAV server | ||
# Copyright © 2012-2017 Guillaume Ayoub | ||
# Copyright © 2017-2019 Unrud <[email protected]> | ||
# Copyright © 2017-2021 Unrud <[email protected]> | ||
# Copyright © 2024-2024 Peter Bieringer <[email protected]> | ||
# | ||
# This library is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -99,12 +100,9 @@ def authorization(self, user: str, path: str) -> str: | |
user, sane_path, user_pattern, | ||
collection_pattern, section, permission) | ||
return permission | ||
logger.debug("Rule %r:%r doesn't match %r:%r from section %r", | ||
user, sane_path, user_pattern, collection_pattern, | ||
section) | ||
if self._log_rights_rule_doesnt_match_on_debug: | ||
logger.debug("Rule %r:%r doesn't match %r:%r from section %r", | ||
user, sane_path, user_pattern, collection_pattern, | ||
section) | ||
logger.info("Rights: %r:%r doesn't match any section", user, sane_path) | ||
logger.debug("Rights: %r:%r doesn't match any section", user, sane_path) | ||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# This file is part of Radicale - CalDAV and CardDAV server | ||
# Copyright © 2014 Jean-Marc Martins | ||
# Copyright © 2012-2017 Guillaume Ayoub | ||
# Copyright © 2017-2018 Unrud <[email protected]> | ||
# Copyright © 2017-2022 Unrud <[email protected]> | ||
# | ||
# This library is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# This file is part of Radicale - CalDAV and CardDAV server | ||
# Copyright © 2014 Jean-Marc Martins | ||
# Copyright © 2012-2017 Guillaume Ayoub | ||
# Copyright © 2017-2019 Unrud <[email protected]> | ||
# Copyright © 2017-2021 Unrud <[email protected]> | ||
# Copyright © 2024-2024 Peter Bieringer <[email protected]> | ||
# | ||
# This library is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -28,6 +29,7 @@ | |
from typing import ClassVar, Iterator, Optional, Type | ||
|
||
from radicale import config | ||
from radicale.log import logger | ||
from radicale.storage.multifilesystem.base import CollectionBase, StorageBase | ||
from radicale.storage.multifilesystem.cache import CollectionPartCache | ||
from radicale.storage.multifilesystem.create_collection import \ | ||
|
@@ -89,3 +91,5 @@ class Storage( | |
def __init__(self, configuration: config.Configuration) -> None: | ||
super().__init__(configuration) | ||
self._makedirs_synced(self._filesystem_folder) | ||
logger.info("storage location: %r", self._filesystem_folder) | ||
logger.info("storage cache subfolder usage for item: %s", self._use_cache_subfolder_for_item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# This file is part of Radicale - CalDAV and CardDAV server | ||
# Copyright © 2014 Jean-Marc Martins | ||
# Copyright © 2012-2017 Guillaume Ayoub | ||
# Copyright © 2017-2018 Unrud <[email protected]> | ||
# Copyright © 2017-2021 Unrud <[email protected]> | ||
# Copyright © 2024-2024 Peter Bieringer <[email protected]> | ||
# | ||
# This library is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -81,8 +82,7 @@ def _store_item_cache(self, href: str, item: radicale_item.Item, | |
if not cache_hash: | ||
cache_hash = self._item_cache_hash( | ||
item.serialize().encode(self._encoding)) | ||
cache_folder = os.path.join(self._filesystem_path, ".Radicale.cache", | ||
"item") | ||
cache_folder = self._storage._get_collection_cache_folder(self._filesystem_path, ".Radicale.cache", "item") | ||
content = self._item_cache_content(item) | ||
self._storage._makedirs_synced(cache_folder) | ||
# Race: Other processes might have created and locked the file. | ||
|
@@ -95,8 +95,7 @@ def _store_item_cache(self, href: str, item: radicale_item.Item, | |
|
||
def _load_item_cache(self, href: str, cache_hash: str | ||
) -> Optional[CacheContent]: | ||
cache_folder = os.path.join(self._filesystem_path, ".Radicale.cache", | ||
"item") | ||
cache_folder = self._storage._get_collection_cache_folder(self._filesystem_path, ".Radicale.cache", "item") | ||
try: | ||
with open(os.path.join(cache_folder, href), "rb") as f: | ||
hash_, *remainder = pickle.load(f) | ||
|
@@ -110,8 +109,7 @@ def _load_item_cache(self, href: str, cache_hash: str | |
return None | ||
|
||
def _clean_item_cache(self) -> None: | ||
cache_folder = os.path.join(self._filesystem_path, ".Radicale.cache", | ||
"item") | ||
cache_folder = self._storage._get_collection_cache_folder(self._filesystem_path, ".Radicale.cache", "item") | ||
self._clean_cache(cache_folder, ( | ||
e.name for e in os.scandir(cache_folder) if not | ||
os.path.isfile(os.path.join(self._filesystem_path, e.name)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# This file is part of Radicale - CalDAV and CardDAV server | ||
# Copyright © 2014 Jean-Marc Martins | ||
# Copyright © 2012-2017 Guillaume Ayoub | ||
# Copyright © 2017-2018 Unrud <[email protected]> | ||
# Copyright © 2017-2021 Unrud <[email protected]> | ||
# Copyright © 2024-2024 Peter Bieringer <[email protected]> | ||
# | ||
# This library is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -41,10 +42,8 @@ def move(self, item: radicale_item.Item, | |
if item.collection._filesystem_path != to_collection._filesystem_path: | ||
self._sync_directory(item.collection._filesystem_path) | ||
# Move the item cache entry | ||
cache_folder = os.path.join(item.collection._filesystem_path, | ||
".Radicale.cache", "item") | ||
to_cache_folder = os.path.join(to_collection._filesystem_path, | ||
".Radicale.cache", "item") | ||
cache_folder = self._get_collection_cache_folder(item.collection._filesystem_path, ".Radicale.cache", "item") | ||
to_cache_folder = self._get_collection_cache_folder(to_collection._filesystem_path, ".Radicale.cache", "item") | ||
self._makedirs_synced(to_cache_folder) | ||
try: | ||
os.replace(os.path.join(cache_folder, item.href), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# This file is part of Radicale - CalDAV and CardDAV server | ||
# Copyright © 2014 Jean-Marc Martins | ||
# Copyright © 2012-2017 Guillaume Ayoub | ||
# Copyright © 2017-2018 Unrud <[email protected]> | ||
# Copyright © 2017-2022 Unrud <[email protected]> | ||
# Copyright © 2024-2024 Peter Bieringer <[email protected]> | ||
# | ||
# This library is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -75,8 +76,7 @@ def get_safe_free_hrefs(uid: str) -> Iterator[str]: | |
yield radicale_item.find_available_uid( | ||
lambda href: not is_safe_free_href(href), suffix) | ||
|
||
cache_folder = os.path.join(self._filesystem_path, | ||
".Radicale.cache", "item") | ||
cache_folder = self._storage._get_collection_cache_folder(self._filesystem_path, ".Radicale.cache", "item") | ||
self._storage._makedirs_synced(cache_folder) | ||
for item in items: | ||
uid = item.uid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# This file is part of Radicale - CalDAV and CardDAV server | ||
# Copyright © 2012-2017 Guillaume Ayoub | ||
# Copyright © 2017-2019 Unrud <[email protected]> | ||
# Copyright © 2017-2022 Unrud <[email protected]> | ||
# Copyright © 2024-2024 Peter Bieringer <[email protected]> | ||
# | ||
# This library is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -99,6 +100,22 @@ def test_item_cache_rebuild(self) -> None: | |
assert answer1 == answer2 | ||
assert os.path.exists(os.path.join(cache_folder, "event1.ics")) | ||
|
||
def test_item_cache_rebuild_subfolder(self) -> None: | ||
"""Delete the item cache and verify that it is rebuild.""" | ||
self.configure({"storage": {"use_cache_subfolder_for_item": "True"}}) | ||
self.mkcalendar("/calendar.ics/") | ||
event = get_file_content("event1.ics") | ||
path = "/calendar.ics/event1.ics" | ||
self.put(path, event) | ||
_, answer1 = self.get(path) | ||
cache_folder = os.path.join(self.colpath, "collection-cache", | ||
"calendar.ics", ".Radicale.cache", "item") | ||
assert os.path.exists(os.path.join(cache_folder, "event1.ics")) | ||
shutil.rmtree(cache_folder) | ||
_, answer2 = self.get(path) | ||
assert answer1 == answer2 | ||
assert os.path.exists(os.path.join(cache_folder, "event1.ics")) | ||
|
||
def test_put_whole_calendar_uids_used_as_file_names(self) -> None: | ||
"""Test if UIDs are used as file names.""" | ||
_TestBaseRequests.test_put_whole_calendar( | ||
|