public class AllocationContext extends Object implements IAllocationContext, IMemoryManager
AllocationContext is used to maintain a handle on allocations
made within some specific environment (context).
In this way, clearing a context will return all allocations to the more
general pool.
There are two obvious implementation strategies:
| Constructor and Description |
|---|
AllocationContext(AllocationContext parent) |
AllocationContext(MemoryManager root,
boolean isolated) |
| Modifier and Type | Method and Description |
|---|---|
void |
abortContext(IAllocationContext context)
Indicates that the allocation context will no longer be used and that the
allocations made within the context should be discarded.
|
long |
alloc(byte[] buf,
int size,
IAllocationContext context)
Writes data on the store.
|
long |
allocate(ByteBuffer data)
Version of
IMemoryManager.allocate(ByteBuffer, boolean) which is either
blocking or non-blocking depending on whether or not the memory
manager is set in a blocking mode. |
long |
allocate(ByteBuffer data,
boolean blocks)
Allocates space on the backing resource and copies the provided data.
|
long |
allocate(ByteBuffer data,
IAllocationContext context) |
long |
allocate(int nbytes)
Return the address of a new allocation sufficient to store the specified
number of bytes of application data.
|
long |
allocate(int nbytes,
boolean blocks)
Return the address of a new allocation sufficient to store the specified
number of bytes of application data.
|
int |
allocationSize(long addr)
Return the size of the application data for the allocation with the given
address.
|
void |
checkActive() |
int |
checkDeferredFrees(AbstractJournal abstractJournal)
This method is invoked during the commit protocol and gives the backing
store an opportunity to check whether storage associated with deferred
frees can now be released.
|
void |
clear()
Clears all current allocations.
|
void |
close()
Close the backing storage.
|
void |
commit()
Global commit on the backing store.
|
IMemoryManager |
createAllocationContext()
Create a child allocation context within which the caller may make and
release allocations.
|
void |
delete(long addr,
IAllocationContext context)
Delete the data associated with the address within the allocation
context.
|
void |
detachContext(IAllocationContext context)
Indicates that the allocation context will no longer be used, but that
the allocations made within the context should be preserved.
|
void |
free(long addr)
Frees the address and makes available for recycling
|
void |
free(long addr,
IAllocationContext context) |
void |
free(long addr,
int size)
Frees allocated storage (clears the bit to enable recycling after
the next commit).
|
ByteBuffer[] |
get(long addr)
Return an array of
ByteBuffers providing an updatable view onto
the backing allocation. |
long |
getAllocationCount()
The #of allocation spanned by this allocation context (including any
any child allocation contexts).
|
int |
getAssociatedSlotSize(int addr) |
Lock |
getCommitLock()
Optionally return a
Lock that must be used (when non-
null) to make the IStore.commit() / IStore.postCommit()
strategy atomic. |
CounterSet |
getCounters()
Return performance counters.
|
void |
getData(long l,
byte[] buf)
Read data of a known size from the store.
|
InputStream |
getInputStream(long addr)
Return an input stream from which a previously written stream may be read
back.
|
long |
getLastReleaseTime()
If history is retained this returns the time for which data was most
recently released.
|
int |
getMaxSectors()
The maximum number of backing buffers which may be allocated by the
IMemoryManager and Integer.MAX_VALUE if there is no
effective limit on the #of backing buffers which may be allocated. |
IPSOutputStream |
getOutputStream()
Return an output stream which can be used to write on the backing store.
|
IPSOutputStream |
getOutputStream(IAllocationContext context)
Return an output stream which can be used to write on the backing store
within the given allocation context.
|
long |
getPhysicalAddress(long addr)
Determine the unencoded physical address
|
int |
getSectorCount()
The #of backing buffers in use.
|
int |
getSectorSize()
The size of a backing buffer in bytes.
|
long |
getSlotBytes()
Return the #of bytes of consumed by allocation slots allocated against
this
IMemoryManager (including any child allocation contexts). |
File |
getStoreFile()
Retrieves store file.
|
long |
getUserBytes()
Return the #of bytes of application data allocated against this
IMemoryManager (including any child allocation contexts). |
boolean |
isCommitted(long addr)
Return
true iff the allocation having that address is
flagged as committed. |
boolean |
isIsolated() |
IAllocationContext |
newAllocationContext(boolean isolated)
Creates a context to be used to isolate updates to within the context until it
is released to the parent environment.
|
IRawTx |
newTx()
A hook used to support session protection by incrementing and
decrementing a transaction counter within the
IStore. |
void |
postCommit()
Hook that supports synchronization with an external commit before which
a rollback to "pre-commit" state is supported.
|
byte[] |
read(long addr)
Return a copy of the data stored at that address.
|
void |
registerExternalCache(ConcurrentWeakValueCache<Long,ICommitter> historicalIndexCache,
int byteCount)
Call made from AbstractJournal to register the cache used.
|
void |
release() |
long |
saveDeferrals()
Saves the current list of delete blocks, returning the address allocated.
|
long |
write(ByteBuffer data,
IAllocationContext context)
Write the data within the allocation context.
|
public AllocationContext(MemoryManager root, boolean isolated)
public AllocationContext(AllocationContext parent)
public final void checkActive()
checkActive in interface IAllocationContextpublic boolean isIsolated()
isIsolated in interface IAllocationContextpublic long allocate(ByteBuffer data)
IMemoryManagerIMemoryManager.allocate(ByteBuffer, boolean) which is either
blocking or non-blocking depending on whether or not the memory
manager is set in a blocking mode.allocate in interface IMemoryManagerdata - The data will be copied to the backing resource. For each
buffer in this array, the position will be advanced to the
limit.public long allocate(ByteBuffer data, boolean blocks)
IMemoryManagerallocate in interface IMemoryManagerdata - The data will be copied to the backing resource. For each
buffer in this array, the position will be advanced to the
limit.blocks - When true the request will block until the memory
is available for the allocation.public long allocate(int nbytes)
IMemoryManagerIMemoryManager.allocate(int).allocate in interface IMemoryManagernbytes - The size of the allocation request.public long allocate(int nbytes,
boolean blocks)
IMemoryManagerallocate in interface IMemoryManagernbytes - The size of the allocation request.blocks - When true the method will block until the
allocation request can be satisfied. When false a
MemoryManagerOutOfMemory will be thrown.public void clear()
IMemoryManagerIMemoryManager will release
any direct ByteBuffers back to the pool from which they were
allocated.
CAUTION: Do not clear an allocation context until you know that all threads with access to that allocation context have either been terminated or released their reference to that allocation context.
clear in interface IMemoryManagerpublic void free(long addr)
IMemoryManagerfree in interface IMemoryManageraddr - to be freedpublic ByteBuffer[] get(long addr)
IMemoryManagerByteBuffers providing an updatable view onto
the backing allocation.
The ByteBuffer[] return enables the handling of blobs that span more than
a single slot, without the need to create an intermediate ByteBuffer.
This method is designed for use with zero-copy NIO. Furthermore, since
the ByteBuffers in the returned array are not read-only, they can
be updated directly. In this way the IMemoryManager.allocate(int) can be used
in conjunction with get to provide more flexibility when storing data.
Using ByteBuffer:put the returned array can be efficiently copied to another ByteBuffer:
ByteBuffer mybb;
ByteBuffer[] bufs = get(addr);
for (ByteBuffer b : bufs) {
mybb.put(b);
}
CAUTION: Do not hold onto the ByteBuffer longer than is
necessary. If the allocation is released by IMemoryManager.free(long)
or IMemoryManager.clear(), then the memory backing the ByteBuffer could
be reallocated by another DirectBufferPool consumer.get in interface IMemoryManageraddr - An previously allocated address.public byte[] read(long addr)
IMemoryManagerIMemoryManager is treated as a
persistence store.read in interface IMemoryManageraddr - The address.public IMemoryManager createAllocationContext()
IMemoryManagerIAllocationContext as well (that
is, why does IMemoryManager not extend IAllocationContext
). Also, note that IStore.commit() is similar to
IAllocationManager.detachContext(IAllocationContext).createAllocationContext in interface IMemoryManagerpublic int allocationSize(long addr)
IMemoryManagerallocationSize in interface IMemoryManageraddr - The address.public long getAllocationCount()
IMemoryManagergetAllocationCount in interface IMemoryManagerpublic long getSlotBytes()
IMemoryManagerIMemoryManager (including any child allocation contexts).getSlotBytes in interface IMemoryManagerpublic long getUserBytes()
IMemoryManagerIMemoryManager (including any child allocation contexts). Due to
the overhead of the storage allocation scheme, this value may be smaller
than IMemoryManager.getSlotBytes().getUserBytes in interface IMemoryManagerpublic CounterSet getCounters()
ICounterSetAccessgetCounters in interface ICounterSetAccesspublic IPSOutputStream getOutputStream()
IStreamStoreIPSOutputStream.getOutputStream in interface IStreamStorepublic IPSOutputStream getOutputStream(IAllocationContext context)
IAllocationManagerStoreIPSOutputStream.getOutputStream in interface IAllocationManagerStorecontext - The context within which any allocations are made by the
returned IPSOutputStream.public InputStream getInputStream(long addr)
IStreamStoregetInputStream in interface IStreamStoreaddr - The address at which the stream was written.public long alloc(byte[] buf,
int size,
IAllocationContext context)
IStorepublic void close()
IStorepublic void free(long addr,
int size)
IStorepublic int getAssociatedSlotSize(int addr)
getAssociatedSlotSize in interface IStoreaddr - - the addresspublic void getData(long l,
byte[] buf)
IStorepublic File getStoreFile()
IStoregetStoreFile in interface IStorepublic int getSectorSize()
IMemoryManagergetSectorSize in interface IMemoryManagerpublic int getMaxSectors()
IMemoryManagerIMemoryManager and Integer.MAX_VALUE if there is no
effective limit on the #of backing buffers which may be allocated.getMaxSectors in interface IMemoryManagerpublic int getSectorCount()
IMemoryManagergetSectorCount in interface IMemoryManagerpublic void commit()
IStoreIStore.free(long, int) is now available for recycling.
However, recycling can not occur if session protection is active.public Lock getCommitLock()
IStoreLock that must be used (when non-
null) to make the IStore.commit() / IStore.postCommit()
strategy atomic.getCommitLock in interface IStorepublic void postCommit()
IStorepostCommit in interface IStorepublic void registerExternalCache(ConcurrentWeakValueCache<Long,ICommitter> historicalIndexCache, int byteCount)
IHistoryManagerNote: It is not safe to clear at the point of the delete request since the data could still be loaded if the data is retained for a period due to a non-zero retention period or session protection.
registerExternalCache in interface IHistoryManagerpublic int checkDeferredFrees(AbstractJournal abstractJournal)
IHistoryManagercheckDeferredFrees in interface IHistoryManagerAbstractJournal#commitNow()public IRawTx newTx()
IHistoryManagerIStore. As long as
a transaction is active we can not release data which is currently marked
as freed but was committed at the point the session started.newTx in interface IHistoryManagerpublic long saveDeferrals()
IHistoryManagerWrites the content of currentTxnFreeList to the store.
These are the current buffered frees that have yet been saved into a block referenced from the deferredFreeList
saveDeferrals in interface IHistoryManagerDeleteBlockCommitterpublic long getLastReleaseTime()
IHistoryManagergetLastReleaseTime in interface IHistoryManagerpublic void abortContext(IAllocationContext context)
IAllocationManagerabortContext in interface IAllocationManagercontext - The application object which serves as the allocation context.public void detachContext(IAllocationContext context)
IAllocationManagerIStore is the top-level parent of
allocation contexts. The allocators associated with the allocation
context are return to the global list of available allocators.detachContext in interface IAllocationManagercontext - The application object which serves as the allocation context.public boolean isCommitted(long addr)
IMemoryManagertrue iff the allocation having that address is
flagged as committed. The caller must be holding the allocation lock in
order for the result to remain valid outside of the method call.isCommitted in interface IMemoryManageraddr - The address.true iff the address is currently committed.public long getPhysicalAddress(long addr)
IMemoryManagergetPhysicalAddress in interface IMemoryManageraddr - The encoded addresspublic long allocate(ByteBuffer data, IAllocationContext context)
allocate in interface IMemoryManagerpublic long write(ByteBuffer data, IAllocationContext context)
IAllocationManagerStorewrite in interface IAllocationManagerStoredata - The data.context - The allocation context.public void free(long addr,
IAllocationContext context)
free in interface IMemoryManagerpublic void delete(long addr,
IAllocationContext context)
IAllocationManagerStoredelete in interface IAllocationManagerStoreaddr - The address whose allocation is to be deleted.context - The allocation context.public IAllocationContext newAllocationContext(boolean isolated)
IAllocationManagernewAllocationContext in interface IAllocationManagerpublic void release()
release in interface IAllocationContextCopyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.