wasInterrupted = false;
Logger.debug("Validating: " + ObjectsRegistery.getKey(((AbstractDistinguishable)obj).getId()));
if(!LockTable.lock(obj, locksMarker, deadline_ts, tid)){
Logger.fetal("Remote Obj for commit " + obj);
GlobalObject globalObject = ObjectsRegistery.getKey(((AbstractDistinguishable)obj).getId());
if(globalObject==null) { // object was deleted
throw new TransactionException();
}
Logger.debug("Lock request - Realtime Deadline = " + deadline_ts.getSeconds() + " " + deadline_ts.getNanoseconds());
try {
LockTable.remoteLockRequest(this, globalObject, deadline_ts, period_ts, tid);
} catch (InterruptedException exception) {
wasInterrupted = true;
}
if(!pendingLock){
Logger.debug("Remote lock refused");
throw new TransactionException();
}
}
++lockedCounter;
// Check for expired deadline
if(edu.vt.rt.hyflow.benchmark.Benchmark.getAbortHandler().wasAborted(ChronosUtil.gettid()))
throw new TransactionException();
if(wasInterrupted == true)
throw new InterruptedException();
}
Logger.debug("Validate Read-Set");
readSet.checkClock( localClock, true);
}
catch(TransactionException exception){
DTL2Directory.threadPhaseMap.put(tid, DTL2Directory.IN_COMMIT_PHASE);
Logger.debug("Invalid Read-Set");
for(AbstractDistinguishable obj : writeSet){
if( lockedCounter-- == 0)
break;
Logger.fetal("Releasing " + obj);
if(!LockTable.unLock(obj, locksMarker)) {
LockTable.remoteUnlockRequest(ObjectsRegistery.getKey(((AbstractDistinguishable)obj).getId()), deadline_ts, period_ts, tid);
}
Logger.fetal("Unlocked " + obj + " by thread = " + tid);
}
if(DTL2Directory.priorityRaised_ThreadMap.get(tid) == DTL2Directory.PRIORITY_RAISED) {
Logger.fetal("Reset Priority === on Abort " + tid);
DTL2Directory.priorityRaised_ThreadMap.put(tid, DTL2Directory.PRIORITY_NOT_RAISED);
ChronosScheduler.reset_self_deadline_priority(deadline_ts);
}
DTL2Directory.threadPhaseMap.put(tid, DTL2Directory.NOT_IN_COMMIT_PHASE);
return false;
} catch (InterruptedException exception) {
DTL2Directory.threadPhaseMap.put(tid, DTL2Directory.IN_COMMIT_PHASE);
Logger.debug("Invalid Read-Set");
for(AbstractDistinguishable obj : writeSet){
if( lockedCounter-- == 0)
break;
Logger.fetal("Releasing " + obj);
if(!LockTable.unLock(obj, locksMarker)) {
LockTable.remoteUnlockRequest(ObjectsRegistery.getKey(((AbstractDistinguishable)obj).getId()), deadline_ts, period_ts, tid);
}
Logger.fetal("Unlocked " + obj + " by thread = " + tid);
}
if(DTL2Directory.priorityRaised_ThreadMap.get(tid) == DTL2Directory.PRIORITY_RAISED) {
Logger.fetal("Reset Priority === on Abort " + tid);
DTL2Directory.priorityRaised_ThreadMap.put(tid, DTL2Directory.PRIORITY_NOT_RAISED);
ChronosScheduler.reset_self_deadline_priority(deadline_ts);
}
DTL2Directory.threadPhaseMap.put(tid, DTL2Directory.NOT_IN_COMMIT_PHASE);
return false;
}
Logger.debug("Now going to finish commit");
DTL2Directory.threadPhaseMap.put(tid, DTL2Directory.IN_COMMIT_PHASE);
ConcurrentHashMap<Object, Address> objPrevOwnerAddressMap = new ConcurrentHashMap<Object, Address>();
// store object's previous owner address.. will be used to wakeup waiting Tx
for(Object obj : writeSet){
GlobalObject globalObject = ObjectsRegistery.getKey(((AbstractDistinguishable)obj).getId());
if(globalObject!=null)
objPrevOwnerAddressMap.put(obj, globalObject.getHome().getAddress());
}
final int newClock = LocalClock.increment();
canBeAborted = false;
Logger.debug("Commit values to objects");
for( WriteObjectAccess writeField : this.writeSet)
writeField.put(); // commit value to field
Logger.debug("Publish newly created objects");
for(AbstractDistinguishable object : lazyPublish) {
new GlobalObject(object, object.getId()); // populate me as this object owner
Logger.fetal("Populate me as Owner for " + object);
}
DirectoryManager locator = HyFlow.getLocator();
Logger.debug("Unregister deleted objects");
for(AbstractDistinguishable object : lazyDelete){
GlobalObject key = ObjectsRegistery.getKey(object.getId());
locator.unregister(key); // unregister this object
PE.thisPE().populate(new UnregisterObject(key)); // unregister this object from other nodes
Logger.fetal("Unregister " + object);
}
Logger.debug("Release Write-Set");
for(AbstractDistinguishable obj: writeSet){
if(LockTable.setAndReleaseLock( obj, newClock, locksMarker)){ // is it remote
AbstractDistinguishable object = (AbstractDistinguishable)obj;
GlobalObject key = ObjectsRegistery.getKey(object.getId());
if(key==null){
System.out.println("TTTTT:"+object.getId());
continue;
}
key.setHome(PE.thisPE()); // me is the new owner
ObjectsRegistery.regsiterObject(key); // register key local
locator.newObject(key, object); // register at the directory manager
PE.thisPE().populate(new RegisterObject(key)); // populate me as the new owner
Logger.debug("Populate me owner of " + key);
// FIXME: if more than one local transaction at this node then we should release the object now not before changing its location
}
}
//System.out.println(" Wake up other tasks " + tid);
for(Object obj : objPrevOwnerAddressMap.keySet()) {
//System.out.println("From my address " + PE.thisPE().getAddress() + " Send signal request to " + obj + " owner" + objPrevOwnerAddressMap.get(obj));
if(!objPrevOwnerAddressMap.get(obj).equals(PE.thisPE().getAddress())) {
//try {
AbstractDistinguishable object = (AbstractDistinguishable)obj;
GlobalObject key = ObjectsRegistery.getKey(object.getId());
//CommunicationManager.getManager().send(objPrevOwnerAddressMap.get(obj), new SignalWaitingTxRequest(key, tid, obj, deadline_ts, period_ts));
TransactionWaitQueue.remoteWaitQueueRequest(this, key, object);
//} catch (IOException ex) {
// ex.printStackTrace();
//}