Skip to content

Commit

Permalink
got rid of the rest of CachedProperty. (its too hacky, and confuses p…
Browse files Browse the repository at this point in the history
…ycharm as well, and now we can actually partually invalidate caches. take that past self!)
  • Loading branch information
Your Name committed Sep 24, 2024
1 parent 0754236 commit b54c10e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 89 deletions.
39 changes: 0 additions & 39 deletions zfs_autobackup/CachedProperty.py

This file was deleted.

14 changes: 0 additions & 14 deletions zfs_autobackup/ZfsDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def __init__(self, zfs_node, name, force_exists=None):

def invalidate_cache(self):
"""clear caches"""
# CachedProperty.clear(self)
self.force_exists = None
self.__snapshots = None
self.__written_since_ours = None
Expand Down Expand Up @@ -448,19 +447,6 @@ def timestamp(self):
seconds = time.mktime(dt.timetuple())
return seconds

# def add_virtual_snapshot(self, snapshot):
# """pretend a snapshot exists (usefull in test mode)"""
#
# # NOTE: we could just call self.snapshots.append() but this would trigger a zfs list which is not always needed.
# if CachedProperty.is_cached(self, 'snapshots'):
# # already cached so add it
# print ("ADDED")
# self.snapshots.append(snapshot)
# else:
# # self.snapshots will add it when requested
# print ("ADDED VIRT")
# self._virtual_snapshots.append(snapshot)

@property
def snapshots(self):
"""get all snapshots of this dataset
Expand Down
52 changes: 28 additions & 24 deletions zfs_autobackup/ZfsNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from .ExecuteNode import ExecuteNode
from .Thinner import Thinner
from .CachedProperty import CachedProperty
from .ZfsPool import ZfsPool
from .ZfsDataset import ZfsDataset
from .ExecuteNode import ExecuteError
Expand All @@ -18,7 +17,8 @@
class ZfsNode(ExecuteNode):
"""a node that contains zfs datasets. implements global (systemwide/pool wide) zfs commands"""

def __init__(self, logger, utc=False, snapshot_time_format="", hold_name="", ssh_config=None, ssh_to=None, readonly=False,
def __init__(self, logger, utc=False, snapshot_time_format="", hold_name="", ssh_config=None, ssh_to=None,
readonly=False,
description="",
debug_output=False, thinner=None, exclude_snapshot_patterns=[]):

Expand All @@ -30,6 +30,9 @@ def __init__(self, logger, utc=False, snapshot_time_format="", hold_name="", ssh

self.logger = logger

self.__supported_send_options = None
self.__supported_recv_options = None

self.exclude_snapshot_patterns = exclude_snapshot_patterns

if ssh_config:
Expand Down Expand Up @@ -74,27 +77,30 @@ def thin_list(self, snapshots, keep_snapshots):
else:
return (keep_snapshots, [])

@CachedProperty
@property
def supported_send_options(self):
"""list of supported options, for optimizing sends"""
# not every zfs implementation supports them all

ret = []
for option in ["-L", "-e", "-c"]:
if self.valid_command(["zfs", "send", option, "zfs_autobackup_option_test"]):
ret.append(option)
return ret
if self.__supported_send_options is None:
self.__supported_send_options = []
for option in ["-L", "-e", "-c"]:
if self.valid_command(["zfs", "send", option, "zfs_autobackup_option_test"]):
self.__supported_send_options.append(option)
return self.__supported_send_options

@CachedProperty
@property
def supported_recv_options(self):
"""list of supported options"""
# not every zfs implementation supports them all

ret = []
for option in ["-s"]:
if self.valid_command(["zfs", "recv", option, "zfs_autobackup_option_test"]):
ret.append(option)
return ret
if self.__supported_recv_options is None:
self.__supported_recv_options = []
for option in ["-s"]:
if self.valid_command(["zfs", "recv", option, "zfs_autobackup_option_test"]):
self.__supported_recv_options.append(option)

return self.__supported_recv_options

def valid_command(self, cmd):
"""test if a specified zfs options are valid exit code. use this to determine support options"""
Expand Down Expand Up @@ -129,13 +135,12 @@ def get_datasets(self, names, force_exists=None):
"""

ret=[]
ret = []
for name in names:
ret.append(self.get_dataset(name, force_exists))

return ret


# def reset_progress(self):
# """reset progress output counters"""
# self._progress_total_bytes = 0
Expand Down Expand Up @@ -275,7 +280,6 @@ def selected_datasets(self, property_name, exclude_received, exclude_paths, excl
property_name
])


# The returnlist of selected ZfsDataset's:
selected_filesystems = []
excluded_filesystems = []
Expand All @@ -298,14 +302,14 @@ def selected_datasets(self, property_name, exclude_received, exclude_paths, excl
source = raw_source

# determine it
selected=dataset.is_selected(value=value, source=source, inherited=inherited, exclude_received=exclude_received,
exclude_paths=exclude_paths, exclude_unchanged=exclude_unchanged)
selected = dataset.is_selected(value=value, source=source, inherited=inherited,
exclude_received=exclude_received,
exclude_paths=exclude_paths, exclude_unchanged=exclude_unchanged)

if selected==True:
if selected == True:
selected_filesystems.append(dataset)
elif selected==False:
elif selected == False:
excluded_filesystems.append(dataset)
#returns None when no property is set.

# returns None when no property is set.

return ( selected_filesystems, excluded_filesystems)
return (selected_filesystems, excluded_filesystems)
27 changes: 15 additions & 12 deletions zfs_autobackup/ZfsPool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from .CachedProperty import CachedProperty


class ZfsPool():
"""a zfs pool"""

Expand All @@ -10,6 +7,10 @@ def __init__(self, zfs_node, name):

self.zfs_node = zfs_node
self.name = name
self.__properties = None

def invalidate_cache(self):
self.__properties = None

def __repr__(self):
return "{}: {}".format(self.zfs_node, self.name)
Expand All @@ -32,22 +33,24 @@ def error(self, txt):
def debug(self, txt):
self.zfs_node.debug("zpool {}: {}".format(self.name, txt))

@CachedProperty
@property
def properties(self):
"""all zpool properties"""

self.debug("Getting zpool properties")
if self.__properties is None:

cmd = [
"zpool", "get", "-H", "-p", "all", self.name
]
self.debug("Getting zpool properties")

ret = {}
cmd = [
"zpool", "get", "-H", "-p", "all", self.name
]

for pair in self.zfs_node.run(tab_split=True, cmd=cmd, readonly=True, valid_exitcodes=[0]):
ret[pair[1]] = pair[2]
self.__properties = {}

return ret
for pair in self.zfs_node.run(tab_split=True, cmd=cmd, readonly=True, valid_exitcodes=[0]):
self.__properties[pair[1]] = pair[2]

return self.__properties

@property
def features(self):
Expand Down

0 comments on commit b54c10e

Please sign in to comment.