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
ByteBuffer s 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 IAllocationContext
public boolean isIsolated()
isIsolated
in interface IAllocationContext
public long allocate(ByteBuffer data)
IMemoryManager
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.allocate
in interface IMemoryManager
data
- 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)
IMemoryManager
allocate
in interface IMemoryManager
data
- 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)
IMemoryManager
IMemoryManager.allocate(int)
.allocate
in interface IMemoryManager
nbytes
- The size of the allocation request.public long allocate(int nbytes, boolean blocks)
IMemoryManager
allocate
in interface IMemoryManager
nbytes
- 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()
IMemoryManager
IMemoryManager
will release
any direct ByteBuffer
s 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 IMemoryManager
public void free(long addr)
IMemoryManager
free
in interface IMemoryManager
addr
- to be freedpublic ByteBuffer[] get(long addr)
IMemoryManager
ByteBuffer
s 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 ByteBuffer
s 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 IMemoryManager
addr
- An previously allocated address.public byte[] read(long addr)
IMemoryManager
IMemoryManager
is treated as a
persistence store.read
in interface IMemoryManager
addr
- The address.public IMemoryManager createAllocationContext()
IMemoryManager
IAllocationContext
as well (that
is, why does IMemoryManager
not extend IAllocationContext
). Also, note that IStore.commit()
is similar to
IAllocationManager.detachContext(IAllocationContext)
.createAllocationContext
in interface IMemoryManager
public int allocationSize(long addr)
IMemoryManager
allocationSize
in interface IMemoryManager
addr
- The address.public long getAllocationCount()
IMemoryManager
getAllocationCount
in interface IMemoryManager
public long getSlotBytes()
IMemoryManager
IMemoryManager
(including any child allocation contexts).getSlotBytes
in interface IMemoryManager
public long getUserBytes()
IMemoryManager
IMemoryManager
(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 IMemoryManager
public CounterSet getCounters()
ICounterSetAccess
getCounters
in interface ICounterSetAccess
public IPSOutputStream getOutputStream()
IStreamStore
IPSOutputStream
.getOutputStream
in interface IStreamStore
public IPSOutputStream getOutputStream(IAllocationContext context)
IAllocationManagerStore
IPSOutputStream
.getOutputStream
in interface IAllocationManagerStore
context
- The context within which any allocations are made by the
returned IPSOutputStream
.public InputStream getInputStream(long addr)
IStreamStore
getInputStream
in interface IStreamStore
addr
- The address at which the stream was written.public long alloc(byte[] buf, int size, IAllocationContext context)
IStore
public void close()
IStore
public void free(long addr, int size)
IStore
public int getAssociatedSlotSize(int addr)
getAssociatedSlotSize
in interface IStore
addr
- - the addresspublic void getData(long l, byte[] buf)
IStore
public File getStoreFile()
IStore
getStoreFile
in interface IStore
public int getSectorSize()
IMemoryManager
getSectorSize
in interface IMemoryManager
public int getMaxSectors()
IMemoryManager
IMemoryManager
and Integer.MAX_VALUE
if there is no
effective limit on the #of backing buffers which may be allocated.getMaxSectors
in interface IMemoryManager
public int getSectorCount()
IMemoryManager
getSectorCount
in interface IMemoryManager
public void commit()
IStore
IStore.free(long, int)
is now available for recycling.
However, recycling can not occur if session protection is active.public Lock getCommitLock()
IStore
Lock
that must be used (when non-
null
) to make the IStore.commit()
/ IStore.postCommit()
strategy atomic.getCommitLock
in interface IStore
public void postCommit()
IStore
postCommit
in interface IStore
public void registerExternalCache(ConcurrentWeakValueCache<Long,ICommitter> historicalIndexCache, int byteCount)
IHistoryManager
Note: 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 IHistoryManager
public int checkDeferredFrees(AbstractJournal abstractJournal)
IHistoryManager
checkDeferredFrees
in interface IHistoryManager
AbstractJournal#commitNow()
public IRawTx newTx()
IHistoryManager
IStore
. 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 IHistoryManager
public long saveDeferrals()
IHistoryManager
Writes 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 IHistoryManager
DeleteBlockCommitter
public long getLastReleaseTime()
IHistoryManager
getLastReleaseTime
in interface IHistoryManager
public void abortContext(IAllocationContext context)
IAllocationManager
abortContext
in interface IAllocationManager
context
- The application object which serves as the allocation context.public void detachContext(IAllocationContext context)
IAllocationManager
IStore
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 IAllocationManager
context
- The application object which serves as the allocation context.public boolean isCommitted(long addr)
IMemoryManager
true
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 IMemoryManager
addr
- The address.true
iff the address is currently committed.public long getPhysicalAddress(long addr)
IMemoryManager
getPhysicalAddress
in interface IMemoryManager
addr
- The encoded addresspublic long allocate(ByteBuffer data, IAllocationContext context)
allocate
in interface IMemoryManager
public long write(ByteBuffer data, IAllocationContext context)
IAllocationManagerStore
write
in interface IAllocationManagerStore
data
- The data.context
- The allocation context.public void free(long addr, IAllocationContext context)
free
in interface IMemoryManager
public void delete(long addr, IAllocationContext context)
IAllocationManagerStore
delete
in interface IAllocationManagerStore
addr
- The address whose allocation is to be deleted.context
- The allocation context.public IAllocationContext newAllocationContext(boolean isolated)
IAllocationManager
newAllocationContext
in interface IAllocationManager
public void release()
release
in interface IAllocationContext
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.