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

Give file system classes a transaction type, switch to deque #1424

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

nicholasjng
Copy link
Contributor

This means that subclasses of AbstractFileSystem need not override the transaction property and start_transaction function anymore to be able to use custom transaction classes.

Instead, they can just override the newly created transaction_type property to achieve the same.

Also changes the base Transaction's file queue to a collections.deque to pick up thread safety on pop and append events.

Finally, returning self in the transaction's context entry means that transaction objects can now be access in the enclosing transaction context.

For reviewers:
The files member shouldn't need to be flushed anymore on start, so this could just be removed?
Also, I am not sure on how to make the transaction type an instance variable, as the keyword arguments all seem to go to the DirCache. (Should I just use kwargs.pop("transaction_type", Transaction)?)

Addresses part of #1416.

fsspec/spec.py Outdated
@@ -228,6 +228,10 @@ def current(cls):
return cls._cache[cls._latest]
return cls()

@property
def transaction_type(self):
return Transaction
Copy link
Member

Choose a reason for hiding this comment

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

How about a class attribute? Then it could be overridden either by any subclass having a different attribute or by setting the attribute on any instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed, see 0271589.

This means that subclasses of `AbstractFileSystem` need not override the
`transaction` property and `start_transaction` function anymore to be
able to use custom transaction classes.

Instead, they can just override the newly created `transaction_type`
property to achieve the same.

Also changes the base `Transaction`'s file queue to a `collections.deque`
to pick up thread safety on `pop` and `append` events.

Finally, returning `self` in the transaction's context entry means that
transaction objects can now be access in the enclosing transaction
context.
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