Interface SliceAccessor<A>
- Type Parameters:
A
- The array type for transferring data in blocks
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
SliceAccessorImpl
Abstraction over a sequence of pages to view their content as
consecutive items. The underlying pages may be claimed by multiple page ranges held by different clients.
Clients must eventually close pages ranges in order to allow for resources to be freed.
Note: The page range abstraction enables consumers and producers to claim the same pages independently.
A consumer does not have to wait for the producers to advertise pages they are working on, instead the (low-level/internal) consumer can
simply claim the pages it wants to read in advance and then schedule any needed executors.
The claim range can be mutated which performs only the necessary
(un)claim operations.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
addEvictionGuard
(com.google.common.collect.Range<Long> range) void
addEvictionGuard
(com.google.common.collect.RangeSet<Long> ranges) Adds an eviction guard (if the slice supports it) and binds its life cycle to this accessor.void
claimByOffsetRange
(long startOffset, long endOffset) Set or update the claimed range - this will immediately request references to any pages providing the data for that range.void
close()
Closes the page range.getSlice()
void
lock()
Lock the range for writingvoid
Releases all currently held pages.void
unlock()
Unlock the rangeint
unsafeRead
(A tgt, int tgtOffset, long srcOffset, int length) Read operation that assumes a prior check for available ranges has been performed.void
Put a sequence of items into the claimed range Attempts to put items outside of the claimed range raises anIndexOutOfBoundsException
The page range should be locked when calling this method.
-
Method Details
-
getSlice
-
addEvictionGuard
Adds an eviction guard (if the slice supports it) and binds its life cycle to this accessor. Closing an accessor thus also removes all eviction guards created by it. This method must be called after acquiring a read lock on the slice's metadata.- Parameters:
ranges
- The set of ranges which to protected from eviction
-
addEvictionGuard
-
claimByOffsetRange
void claimByOffsetRange(long startOffset, long endOffset) Set or update the claimed range - this will immediately request references to any pages providing the data for that range. Pages outside of that range are considered as no longer needed pages will immediately be released. This method prepares the pages which can be subsequently locked. Calling this method while the page range is locked (lock()
) raises anIllegalStateException
.- Parameters:
startOffset
-endOffset
-
-
lock
void lock()Lock the range for writing -
write
Put a sequence of items into the claimed range Attempts to put items outside of the claimed range raises anIndexOutOfBoundsException
The page range should be locked when calling this method.- Throws:
IOException
-
unsafeRead
Read operation that assumes a prior check for available ranges has been performed. Only use this method after locking.- Throws:
IOException
-
unlock
void unlock()Unlock the range -
releaseAll
void releaseAll()Releases all currently held pages. Future requests viaclaimByOffsetRange(long, long)
are allowed. -
close
void close()Closes the page range. Implementations of this method should call {releaseAll()
and an addition prevent any further claims.- Specified by:
close
in interfaceAutoCloseable
-