public class MemStrategy extends Object implements IBufferStrategy, IRWStrategy, IAllocationManagerStore
IMemoryManager
.NULL
Constructor and Description |
---|
MemStrategy(IMemoryManager mmgr) |
Modifier and Type | Method and Description |
---|---|
void |
abort()
A method that requires the implementation to discard its buffered write
set (if any).
|
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.
|
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 |
close()
Close the store immediately.
|
void |
closeForWrites()
Seals the store against further writes and discards any write caches
since they will no longer be used.
|
void |
commit()
A method that removes assumptions of how a specific strategy commits
data.
|
void |
delete(long addr)
Delete the data (unisolated).
|
void |
delete(long addr,
IAllocationContext context)
Delete the data associated with the address within the allocation
context.
|
void |
deleteResources()
Deletes the backing file(s) (if any).
|
void |
destroy()
Closes the store immediately (if open) and deletes its persistent
resources.
|
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 |
force(boolean metadata)
Force the data to stable storage.
|
IAddressManager |
getAddressManager() |
BufferMode |
getBufferMode()
The buffer mode supported by the implementation
|
int |
getByteCount(long addr)
The length of the datum in bytes.
|
Lock |
getCommitLock()
Optionally return a
Lock that must be used (when non-
null ) to make the IBufferStrategy.commit() /
IRWStrategy.postCommit() strategy atomic. |
CounterSet |
getCounters()
Return the performance counter hierarchy.
|
long |
getExtent()
The current size of the journal in bytes.
|
File |
getFile()
The backing file -or-
null if there is no backing file
for the store. |
int |
getHeaderSize()
The size of the journal header, including MAGIC, version, and both root
blocks.
|
long |
getInitialExtent()
The initial extent.
|
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.
|
long |
getMaximumExtent()
The maximum extent allowable before a buffer overflow operation will be
rejected.
|
int |
getMaxRecordSize() |
long |
getMetaBitsAddr()
The RWStrategy requires meta allocation info in the root block, this
method is the hook to enable access.
|
long |
getMetaStartAddr()
The RWStrategy requires meta allocation info in the root block, this
method is the hook to enable access.
|
long |
getNextOffset()
The next offset at which a data item would be written on the store as an
offset into the user extent.
|
long |
getOffset(long addr)
The offset on the store at which the datum is stored.
|
int |
getOffsetBits() |
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
|
IResourceMetadata |
getResourceMetadata()
A description of this store in support of the scale-out architecture.
|
IMemoryManager |
getStore()
Return the backing
IStore . |
long |
getUserExtent()
The size of the user data extent in bytes.
|
UUID |
getUUID()
|
boolean |
isCommitted(long addr)
Return
true iff the allocation having that address is
flagged as committed. |
boolean |
isDirty()
Return
true if the store has been modified since the last
IBufferStrategy.commit() or IBufferStrategy.abort() . |
boolean |
isFullyBuffered()
True iff the store is fully buffered (all reads are against memory).
|
boolean |
isOpen()
true iff the store is open. |
boolean |
isReadOnly()
true iff the store does not allow writes. |
boolean |
isStable()
True iff backed by stable storage.
|
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()
Called post commit to dispose any transient commit state retained to
support reset/rollback.
|
ByteBuffer |
read(long addr)
Read the data (unisolated).
|
ByteBuffer |
readRootBlock(boolean rootBlock0)
Read the specified root block from the backing file.
|
void |
registerExternalCache(ConcurrentWeakValueCache<Long,ICommitter> historicalIndexCache,
int byteCount)
Call made from AbstractJournal to register the cache used.
|
boolean |
requiresCommit(IRootBlockView block)
A method that removes assumptions of how a specific strategy determines
whether a transaction commit is required.
|
long |
saveDeferrals()
Saves the current list of delete blocks, returning the address allocated.
|
long |
size()
The #of application data bytes written on the store (does not count any
headers or root blocks that may exist for the store).
|
long |
toAddr(int nbytes,
long offset)
Converts a byte count and offset into a long integer.
|
String |
toString(long addr)
A human readable representation of the address.
|
long |
transferTo(RandomAccessFile out)
A block operation that transfers the serialized records (aka the written
on portion of the user extent) en mass from the buffer onto an output
file.
|
void |
truncate(long extent)
Either truncates or extends the journal.
|
boolean |
useChecksums()
Return
true if the store uses per-record checksums. |
long |
write(ByteBuffer data)
Write the data (unisolated).
|
long |
write(ByteBuffer data,
IAllocationContext context)
FIXME There are two unit tests for the
MemStore which are failing
due to this method not being implemented. |
void |
writeRootBlock(IRootBlockView rootBlock,
ForceEnum forceOnCommitEnum)
Write the root block onto stable storage (ie, flush it through to disk).
|
public MemStrategy(IMemoryManager mmgr)
public IMemoryManager getStore()
IRWStrategy
IStore
.getStore
in interface IRWStrategy
public void abort()
IBufferStrategy
abort
in interface IBufferStrategy
public void closeForWrites()
IBufferStrategy
closeForWrites
in interface IBufferStrategy
public void commit()
IBufferStrategy
commit
in interface IBufferStrategy
public Lock getCommitLock()
IRWStrategy
Lock
that must be used (when non-
null
) to make the IBufferStrategy.commit()
/
IRWStrategy.postCommit()
strategy atomic.getCommitLock
in interface IRWStrategy
public void postCommit()
IRWStrategy
Note: It is the responsibility of the commit protocol layers to wind up
calling IBufferStrategy.abort()
if there is a failure during the
commit protocol.
postCommit
in interface IRWStrategy
public IAddressManager getAddressManager()
getAddressManager
in interface IBufferStrategy
public BufferMode getBufferMode()
IBufferStrategy
getBufferMode
in interface IBufferStrategy
public CounterSet getCounters()
IBufferStrategy
getCounters
in interface ICounterSetAccess
getCounters
in interface IBufferStrategy
public long getExtent()
IBufferStrategy
Options.INITIAL_EXTENT
.getExtent
in interface IBufferStrategy
public int getHeaderSize()
IBufferStrategy
getHeaderSize
in interface IBufferStrategy
public long getInitialExtent()
IBufferStrategy
getInitialExtent
in interface IBufferStrategy
public int getMaxRecordSize()
getMaxRecordSize
in interface IBufferStrategy
public long getMaximumExtent()
IBufferStrategy
Note: The semantics here differ from those defined by
Options.MAXIMUM_EXTENT
. The latter specifies the threshold at
which a journal will overflow (onto another journal) while this specifies
the maximum size to which a buffer is allowed to grow.
Note: This is normally zero (0L), which basically means that
the maximum extent is ignored by the IBufferStrategy
but
respected by the AbstractJournal
, resulting in a soft limit
on journal overflow.
getMaximumExtent
in interface IBufferStrategy
0L
iff no limit is imposed.public long getMetaBitsAddr()
IBufferStrategy
getMetaBitsAddr
in interface IBufferStrategy
public long getMetaStartAddr()
IBufferStrategy
getMetaStartAddr
in interface IBufferStrategy
public long getNextOffset()
IBufferStrategy
getNextOffset
in interface IBufferStrategy
public int getOffsetBits()
getOffsetBits
in interface IBufferStrategy
public long getUserExtent()
IBufferStrategy
Note: The size of the user extent is always generally smaller than the
value reported by IBufferStrategy.getExtent()
since the latter also reports the
space allocated to the journal header and root blocks.
getUserExtent
in interface IBufferStrategy
public ByteBuffer readRootBlock(boolean rootBlock0)
IBufferStrategy
readRootBlock
in interface IBufferStrategy
public boolean requiresCommit(IRootBlockView block)
IBufferStrategy
requiresCommit
in interface IBufferStrategy
block
- The root block held by the client, can be checked against the
state of the Buffer Strategypublic long transferTo(RandomAccessFile out) throws IOException
IBufferStrategy
Note: Implementations of this method MUST be synchronized so that the operation is atomic with respect to concurrent writers.
transferTo
in interface IBufferStrategy
out
- The file to which the buffer contents will be transferred.IOException
public void truncate(long extent)
IBufferStrategy
Note: Implementations of this method MUST be synchronized so that the operation is atomic with respect to concurrent writers.
truncate
in interface IBufferStrategy
extent
- The new extent of the journal. This value represent the total
extent of the journal, including any root blocks together with
the user extent.public boolean useChecksums()
IBufferStrategy
true
if the store uses per-record checksums. When
true
, an additional 4 bytes are written after the record on
the disk. Those bytes contain the checksum of the record.useChecksums
in interface IBufferStrategy
public void writeRootBlock(IRootBlockView rootBlock, ForceEnum forceOnCommitEnum)
IBufferStrategy
writeRootBlock
in interface IBufferStrategy
rootBlock
- The root block. Which root block is indicated by
IRootBlockView.isRootBlock0()
.public void close()
IRawStore
public void delete(long addr)
IRawStore
After this operation subsequent reads on the address MAY fail and the caller MUST NOT depend on the ability to read at that address.
public void deleteResources()
IRawStore
deleteResources
in interface IRawStore
public void destroy()
IRawStore
IllegalStateException
if the store
is already closed, but still deletes the backing resources.destroy
in interface IRawStore
IRawStore.deleteResources()
public void force(boolean metadata)
IRawStore
public File getFile()
IRawStore
null
if there is no backing file
for the store.public IResourceMetadata getResourceMetadata()
IRawStore
getResourceMetadata
in interface IRawStore
public boolean isFullyBuffered()
IRawStore
Note: This does not guarantee that the OS will not swap the buffer onto disk.
isFullyBuffered
in interface IRawStore
public boolean isOpen()
IRawStore
true
iff the store is open.public boolean isReadOnly()
IRawStore
true
iff the store does not allow writes.isReadOnly
in interface IRawStore
public boolean isStable()
IRawStore
public ByteBuffer read(long addr)
IRawStore
read
in interface IRawStore
addr
- A long integer that encodes both the offset from which the
data will be read and the #of bytes to be read. See
IAddressManager.toAddr(int, long)
.public long size()
IRawStore
public long write(ByteBuffer data)
IRawStore
write
in interface IRawStore
data
- The data. The bytes from the current
Buffer.position()
to the
Buffer.limit()
will be written and the
Buffer.position()
will be advanced to the
Buffer.limit()
. The caller may subsequently
modify the contents of the buffer without changing the state
of the store (i.e., the data are copied into the store).IAddressManager
.public int getByteCount(long addr)
IAddressManager
IRawStore
.getByteCount
in interface IAddressManager
addr
- The opaque identifier that is the within store locator for
some datum.public long getOffset(long addr)
IAddressManager
getOffset
in interface IAddressManager
addr
- The opaque identifier that is the within store locator for
some datum.public long getPhysicalAddress(long addr)
IAddressManager
getPhysicalAddress
in interface IAddressManager
addr
- The encoded addresspublic long toAddr(int nbytes, long offset)
IAddressManager
toAddr
in interface IAddressManager
nbytes
- The byte count.offset
- The byte offset.public String toString(long addr)
IAddressManager
toString
in interface IAddressManager
addr
- The opaque identifier that is the within store locator for
some datum.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 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 int checkDeferredFrees(AbstractJournal abstractJournal)
IHistoryManager
checkDeferredFrees
in interface IHistoryManager
AbstractJournal#commitNow()
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 long getLastReleaseTime()
IHistoryManager
getLastReleaseTime
in interface IHistoryManager
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 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 write(ByteBuffer data, IAllocationContext context)
MemStore
which are failing
due to this method not being implemented. Those methods are using an
abstract task within an isolated action journal context.write
in interface IAllocationManagerStore
data
- The data.context
- The allocation context.public boolean isCommitted(long addr)
IRWStrategy
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 IRWStrategy
addr
- The address.true
iff the address is currently committed.public InputStream getInputStream(long addr)
IStreamStore
getInputStream
in interface IStreamStore
addr
- The address at which the stream was written.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 boolean isDirty()
IBufferStrategy
true
if the store has been modified since the last
IBufferStrategy.commit()
or IBufferStrategy.abort()
.isDirty
in interface IBufferStrategy
IBufferStrategy.commit()
or
IBufferStrategy.abort()
.public IAllocationContext newAllocationContext(boolean isolated)
IAllocationManager
newAllocationContext
in interface IAllocationManager
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.