@InterfaceAudience.Private public class MultiVersionConcurrencyControl extends Object
Modifier and Type | Class and Description |
---|---|
static class |
MultiVersionConcurrencyControl.WriteEntry
Write number and whether write has completed given out at start of a write transaction.
|
Modifier and Type | Field and Description |
---|---|
static long |
FIXED_SIZE |
private static org.slf4j.Logger |
LOG |
static long |
NONE
Represents no value, or not set.
|
(package private) AtomicLong |
readPoint |
private Object |
readWaiters |
(package private) AtomicLong |
writePoint |
private LinkedList<MultiVersionConcurrencyControl.WriteEntry> |
writeQueue |
Constructor and Description |
---|
MultiVersionConcurrencyControl() |
MultiVersionConcurrencyControl(long startPoint)
Construct and set read point.
|
Modifier and Type | Method and Description |
---|---|
void |
advanceTo(long newStartPoint)
Step the MVCC forward on to a new read/write basis.
|
void |
await()
Wait until the read point catches up to the write point; i.e.
|
MultiVersionConcurrencyControl.WriteEntry |
begin()
Call
begin(Runnable) with an empty Runnable . |
MultiVersionConcurrencyControl.WriteEntry |
begin(Runnable action)
Start a write transaction.
|
boolean |
complete(MultiVersionConcurrencyControl.WriteEntry writeEntry)
Mark the
MultiVersionConcurrencyControl.WriteEntry as complete and advance the read point as much as possible. |
void |
completeAndWait(MultiVersionConcurrencyControl.WriteEntry e)
Complete a
MultiVersionConcurrencyControl.WriteEntry that was created by begin() then wait until the
read point catches up to our write. |
long |
getReadPoint() |
long |
getWritePoint() |
String |
toString() |
(package private) boolean |
tryAdvanceTo(long newStartPoint,
long expected)
Step the MVCC forward on to a new read/write basis.
|
(package private) void |
waitForRead(MultiVersionConcurrencyControl.WriteEntry e)
Wait for the global readPoint to advance up to the passed in write entry number.
|
private static final org.slf4j.Logger LOG
final AtomicLong readPoint
final AtomicLong writePoint
private final Object readWaiters
public static final long NONE
private final LinkedList<MultiVersionConcurrencyControl.WriteEntry> writeQueue
public static final long FIXED_SIZE
public MultiVersionConcurrencyControl()
public MultiVersionConcurrencyControl(long startPoint)
public void advanceTo(long newStartPoint)
newStartPoint
- boolean tryAdvanceTo(long newStartPoint, long expected)
newStartPoint
- Point to move read and write points to.expected
- If not -1 (#NONE)expected
is not equal to the
current readPoint
or if startPoint
is less than current
readPoint
public MultiVersionConcurrencyControl.WriteEntry begin()
begin(Runnable)
with an empty Runnable
.public MultiVersionConcurrencyControl.WriteEntry begin(Runnable action)
MultiVersionConcurrencyControl.WriteEntry
with a new write number and add it
to our queue of ongoing writes. Return this WriteEntry instance. To complete the write
transaction and wait for it to be visible, call completeAndWait(WriteEntry)
. If the
write failed, call complete(WriteEntry)
so we can clean up AFTER removing ALL trace of
the failed write transaction.
The action
will be executed under the lock which means it can keep the same order with
mvcc.
complete(WriteEntry)
,
completeAndWait(WriteEntry)
public void await()
public void completeAndWait(MultiVersionConcurrencyControl.WriteEntry e)
MultiVersionConcurrencyControl.WriteEntry
that was created by begin()
then wait until the
read point catches up to our write.
At the end of this call, the global read point is at least as large as the write point
of the passed in WriteEntry. Thus, the write is visible to MVCC readers.public boolean complete(MultiVersionConcurrencyControl.WriteEntry writeEntry)
MultiVersionConcurrencyControl.WriteEntry
as complete and advance the read point as much as possible.
Call this even if the write has FAILED (AFTER backing out the write transaction
changes completely) so we can clean up the outstanding transaction.
How much is the read point advanced?
Let S be the set of all write numbers that are completed. Set the read point to the highest
numbered write of S.writeEntry
- void waitForRead(MultiVersionConcurrencyControl.WriteEntry e)
public long getReadPoint()
public long getWritePoint()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.