Skip to content
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

Allow for changing the spatial filter with kart checkout #465

Merged
merged 2 commits into from
Aug 2, 2021

Conversation

olsen232
Copy link
Collaborator

@olsen232 olsen232 commented Aug 1, 2021

Description

kart checkout --spatial-filter=SPEC now updates the spatial filter. The syntax is the same as for kart init and kart clone.
The spatial filter cannot be changed while there are uncommitted changes in the working copy (this avoids certain potential problems with handling probably-accidental-PK-collisions - note that these aren't actually handled yet however), and it works by rewriting the entire working copy from scratch (anything else would be an optimisation, and would only speed things up in the case that the intersection between the old and the new spatial filter is large compared to the their total size).

Not done in this PR:

  • Handling of probably-accidental-PK-collisions (see above)
  • Notifying user when a spatial filter that is stored by reference has changed and/or updating it automatically when possible

Related links:

#456

@olsen232 olsen232 requested review from craigds and rcoup August 1, 2021 23:36
kart/checkout.py Outdated

db_tree_matches = (
working_copy.get_db_tree() == target_tree_or_commit.peel(pygit2.Tree).hex
)

if discard_changes or not db_tree_matches:
if discard_changes or not db_tree_matches or not spatial_filter_matches:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we never hit this because of the above, so might as well remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

)

def resolve(self, repo):
# Returns the ResolvedSpatialFilterSpec that this ReferenceSpatialFilterSpec points to.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs clarifying I think (and turning into a docstring)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded the docstring and moved it to a superclass.

except (KeyError, ValueError):
pass

if obj is not None:
return None, oid, self._resolve_object_contents(obj)

ref = self.ref_or_oid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this function is assuming (AFAICT) that at this point the self.ref_or_oid is the name of a ref rather than an OID. Is that true? It seems like it could be an OID of an unfetched object also. Is there any way to tell?

Copy link
Collaborator Author

@olsen232 olsen232 Aug 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does assume that if it doesn't find the object, it must be a ref - or missing. It could be that it is an unfetched object however. But whether non-existent or unfetched, the end results will be this:
No spatial filter object was found in the repository at 9d5d8e7 or refs/filters/9d5d8e7 - which is true and describes the problem accurately.

I'll add a TODO to handle unfetched objects here somehow, but it's part of a bigger problem - we can't currently tell if objects are non-existent / corrupted or merely unfetched, and we don't specifically handle unfetched objects anywhere.

if not force:
self.check_not_dirty()

self.drop_table(commit, *datasets)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should rename to drop_tables ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1010,6 +1046,18 @@ def _delete_meta(self, sess, dataset):
"""
raise NotImplementedError()

def rewrite_full(self, commit, *datasets, force=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this method be done in one transaction? Otherwise a client watching carefully will see tables be dropped, and then recreated shortly afterwards. For big WCs those could be a while apart.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@olsen232 olsen232 merged commit deb3a54 into master Aug 2, 2021
@olsen232 olsen232 deleted the spatial-filter-5 branch August 2, 2021 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants