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

Reduces flushes during commit/checkout #1381

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions hub/core/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ def commit(self, message: Optional[str] = None) -> None:
str: the commit id of the stored commit that can be used to access the snapshot.
"""
commit_id = self.version_state["commit_id"]
try_flushing(self)
Copy link
Contributor Author

@AbhinavTuli AbhinavTuli Dec 8, 2021

Choose a reason for hiding this comment

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

we already flush after copying metas inside commit function in version_control.py so this wasn't needed

initial_autoflush = self.storage.autoflush
Copy link
Contributor Author

Choose a reason for hiding this comment

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

always disable autoflush during commit and enable it back at the end if required

self.storage.autoflush = False
commit(self.version_state, self.storage, message)
self._info = None

Expand All @@ -413,6 +414,7 @@ def commit(self, message: Optional[str] = None) -> None:
parameters={},
)

self.storage.autoflush = initial_autoflush
return commit_id

def checkout(self, address: str, create: bool = False) -> str:
Expand All @@ -426,7 +428,8 @@ def checkout(self, address: str, create: bool = False) -> str:
Returns:
str: The commit_id of the dataset after checkout.
"""
try_flushing(self)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can remove this call as we flush during copy_metas during checkout in version_control.py if a new branch is being created, otherwise if we're checking out to an existing branch/commit, explicit flushes have been added now.

initial_autoflush = self.storage.autoflush
self.storage.autoflush = False
checkout(self.version_state, self.storage, address, create)
self._info = None

Expand All @@ -436,6 +439,7 @@ def checkout(self, address: str, create: bool = False) -> str:
parameters={"Create": str(create)},
)

self.storage.autoflush = initial_autoflush
return self.version_state["commit_id"]

def log(self):
Expand Down
4 changes: 4 additions & 0 deletions hub/util/version_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def checkout(
return
version_state["commit_id"] = new_commit_id
version_state["commit_node"] = version_state["commit_node_map"][new_commit_id]
if not storage.read_only:
storage.flush()
elif address in version_state["commit_node_map"].keys():
if create:
raise CheckoutError(
Expand All @@ -80,6 +82,8 @@ def checkout(
version_state["commit_id"] = address
version_state["commit_node"] = version_state["commit_node_map"][address]
version_state["branch"] = version_state["commit_node"].branch
if not storage.read_only:
storage.flush()
elif create:
storage.check_readonly()
# if the original commit is head of the branch, auto commit and checkout to original commit before creating new branch
Expand Down