|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.service.AbstractService
com.bigdata.service.AbstractTransactionService
public abstract class AbstractTransactionService
Centalized transaction manager service. In response to a client request, the transaction manager will distribute prepare/commit or abort operations to all data services on which writes were made by a transaction. The transaction manager also provides global timestamps required for non-transactional commit points and various other purposes.
| Nested Class Summary | |
|---|---|
static interface |
AbstractTransactionService.Options
Options understood by this service. |
protected class |
AbstractTransactionService.TxState
Transaction state as maintained by the ITransactionService. |
| Field Summary | |
|---|---|
protected CounterSet |
countersRoot
|
protected static boolean |
DEBUG
|
protected static String |
ERR_NO_SUCH
If the transaction is not known to this service. |
protected static String |
ERR_NOT_ACTIVE
If a transaction is no longer active. |
protected static String |
ERR_READ_ONLY
If the transaction is read-only and a write operation was requested. |
protected static String |
ERR_SERVICE_NOT_AVAIL
If the transaction service is not in a run state which permits the requested operation. |
protected static boolean |
INFO
|
protected ReentrantLock |
lock
A lock used to serialize certain operations that must be atomic with respect to the state of the transaction service. |
protected static org.apache.log4j.Logger |
log
Logger. |
protected CommitTimeIndex |
startTimeIndex
A transient index holding the absolute value of the start times of all active transactions. |
protected Condition |
txDeactivate
Signalled by deactivateTx(TxState). |
| Constructor Summary | |
|---|---|
AbstractTransactionService(Properties properties)
|
|
| Method Summary | |
|---|---|
void |
abort(long tx)
Abort the transaction (asynchronous). |
protected abstract void |
abortImpl(AbstractTransactionService.TxState state)
Implementation must abort the tx on the journal (standalone) or on each data service (federation) on which it has written. |
protected void |
activateTx(AbstractTransactionService.TxState state)
Adds the transaction from to the local tables. |
protected void |
assertOpen()
|
protected long |
assignTransactionIdentifier(long timestamp)
Assign a transaction identifier for a new transaction. |
long |
commit(long tx)
Request commit of the transaction write set. |
protected abstract long |
commitImpl(AbstractTransactionService.TxState state)
Implementation must either single-phase commit (standalone journal or a transaction that only writes on a single data service) or 2-/3-phase commit (distributed transaction running on a federation). |
protected void |
deactivateTx(AbstractTransactionService.TxState state)
Removes the transaction from the local tables. |
void |
declareResources(long tx,
UUID dataServiceUUID,
String[] resource)
Note: Only those DataServices on which a read-write transaction
has started will participate in the commit. |
void |
destroy()
Immediate/fast shutdown of the service and then destroys any persistent state associated with the service. |
protected abstract long |
findCommitTime(long timestamp)
Find the commit time from which the tx will read (largest commitTime LTE timestamp). |
protected abstract long |
findNextCommitTime(long commitTime)
Return the commit time for the successor of that commit point have the specified timestamp (a commit time strictly GT the given value). |
protected long |
findUnusedTimestamp(long commitTime,
long nextCommitTime,
long timeout,
TimeUnit unit)
Find a valid, unused timestamp. |
long |
getAbortCount()
#of transaction aborted. |
int |
getActiveCount()
The #of open transactions in any RunState. |
long |
getCommitCount()
#of transaction committed. |
CounterSet |
getCounters()
Return the CounterSet. |
abstract long |
getLastCommitTime()
Note: Declared abstract so that we can hide the IOException. |
long |
getMinReleaseAge()
Return the minimum #of milliseconds of history that must be preserved. |
protected Properties |
getProperties()
An object wrapping the properties used to initialize the service. |
long |
getReadOnlyActiveCount()
|
long |
getReadWriteActiveCount()
|
long |
getReleaseTime()
Return the timestamp whose historical data MAY be release. |
TxServiceRunState |
getRunState()
Return the RunState. |
Class |
getServiceIface()
Return the most interesting interface for the service. |
long |
getStartCount()
#of transaction started. |
protected long |
getStartTime(long timestamp)
Assign a distinct timestamp to a historical read that will read from the commit point identified by the specified timestamp. |
boolean |
isOpen()
Any state other than TxServiceRunState.Halted. |
long |
newTx(long timestamp)
Note: There is an upper bound of one read-write transaction that may be created per millisecond (the resolution of nextTimestamp()) and
requests for new read-write transactions contend with other requests for
nextTimestamp(). |
long |
nextTimestamp()
Return the next unique timestamp. |
void |
notifyCommit(long commitTime)
The basic implementation advances the release time periodically as commits occur even when there are no transactions in use. |
protected void |
setReleaseTime(long newValue)
Sets the new release time. |
protected void |
setRunState(TxServiceRunState newval)
Change the TxServiceRunState. |
void |
shutdown()
Polite shutdown. |
void |
shutdownNow()
Fast shutdown (not immediate since it must abort active transactions). |
AbstractTransactionService |
start()
Verifies that nextTimestamp() will not report a time before
getLastCommitTime() and then changes the TxServiceRunState
to TxServiceRunState.Running. |
protected void |
updateReleaseTime(long timestamp)
This method is invoked each time a transaction completes with the absolute value of the transaction identifier that has just been deactivated. |
| Methods inherited from class com.bigdata.service.AbstractService |
|---|
clearLoggingContext, getFederation, getHostname, getServiceName, getServiceUUID, setServiceUUID, setupLoggingContext |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.bigdata.journal.ITransactionService |
|---|
committed, prepared |
| Methods inherited from interface com.bigdata.service.IService |
|---|
getHostname, getServiceName, getServiceUUID |
| Field Detail |
|---|
protected static final org.apache.log4j.Logger log
protected static final boolean INFO
protected static final boolean DEBUG
protected static final transient String ERR_READ_ONLY
protected static final transient String ERR_NO_SUCH
protected static final transient String ERR_NOT_ACTIVE
protected static final transient String ERR_SERVICE_NOT_AVAIL
protected final ReentrantLock lock
protected final Condition txDeactivate
deactivateTx(TxState).
protected final CommitTimeIndex startTimeIndex
Note: The absolute value constraint is imposed so that we can directly identify the earliest active transaction in the index by its position (it will be at position zero). This would not work if we let in negative start times.
Note: In order to support this, #findUnusedTimestamp(long, long)
will not return a timestamp whose absolute value corresponds to an active
transaction.
protected CounterSet countersRoot
| Constructor Detail |
|---|
public AbstractTransactionService(Properties properties)
| Method Detail |
|---|
protected Properties getProperties()
public final int getActiveCount()
RunState.
public boolean isOpen()
TxServiceRunState.Halted.
isOpen in interface IServiceShutdownprotected void assertOpen()
public TxServiceRunState getRunState()
RunState.
protected void setRunState(TxServiceRunState newval)
TxServiceRunState.
newval - The new value.
IllegalStateException - if the requested state is not a legal state change.public void shutdown()
shutdown in interface IServiceShutdownshutdown in class AbstractServicepublic void shutdownNow()
New transactions will not start and active transactions will be aborted.
Transactions which are concurrently committing MAY fail (throwing
exceptions from various methods, including nextTimestamp())
when the service halts.
shutdownNow in interface IServiceShutdownshutdownNow in class AbstractServicepublic void destroy()
destroy in interface IServicedestroy in class AbstractServicepublic final long nextTimestamp()
ITimestampServiceNote: This method MUST return strictly increasing values, even when it is invoked by concurrent threads. While other implementations are possible and may be more efficient, one way to insure thread safety is to synchronize on some object such that the implementaiton exhibits a FIFO behavior.
nextTimestamp in interface ITimestampServiceTimestampServiceUtil.nextTimestamp(ITimestampService)public long newTx(long timestamp)
nextTimestamp()) and
requests for new read-write transactions contend with other requests for
nextTimestamp().
Note: The transaction service will refuse to start new transactions whose
timestamps are LTE to #getEarliestTxStartTime().
newTx in interface ITransactionServicetimestamp - The timestamp may be:
ITx.READ_COMMITTED to
obtain a read-historical transaction reading from the most
recently committed state of the database. The transaction will
be assigned a start time corresponding to the most recent
commit point of the database and will be a fully isolated
read-only view of the state of the database as of that start
time. (This is an atomic shorthand for
newTx(getLastCommitTime())).ITx.UNISOLATED for a read-write transaction.RuntimeException - Wrapping TimeoutException if a timeout occurs
awaiting a start time which would satisify the request for a
read-only transaction (this can occur only for read-only
transactions which must contend for start times which will
read from the appropriate historical commit point).public long getStartCount()
public long getAbortCount()
public long getCommitCount()
public long getReadOnlyActiveCount()
public long getReadWriteActiveCount()
public long getReleaseTime()
ITransactionService
getReleaseTime in interface ITransactionServiceAbstractTransactionService.Options.MIN_RELEASE_AGEprotected void setReleaseTime(long newValue)
newValue - The new value.protected void activateTx(AbstractTransactionService.TxState state)
state - The transaction.protected void deactivateTx(AbstractTransactionService.TxState state)
state - The transaction.protected final void updateReleaseTime(long timestamp)
startTimeIndex). If the specified
timestamp corresponds to the earliest running transaction, then the
releaseTime will be updated and the new releaseTime will
be set using setReleaseTime(long).
Note that the startTimeIndex contains the absolute value of the
transaction identifers!
timestamp - The absolute value of a transaction identifier that has just
been deactivated.startTimeIndex could be used by
#findUnusedTimestamp(long, long) so that it could further
constrain its search within the half-open interval.public void notifyCommit(long commitTime)
Note: This needs to be a fairly low-latency operation since this method is invoked for all commits on all data services and will otherwise be a global hotspot.
notifyCommit in interface ITransactionServicecommitTime - The commit time.public final long getMinReleaseAge()
If minReleaseTime is increased, then the release time can be changed to match, but only by NOT advancing it until we are retaining enough history.
If minReleaseTime is decreased, then we can immediately release more history (or at least as soon as the task runs to notify the discovered data services of the new release time).
protected long assignTransactionIdentifier(long timestamp)
throws InterruptedException,
TimeoutException
timestamp - The timestamp.
InterruptedException - if interrupted while awaiting a start time which would
satisify the request.
InterruptedException - if a timeout occurs while awaiting a start time which would
satisify the request.
TimeoutException
protected long getStartTime(long timestamp)
throws InterruptedException,
TimeoutException
Note: Under some circumstances the assignment of a read-only transaction identifier must be delayed until a distinct timestamp becomes available between the designed start time and the next commit point.
timestamp - The timestamp (identifies the desired commit point).
InterruptedException
TimeoutExceptionprotected abstract long findCommitTime(long timestamp)
timestamp - The timestamp.
protected abstract long findNextCommitTime(long commitTime)
commitTime - The probe.
protected long findUnusedTimestamp(long commitTime,
long nextCommitTime,
long timeout,
TimeUnit unit)
throws InterruptedException,
TimeoutException
Note: Any timestamp in the half-open range [commitTime:nextCommitTime) MAY be assigned as all such timestamps will read from the commit point associated with [commitTime].
commitTime - The commit time for the commit point on which the tx will read
(this must be the exact timestamp associated with the desired
commit point).nextCommitTime - The commit time for the successor of that commit point.timeout - The maximum length of time to await an available timestamp.unit - The unit in which timeout is expressed.
InterruptedException
TimeoutExceptionpublic abstract long getLastCommitTime()
IOException.
getLastCommitTime in interface ITransactionService
protected abstract void abortImpl(AbstractTransactionService.TxState state)
throws Exception
Pre-conditions:
RunState.Active; andAbstractTransactionService.TxState.lock.Post-conditions:
RunState.Aborted; andJournal
or IDataService or which it has written (applicable for
read-write transactions only).
state - The transaction state as maintained by the transaction server.
Exception
protected abstract long commitImpl(AbstractTransactionService.TxState state)
throws Exception
Pre-conditions:
RunState.Active; andAbstractTransactionService.TxState.lock.Post-conditions (success for read-only transaction or a read-write transaction with an empty write set):
RunState.Committed; andPost-conditions (success for read-write transaction with a non-empty write set):
RunState.Committed;Journal or IDataService or which it has written
(applicable for read-write transactions only); andPost-conditions (failure):
RunState.Aborted; andJournal
or IDataService or which it has written (applicable for
read-write transactions only).
tx - The transaction identifier.
Exception - if something else goes wrong. This will be (or will wrap) a
ValidationError if validation fails.public void abort(long tx)
abort in interface ITransactionServicetx - The transaction identifier.
public long commit(long tx)
throws ValidationError
ITransactionService
The commit of a transaction with a write set on a single
IDataService does not require either ITx.UNISOLATED tasks
or other transactions to wait. The latency for such commits is directly
related to the size of the transaction write set.
However, the commit of a transaction with writes on more than one
IDataService requires a distributed commit protocol. The
distributed commit protocol forces ALL tasks writing on those
IDataServices to wait until the transaction is complete. This is
necessary in order to obtain a global commit point that corresponds to
the atomic commit state of the transaction (without this we would not
have the Atomic property for distributed transaction commits).
commit in interface ITransactionServicetx - The transaction identifier.
ValidationError - if the transaction could not be validated.
public void declareResources(long tx,
UUID dataServiceUUID,
String[] resource)
throws IllegalStateException
DataServices on which a read-write transaction
has started will participate in the commit. If there is only a single
such IDataService, then a single-phase commit will be used.
Otherwise a distributed transaction commit protocol will be used.
Note: The commits requests are placed into a partial order by sorting the
total set of resources which the transaction declares (via this method)
across all operations executed by the transaction and then contending for
locks on the named resources using a LockManager. This is
handled by the DistributedTransactionService.
declareResources in interface ITransactionServicetx - The transaction identifier.dataServiceUUID - The UUID an IDataService on which the
transaction will write.resource - An array of the named resources which the transaction will use
on that IDataService (this may be different for each
operation submitted by that transaction to the
IDataService).
IllegalStateExceptionpublic AbstractTransactionService start()
nextTimestamp() will not report a time before
getLastCommitTime() and then changes the TxServiceRunState
to TxServiceRunState.Running.
start in class AbstractServicepublic Class getServiceIface()
AbstractService
getServiceIface in interface IServicegetServiceIface in class AbstractServicepublic CounterSet getCounters()
CounterSet.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||