|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.faunos.skwish.Segment com.faunos.skwish.TxnSegment
public abstract class TxnSegment
A Segment
transaction. The idea is to support multiple
concurrent writers to a same logical whole segment. Each instance of this
class supports a single bulk commit to the logical whole. That is,
changes to the segment (both new entry insertions, and detetions of existing
entries) are not saved until committed,
and then only in all-or-nothing fashion.
TxnSegment
works with the union of two logical segments.
This is a read-only view of the already committed segments. It is a snapshot with respect to the fact that the size of the view (the number of entries) is fixed when the transaction (a new instance of this class) is first created and does not grow even while other TxnSegments are committed. This read-only view is live in every other respect--that is, deletes committed through other transactions become immediately visible to this view.
This "snapshot" segment contains entries with ids in the semi-open range [baseId, txnBaseId). (The txnBaseId property of the TxnSegment instance, is set at construction time to equal the nextId property of the [union of the] already committed segments.)
This segment contains newly inserted entries that have yet to be committed. Ids of newly inserted entries begin at the txnBaseId property of the instance.
txnId
on inserting new entries. This txnId (transaction id) is an
immutable property. After the transaction is committed, a committed entry's
id can be determined by
entryId += SegmentStore.getTxnCommitIdGap(txnId)
.
SegmentStore.newTransaction()
,
SegmentStore.getTxnCommitIdGap(long)
Field Summary |
---|
Fields inherited from class com.faunos.skwish.Segment |
---|
validator |
Constructor Summary | |
---|---|
TxnSegment()
|
Method Summary | |
---|---|
abstract long |
commit()
Commits the transaction and returns the commit ID. |
abstract void |
discard()
Discards this transaction. |
abstract FileChannel |
getEntryInsertionChannel()
Returns a read-write FileChannel for the next entry. |
abstract FileChannel |
getEntryUpdateChannel(long id)
Returns a read-write FileChannel on the entry with the
specified id . |
abstract long |
getTxnBaseId()
Returns the transaction base ID, if not discarded; -1, o.w. |
abstract long |
getTxnCommitId()
Returns the transaction commit ID, if committed; -1, o.w. |
long |
getTxnCommitIdGap()
Returns the difference between the commit ID and the transaction base ID, if the instance is already committed; -1, o.w. |
abstract long |
getTxnId()
Returns the transaction ID for this instance. |
boolean |
isAlive()
Determines whether the instance is alive. |
boolean |
isCommitted()
Determines whether the instance is committed. |
boolean |
isDiscarded()
Determines whether the instance is discarded. |
Methods inherited from class com.faunos.skwish.Segment |
---|
contains, delete, delete, delete, getBaseId, getEntry, getEntry, getEntryChannel, getEntryCount, getEntryPart, getEntrySize, getEntrySize, getEntryStream, getNextId, hi, insertEntry, insertEntry, isDeleted, isDeleted, isReadOnly, killNext, killNext, lo, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TxnSegment()
Method Detail |
---|
public abstract long getTxnId() throws IOException
IOException
SegmentStore.getTxnCommitIdGap(long)
public abstract long getTxnBaseId()
discard()
public abstract long commit() throws IOException
After an instance has been committed, no more changes can be written to the segment.
IOException
getTxnCommitId()
public abstract void discard() throws IOException
Segment
method, raises an exception. On return,
the transaction base ID is set to -1.
Throw this instance away after invoking this method: there's little you
can do with it.
IOException
public abstract long getTxnCommitId()
public final long getTxnCommitIdGap()
public final boolean isAlive()
public final boolean isCommitted()
getTxnCommitId()
public final boolean isDiscarded()
getTxnBaseId()
public abstract FileChannel getEntryUpdateChannel(long id) throws IOException
FileChannel
on the entry with the
specified id
. Note that the size of the entry may not
be changed. Also, the id must belong to a newly created uncommitted entry
within this transaction. (We don't yet support updating already
committed entries.)
Reminder: Be sure to close the returned channel when you
are done.
FileChannel
on the contents of the
entry with the specified id
, if the entry exists;
null
, o.w.
IOException
public abstract FileChannel getEntryInsertionChannel() throws IOException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |