-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backup tree walking using yield #941
Conversation
I have tried something like
We need to keep track of visited nodes, so i added a visited parameter for it that should be passed along the recursion ( the visited is the result of the walk through based on Depth-first search Post Order algo). |
this is an interesting take on the tree-walking method.
Why do you want to keep track of the nodes?
But that is not possible as an incremental backup can have a single parent only.
(please forgive my ascii-art skills... but I think you got the idea) Using the Where |
Actually the |
c1e0406
to
025d499
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a commit with docstring suggestions.
The PR looks good, I only have a small comment about the walk_to_root
method.
backup_info = self.get_parent_backup_info() | ||
while backup_info: | ||
yield backup_info | ||
backup_info = backup_info.get_parent_backup_info() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we yield self
as well?
I mean, just so we make both methods "compatible" in terms of what is returned.
Also, it may make it easier to build the pg_combinebackup
command later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depends on the behaviour we want... my rationale was:
"I already know the object that is self
, so I start returning objects from the first parent."
I see nothing wrong in yielding self too... is just that in my mind were were more often going to ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way works for me, actually.
I think we can keep it as it is, and later change if we think this is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
This patch adds methods to walk a tree of incremental backups. The `walk_backups_tree` method, given a node as root, traverses the tree in post-order identifying leaves first and nodes parent of the leaves after. This is useful for actions like: removal of a full chain of backups. The method is implemented using yield statements, that allow to iterate through the chain of nodes The `walk_to_root` method allows to reach the parent full backup of a given backup node of an incremental backups tree. The method is implemented using yield statements allowing to cycle from the node until the root. References: bar-182 Signed-off-by: Giulio Calacoci <giulio.calacoci@enterprisedb.com> Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
Test `walk_to_root` and `walk_backups_tree` methods of the BackupInfo class References: bar-182 Signed-off-by: Giulio Calacoci <giulio.calacoci@enterprisedb.com> Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
This is much a draft.
I've added a method
walk_backups_tree
that given any backup info allows to walk the tree of children and act on them starting from leaves.let's assume this backups structure where names of the nodes are backup_id values:
the method starting from the root_backup, should walk down until the leaves and then return up.
To put it simple, assuming to execute something like this:
we should get as result:
This should simplify the execution of actions like backup removal, allowing to walk bottom up the tree.