class TransactableReadIfExistsWatcher extends SingletonQueryWatcher implements IfExistsWatcher, Transactable
QueryWatcher
for and transactional
readIfExists
queries. Resolves with the first
matching transition where the entry is visible to the associated
transaction and the entry is still available, or of the locked
entry set goes empty.Modifier and Type | Field and Description |
---|---|
private boolean |
backlogFinished
Set
true once the query thread is
done processing the backlog. |
private Set |
lockedEntries
The set of entries that would match but are currently
unavailable (e.g. they are locked).
|
private WeakHashMap |
provisionallyRemovedEntrySet
Set of entries (represented by
EntryHolder s) that
we would have liked to return, but have been provisionally
removed. |
private Txn |
txn
The transaction this query is
being performed under.
|
startOrdinal
ABORTED, ACTIVE, COMMITTED, NOTCHANGED, PREPARED, VOTING
Constructor and Description |
---|
TransactableReadIfExistsWatcher(long expiration,
long timestamp,
long startOrdinal,
Set lockedEntries,
WeakHashMap provisionallyRemovedEntrySet,
Txn txn)
Create a new
TransactableReadIfExistsWatcher . |
Modifier and Type | Method and Description |
---|---|
void |
abort(TransactableMgr mgr,
OutriggerServerImpl space)
If a transaction ends in the middle of a query we want
to throw an exception to the client making the query
(not the
Txn calling us here.) |
(package private) boolean |
catchUp(EntryTransition transition,
long now)
Process a transition which was posted before the watcher was
placed in
TransitionWatchers object. |
void |
caughtUp()
Once the backlog is complete we can resolve if
lockedEntries is/becomes empty.
|
void |
commit(TransactableMgr mgr,
OutriggerServerImpl space)
This should never happen since we always return
NOTCHANGED from prepare . |
(package private) boolean |
isInterested(EntryTransition transition,
long ordinal)
Return
true if this watcher cares about a given
visibility transition. |
boolean |
isLockedEntrySetEmpty()
If the query has been resolved by the locked entry set
becoming empty returns
true , otherwise
return false . |
int |
prepare(TransactableMgr mgr,
OutriggerServerImpl space)
If a transaction ends in the middle of a query we want
to throw an exception to the client making the query
not the
Txn calling us here.) |
(package private) void |
process(EntryTransition transition,
long now)
Process the given transition.
|
addTemplateHandle, getServer, isResolved, resolve, resolvedWithEntry, resolvedWithThrowable, waitOnResolution
getExpiration, removeIfExpired
compareTo
private final Set lockedEntries
private boolean backlogFinished
true
once the query thread is
done processing the backlog. Once this is
true
it is ok to resolve if
lockedEntries
is empty.private final Txn txn
private final WeakHashMap provisionallyRemovedEntrySet
EntryHolder
s) that
we would have liked to return, but have been provisionally
removed.TransactableReadIfExistsWatcher(long expiration, long timestamp, long startOrdinal, Set lockedEntries, WeakHashMap provisionallyRemovedEntrySet, Txn txn)
TransactableReadIfExistsWatcher
.expiration
- the initial expiration time
for this TransitionWatcher
in
milliseconds since the beginning of the epoch.timestamp
- the value that is used
to sort TransitionWatcher
s.startOrdinal
- the highest ordinal associated
with operations that are considered to have occurred
before the operation associated with this watcher.lockedEntries
- Set of entries (by their IDs)
that match but are unavailable. Must be non-empty.
Keeps a reference to this object.provisionallyRemovedEntrySet
- If the watcher encounters
an entry that can not be read/taken because it has been
provisionally removed then its handle will be placed in
this WeakHashMap
as a key (with null as the
value). May be null
in which case
provisionally removed entries will not be
recorded. Ensures that object is only accessed by one
thread at a timetxn
- If the query is being performed under
a transaction the Txn
object
associated with that transaction.NullPointerException
- if lockedEntries
or
txn
is null
.boolean isInterested(EntryTransition transition, long ordinal)
TransitionWatcher
true
if this watcher cares about a given
visibility transition. Assumes the transitioning entry matches
the template in the TemplateHandle
associated with
this watcher. This method should return a value even if the
expiration time has been reached or remove
has
been called. This call should not obtain any locks.isInterested
in class TransitionWatcher
transition
- A EntryTransition
that
describes the transition and what
entry is transitioning. This method
will assume that transition.getHandle
returns a non-null value.ordinal
- The ordinal associated with transition
.true
if this watcher is interested
in the indicated transition and false
otherwise.void process(EntryTransition transition, long now)
TransitionWatcher
TemplateHandle
associated with this
watcher and that isInterested
returned
true
. This call may make changes to the passed
EntryHandle
that will prevent it from being used by
other watchers. If remove
has been called or the
expiration time of this watcher has passed, this call should have no
effect. This call may cause the watcher to be removed.process
in class TransitionWatcher
transition
- A EntryTransition
that
describes the transition and what
entry is transitioning. This method
will assume that transition.getHandle
returns a non-null value.now
- An estimate of the current time (not the time
when the event occured).boolean catchUp(EntryTransition transition, long now)
QueryWatcher
TransitionWatchers
object. Assumes that
the entry in the transition matches matches the template in the
TemplateHandle
associated with this watcher. Does
not assume isInterested
has been called.catchUp
in class QueryWatcher
transition
- A EntryTransition
that
describes the transition and what
entry is transitioning. This method
will assume that transition.getHandle
returns a non-null value.now
- An estimate of the current time (not the time
when the event occured).true
if the query has been resolved, and
false
otherwise. Note, even if this
call returns true
, waitOnResolution
must still be called.public void caughtUp()
caughtUp
in interface IfExistsWatcher
public boolean isLockedEntrySetEmpty()
IfExistsWatcher
true
, otherwise
return false
.isLockedEntrySetEmpty
in interface IfExistsWatcher
true
if locked entry set
associated with this query is empty.public int prepare(TransactableMgr mgr, OutriggerServerImpl space)
Txn
calling us here.)prepare
in interface Transactable
public void commit(TransactableMgr mgr, OutriggerServerImpl space)
NOTCHANGED
from prepare
.commit
in interface Transactable
public void abort(TransactableMgr mgr, OutriggerServerImpl space)
Txn
calling us here.)abort
in interface Transactable
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.