Invalidate existing dataset or metadata accessor objects after a checkout is closed #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These changes ensure that when a checkout (reader or writer) is closed, that any references to
dataset
ormetadata
objects are invalidated and will not perform any type of operation.Description
Instead of explicitly validating that some sort of
IS_ALIVE
sentinal on every call to thedataset
ormetadata
interactor objects, we use an invalidation scheme based on weakrefs. The control flow is as follows:A strong reference to a dataset or metadata instance is created and held in a "
_private
" attribute of thecheckout
class. In the new scheme, this is the ONLY strong reference which will be kept to the members.For public consumption,
datasets
andmetadata
methods are defined in thecheckout
object using theproperty
protocol to remap thegetter
to the internal attributes. Because nosetter
is defined, these properties cannot be changed by the user.At this point, we do a "bait-and-switch", providing a
weakref proxy
to the requested object. By definition, these do not increment the reference count, but pass through all calls to the checkout's instance of the actual object.when the
checkout.close()
method is called, the checkout objects._datasets
and._metadata
attributes are deleted and we explicitly perform a garbage collection.Since
weakrefs
don't increment reference counts, when the attributes are deleted on close and gc is run, theproxy
mapping no longer has a valid reference. It will raise aReferenceError()
if any operation is attempted on it.Validations performed in the
checkout
class ensure that the object is essentially dead to the user, and a new checkout must be created to interact with the repository again.This is a performant and clean way of ensuring that users are not able to perform operations during a time they shouldn't be able to. Methods are implemented for both read and write checkouts and both function as expected and pass all tests.
Motivation and Context
Examples of the problem before this fix were first shown in Issue #36. Please refer to that posting for further background.
How Has This Been Tested?
Test cases have been added to the test suite.
Types of changes
Checklist:
Please review @hhsecond and @lantiga