/// <summary> /// Periodically runs and remove older tentitive rights to prvent deadlock /// </summary> public void TentativeWriteTimeOutMonitor(Object state) { try { if (!isThisServerFailed && !IsThisServerFreezed && !isShufflingActive) { PADI_Coordinator coordinator = (PADI_Coordinator)Activator.GetObject(typeof(PADI_Coordinator), Common.GetCoordinatorTcpUrl()); long tid = 0; foreach (var item in padIntActiveList) { if (item.Value.TentativeList.Count > 1) { if (DateTime.Now.Subtract(item.Value.TentativeList[0].CreatedTimeStamp).Seconds > 3) { tid = item.Value.TentativeList[0].WriteTS; coordinator.AbortTxn(tid); item.Value.TentativeList[1].CreatedTimeStamp = DateTime.Now; Console.WriteLine("TentativeWriteTimeOutMonitor order abort to TID = " + tid); } } } } } catch (Exception ex) { Console.WriteLine("TentativeWriteTimeOutMonitor :" + ex.Message); } }
/// <summary> /// Write the value to the UID within the transaction TID /// </summary> /// <param name="uid"></param> /// <param name="TID"></param> /// <param name="value"></param> public void Write(int uid, long TID, int value) { bool isWriteSuccessful = padIntActiveList[uid].Write(TID, value); lock (this) { if (isThisServerFreezed) { Monitor.Wait(this); } } if (!isWriteSuccessful) { PADI_Coordinator coordinator = (PADI_Coordinator)Activator.GetObject(typeof(PADI_Coordinator), Common.GetCoordinatorTcpUrl()); coordinator.AbortTxn(TID); Console.WriteLine("Write aborted TID=" + TID); // throw new TxException("Write aborted TID=" + TID); } }
public static bool Init() { bool isInitSuccessful = false; try { //TODO:Load the Info object when start and save it when client exit. Currently new object is created. coordinator = (PADI_Coordinator)Activator.GetObject(typeof(PADI_Coordinator), Common.GenerateTcpUrl(ConfigurationManager.AppSettings[Constants.APPSET_MASTER_IP], ConfigurationManager.AppSettings[Constants.APPSET_MASTER_PORT], Constants.OBJECT_TYPE_PADI_COORDINATOR)); master = (PADI_Master)Activator.GetObject(typeof(PADI_Master), Common.GetMasterTcpUrl()); workers = new List <PADI_Worker>(); info = new Information(); padIntUids = new List <int>(); LoadServerMap(); isInitSuccessful = true; } catch (Exception ex) { Console.WriteLine(ex.Message); } return(isInitSuccessful); }