Merge branch '2.0.12-SNAPSHOT' into develop

This commit is contained in:
Greg Burd 2017-08-09 15:00:46 -04:00
commit 62e2e75dfc

View file

@ -10,56 +10,58 @@ import java.util.function.Function;
*/ */
public class UnitOfWork { public class UnitOfWork {
private final HelenusSession session; private final HelenusSession session;
private ArrayList<UnitOfWork> nested; private ArrayList<UnitOfWork> nested;
UnitOfWork(HelenusSession session) { UnitOfWork(HelenusSession session) {
this.session = session; this.session = session;
// log.record(txn::start) // log.record(txn::start)
} }
/** /**
* Marks the beginning of a transactional section of work. Will write a record * Marks the beginning of a transactional section of work. Will write a record
* to the shared write-ahead log. * to the shared write-ahead log.
* *
* @return the handle used to commit or abort the work. * @return the handle used to commit or abort the work.
*/ */
public UnitOfWork begin() { public UnitOfWork begin() {
if (nested == null) { if (nested == null) {
nested = new ArrayList<UnitOfWork>(); nested = new ArrayList<UnitOfWork>();
} }
UnitOfWork unitOfWork = new UnitOfWork(session); UnitOfWork unitOfWork = new UnitOfWork(session);
nested.add(unitOfWork); nested.add(unitOfWork);
return unitOfWork; return unitOfWork;
} }
/** /**
* Checks to see if the work performed between calling begin and now can be * Checks to see if the work performed between calling begin and now can be
* committed or not. * committed or not.
* *
* @return a function from which to chain work that only happens when commit is successful * @return a function from which to chain work that only happens when commit is successful
* @throws ConflictingUnitOfWorkException * @throws ConflictingUnitOfWorkException when the work overlaps with other concurrent writers.
* when the work overlaps with other concurrent writers. */
*/ public Function<Void, Void> commit() throws ConflictingUnitOfWorkException {
public Function<Void, Void> commit() throws ConflictingUnitOfWorkException { if (nested != null) {
nested.forEach((uow) -> Errors.rethrow().wrap(uow::commit)); nested.forEach((uow) -> Errors.rethrow().wrap(uow::commit));
// log.record(txn::provisionalCommit) }
// examine log for conflicts in read-set and write-set between begin and provisional commit // log.record(txn::provisionalCommit)
// if (conflict) { throw new ConflictingUnitOfWorkException(this) } // examine log for conflicts in read-set and write-set between begin and provisional commit
// if (conflict) { throw new ConflictingUnitOfWorkException(this) }
// else return function so as to enable commit.andThen(() -> { do something iff commit was successful; }) // else return function so as to enable commit.andThen(() -> { do something iff commit was successful; })
return Function.<Void>identity(); return Function.<Void>identity();
} }
/** /**
* Explicitly discard the work and mark it as as such in the log. * Explicitly discard the work and mark it as as such in the log.
*/ */
public void abort() { public void abort() {
// log.record(txn::abort) // log.record(txn::abort)
// cache.invalidateSince(txn::start time) // cache.invalidateSince(txn::start time)
} }
public String describeConflicts() { public String describeConflicts() {
return "it's complex..."; return "it's complex...";
} }
} }
:q