Add option to disable syncing to disk

Disabling syncing increases the risk of data loss when the system crashes or power fails. On the positive it can increase the performance to a great extent.
This commit is contained in:
Unrud 2016-08-08 05:17:41 +02:00
parent c336e0581e
commit f5f52582a1
3 changed files with 15 additions and 6 deletions

5
config
View File

@ -103,6 +103,11 @@
# Folder for storing local collections, created if not present # Folder for storing local collections, created if not present
#filesystem_folder = ~/.config/radicale/collections #filesystem_folder = ~/.config/radicale/collections
# Sync all changes to disk during requests. (This can impair performance.)
# Disabling it increases the risk of data loss, when the system crashes or
# power fails!
#fsync = True
# Command that is run after changes to storage # Command that is run after changes to storage
#hook = #hook =
# Example: git add -A && (git diff --cached --quiet || git commit -m "Changes by "%(user)s) # Example: git add -A && (git diff --cached --quiet || git commit -m "Changes by "%(user)s)

View File

@ -58,6 +58,7 @@ INITIAL_CONFIG = {
"type": "multifilesystem", "type": "multifilesystem",
"filesystem_folder": os.path.expanduser( "filesystem_folder": os.path.expanduser(
"~/.config/radicale/collections"), "~/.config/radicale/collections"),
"fsync": "True",
"hook": ""}, "hook": ""},
"logging": { "logging": {
"config": "/etc/radicale/logging", "config": "/etc/radicale/logging",

View File

@ -393,10 +393,11 @@ class Collection(BaseCollection):
delete=False, prefix=".Radicale.tmp-") delete=False, prefix=".Radicale.tmp-")
try: try:
yield tmp yield tmp
if os.name == "posix" and hasattr(fcntl, "F_FULLFSYNC"): if self.configuration.getboolean("storage", "fsync"):
fcntl.fcntl(tmp.fileno(), fcntl.F_FULLFSYNC) if os.name == "posix" and hasattr(fcntl, "F_FULLFSYNC"):
else: fcntl.fcntl(tmp.fileno(), fcntl.F_FULLFSYNC)
os.fsync(tmp.fileno()) else:
os.fsync(tmp.fileno())
tmp.close() tmp.close()
os.rename(tmp.name, path) os.rename(tmp.name, path)
except: except:
@ -413,13 +414,15 @@ class Collection(BaseCollection):
return file_name return file_name
raise FileExistsError(errno.EEXIST, "No usable file name found") raise FileExistsError(errno.EEXIST, "No usable file name found")
@staticmethod @classmethod
def _sync_directory(path): def _sync_directory(cls, path):
"""Sync directory to disk. """Sync directory to disk.
This only works on POSIX and does nothing on other systems. This only works on POSIX and does nothing on other systems.
""" """
if not cls.configuration.getboolean("storage", "fsync"):
return
if os.name == "posix": if os.name == "posix":
fd = os.open(path, 0) fd = os.open(path, 0)
try: try: