@Override public void run() { try { LOGGER.info("inside run of onCommit"); WriteSet writeSet = WriteSet.getLocal(); ReadSet readSet = ReadSet.getLocal(); VersionClock.setWriteStamp(); long writeVersion = VersionClock.getWriteStamp(); for (Map.Entry<LockObject<?>, Object> entry : writeSet.getList()) { LockObject<?> key = entry.getKey(); Copyable<?> destination = null; try { destination = key.openRead(); } catch (AbortedException | PanicException e) { e.printStackTrace(); } Copyable<Copyable<?>> source = (Copyable<Copyable<?>>) entry.getValue(); source.copyTo(destination); key.stamp = writeVersion; } writeSet.unlock(); writeSet.clear(); readSet.clear(); Transaction.getLocal().clearKarma(); } catch (Exception e) { e.printStackTrace(); } }
@Override public Boolean call() throws Exception { WriteSet writeSet = WriteSet.getLocal(); ReadSet readSet = ReadSet.getLocal(); if (!writeSet.tryLock(TIMEOUT, TimeUnit.MILLISECONDS)) { LOGGER.info("writeSet try lock returned false"); return false; } for (LockObject<?> x : readSet.getList()) { if (x.lock.isLocked() && !x.lock.isHeldByCurrentThread()) { /* try { LOGGER.info("Resolving contention at time of read consistency check"); ContentionManager.getLocal().resolve(Transaction.getLocal(), x.locker); } catch (AbortedException e) { return false; } */ return false; } if (x.stamp > VersionClock.getReadStamp()) { LOGGER.info("Inconsistent version error: Stamp > Version CLOCK"); return false; } } return true; }
@Override public boolean commit() { try { if (writeSet.isEmpty()) // if the writeSet is empty no need to lock a thing. return true; try { // pre commit validation phase writeSet.forEach(lockProcedure); readSet.checkClock(localClock); } catch (TransactionException exception) { lockProcedure.unlockAll(); return false; } // commit new values and release locks writeSet.forEach(putProcedure); lockProcedure.setAndUnlockAll(); return true; } finally { if (irrevocableState) { irrevocableState = false; irrevocableAccessLock.writeLock().unlock(); } else { irrevocableAccessLock.readLock().unlock(); } } }
@Override public void beforeReadAccess(Object obj, long field, int advice) { ReadFieldAccess next = readSet.getNext(); currentReadFieldAccess = next; next.init(obj, field, advice); // Check the read is still valid lastReadLock = LockTable.checkLock(next.hashCode(), localClock); }
@Override public void run() { WriteSet.getLocal().unlock(); WriteSet.getLocal().clear(); ReadSet.getLocal().clear(); }