public class OptimisticTransactionalContext extends AbstractTransactionalContext
Optimistic transactions in Corfu provide the following isolation guarantees:
(1) Read-your-own Writes: Reads in a transaction are guaranteed to observe a write in the same transaction, if a write happens before the read.
(2) Opacity: Read in a transaction observe the state of the system ("snapshot") as of the time of the first read which occurs in the transaction ("first read timestamp"), except in case (1) above where they observe the own transaction's writes.
(3) Atomicity: Writes in a transaction are guaranteed to commit atomically, and commit if and only if none of the objects which were read (the "read set") were modified between the first read ("first read timestamp") and the time of commit.
Created by mwei on 4/4/16.
ABORTED_ADDRESS, commitAddress, completionFuture, FOLDED_ADDRESS, NOWRITE_ADDRESS, startTime, transaction, transactionID, UNCOMMITTED_ADDRESS
Modifier and Type | Method and Description |
---|---|
<R,T> R |
access(ICorfuSMRProxyInternal<T> proxy,
ICorfuSMRAccess<R,T> accessFunction,
Object[] conflictObject)
Access within optimistic transactional context is implemented
in via proxy.access() as follows:
|
void |
addTransaction(AbstractTransactionalContext tc)
Commit a transaction into this transaction by merging the read/write
sets.
|
long |
commitTransaction()
Commit the transaction.
|
long |
getConflictSetAndCommit(ConflictSetInfo conflictSet)
Commit with a given conflict set and return the address.
|
<T> Object |
getUpcallResult(ICorfuSMRProxyInternal<T> proxy,
long timestamp,
Object[] conflictObject)
if a Corfu object's method is an Accessor-Mutator, then although the mutation is delayed,
it needs to obtain the result by invoking getUpcallResult() on the optimistic stream.
|
<T> long |
logUpdate(ICorfuSMRProxyInternal<T> proxy,
SMREntry updateEntry,
Object[] conflictObjects)
Logs an update.
|
protected void |
tryCommitAllProxies()
Try to commit the optimistic updates to each proxy.
|
protected void |
updateAllProxies(Consumer<ICorfuSMRProxyInternal> function) |
abortTransaction, addToReadSet, compareTo, syncWithRetryUnsafe, toString
public <R,T> R access(ICorfuSMRProxyInternal<T> proxy, ICorfuSMRAccess<R,T> accessFunction, Object[] conflictObject)
1. First, we try to grab a read-lock on the proxy, and hope to "catch" the proxy in the snapshot version. If this succeeds, we invoke the corfu-object access method, and un-grab the read-lock.
2. Otherwise, we grab a write-lock on the proxy and bring it to the correct version - Inside proxy.setAsOptimisticStream, if there are currently optimistic updates on the proxy, we roll them back. Then, we set this transactional context as the proxy's new optimistic context. - Then, inside proxy.syncObjectUnsafe, depending on the proxy version, we may need to undo or redo committed changes, or apply forward committed changes. Access the state of the object.
access
in class AbstractTransactionalContext
R
- The return type of the access function.T
- The type of the proxy's underlying object.proxy
- The proxy to access the state for.accessFunction
- The function to execute, which will be provided with the state
of the object.conflictObject
- Fine-grained conflict information, if available.public <T> Object getUpcallResult(ICorfuSMRProxyInternal<T> proxy, long timestamp, Object[] conflictObject)
This is similar to the second stage of access(), accept working on the optimistic stream instead of the underlying stream.- grabs the write-lock on the proxy. - uses proxy.setAsOptimisticStream in order to set itself as the proxy optimistic context, including rolling-back current optimistic changes, if any. - uses proxy.syncObjectUnsafe to bring the proxy to the desired version, which includes applying optimistic updates of the current transactional context. Get the result of an upcall.
getUpcallResult
in class AbstractTransactionalContext
T
- The type of the proxy's underlying object.proxy
- The proxy to retrieve the upcall for.timestamp
- The timestamp to return the upcall for.conflictObject
- Fine-grained conflict information, if available.public <T> long logUpdate(ICorfuSMRProxyInternal<T> proxy, SMREntry updateEntry, Object[] conflictObjects)
Return the "address" of the update; used for retrieving results from operations via getUpcallResult.
logUpdate
in class AbstractTransactionalContext
T
- The type of the proxy.proxy
- The proxy making the request.updateEntry
- The timestamp of the request.conflictObjects
- Fine-grained conflict information, if available.public void addTransaction(AbstractTransactionalContext tc)
addTransaction
in class AbstractTransactionalContext
tc
- The transaction to merge.public long commitTransaction() throws TransactionAbortedException
commitTransaction
in class AbstractTransactionalContext
TransactionAbortedException
- If the transaction was aborted.public long getConflictSetAndCommit(ConflictSetInfo conflictSet)
conflictSet
- conflict set used to check whether transaction can commitprotected void tryCommitAllProxies()
protected void updateAllProxies(Consumer<ICorfuSMRProxyInternal> function)
Copyright © 2019 CorfuDB. All rights reserved.