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

Python Wrapper: Implement Import Manager #7084

Merged
merged 4 commits into from
Dec 1, 2023

Conversation

N-o-Z
Copy link
Member

@N-o-Z N-o-Z commented Nov 29, 2023

Closes #7077

Change Description

Implement ImportManager module

Testing Details

Unit and integration tests

@N-o-Z N-o-Z added exclude-changelog PR description should not be included in next release changelog python-wrapper labels Nov 29, 2023
@N-o-Z N-o-Z requested a review from guy-har November 29, 2023 22:24
@N-o-Z N-o-Z self-assigned this Nov 29, 2023
Copy link
Contributor

@guy-har guy-har left a comment

Choose a reason for hiding this comment

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

Looks good,
most comments are basically for my understanding



class ImportManager:
"""
Manage an import operation on a given repository
ImportManager provides an easy-to-use interface to perform imports with multiple sources.
It provides both synchronous and asynchronous functionality TBD
Copy link
Contributor

Choose a reason for hiding this comment

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

TBD?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 40 to 41
# Bug in import API - message is required
self.commit_message = commit_message if commit_message is not None else ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any intention to make message required in importAPI? if not? what is the value in having optional that is casted to an empty string?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a bug in the API. Commit message should be an optional field we need to fix that. I'll open an issue on it

Copy link
Member Author

Choose a reason for hiding this comment

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

On second though - fixed in the wrapper

Comment on lines +86 to +88
if self._in_progress:
raise ImportManagerException("Import in progress")

Copy link
Contributor

Choose a reason for hiding this comment

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

Believe this is more of a product question: are we allowed to call an import twice (i.e call (start,wait) twice ) currently every time wait is done, the fields are reset and we're ready to do another import with this manager with the same commit_message and metadata.
Also the import_id isn't erased so status will still return the status of the previous run. something feels a bit inconsistent

Copy link
Member Author

Choose a reason for hiding this comment

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

The import id isn't erased by design so that you can continue to status on the import process even when it was completed.
I was considering making the mgr a single use object but eventually decided this would just make the user experience more burdensome. My assumption is that if we wanted it to be single use - it's better to just replace it with a function call rather then an object

Copy link
Member Author

Choose a reason for hiding this comment

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

We can always modify this behavior in the future as this is not a guarantee we have to commit to

Copy link
Member Author

Choose a reason for hiding this comment

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

We can always modify this behavior in the future as this is not a guarantee we have to commit to

Comment on lines 157 to 165
if not self._in_progress: # No import in progress - nothing to do
return

with api_exception_handler():
self._client.sdk_client.import_api.import_cancel(repository=self._repo_id,
branch=self._branch_id,
id=self._import_id)
self._in_progress = False
self.sources = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here...
If I run import wait enough time (for the import to finish) and then call cancel, I will get a conflict saying import is done, but if I call wait and then call cancel everything is fine and no error returns

Copy link
Member Author

Choose a reason for hiding this comment

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

Modified the behavior for cancel to not check for in progress

mgr = branch.import_data("my imported data", metadata={"foo": "bar"})

# No import running
mgr.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

When should cancel succeed and when should it return an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically always succeed unless the import was canceled unexpectedly by someone else or the import started and already completed

Comment on lines 27 to 28
assert res.commit.message == branch.commit_message()
assert res.commit.metadata == branch.metadata()
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to add a validation that it used the commit_message and metadata we expected
"my imported data", metadata={"foo": "bar"}

Comment on lines +62 to +64
mgr.start()
sleep(1)
mgr.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be flaky if we somehow finished before the cancel call

Copy link
Member Author

Choose a reason for hiding this comment

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

The import here is very big, it will not take less than a second. We have a similar test flow in esti

N-o-Z added 2 commits December 1, 2023 09:31
…-import-manager-7077

# Conflicts:
#	clients/python-wrapper/lakefs/branch.py
#	clients/python-wrapper/lakefs/namedtuple.py
#	clients/python-wrapper/lakefs/repository.py
@N-o-Z N-o-Z enabled auto-merge (squash) December 1, 2023 10:09
@N-o-Z N-o-Z disabled auto-merge December 1, 2023 10:11
@N-o-Z N-o-Z merged commit 45adc44 into master Dec 1, 2023
32 checks passed
@N-o-Z N-o-Z deleted the task/python-wrapper-import-manager-7077 branch December 1, 2023 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exclude-changelog PR description should not be included in next release changelog python-wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python Wrapper: Implement Import Manager
2 participants