Beispiel #1
0
        /// <summary>
        /// Aborts a transaction on this server
        /// </summary>
        /// <param name="tid">transaction identifier</param>
        /// <param name="usedPadInts">Identifiers of PadInts involved</param>
        /// <returns>A predicate confirming the sucess of the operations</returns>
        internal override bool Abort(int tid, List <int> usedPadInts)
        {
            Logger.Log(new String[] { "PrimaryServer", Server.ID.ToString(), "abort", "tid", tid.ToString() });

            bool resultAbort = true;

            try {
                VerifyPadInts(usedPadInts);

                foreach (int padIntUid in usedPadInts)
                {
                    PadInt padInt = GetPadInt(padIntUid);
                    resultAbort = padInt.Abort(tid) && resultAbort;
                }
            } catch (PadIntNotFoundException) {
                throw;
            }

            /* updates the backup server */
            backupReplyTimer.Start();
            BackupServer.Abort(tid, usedPadInts);
            backupReplyTimer.Stop();

            return(resultAbort);
        }
Beispiel #2
0
        /// <summary>
        /// Writes a value in a PadInt
        /// </summary>
        /// <param name="tid">Transaction identifier</param>
        /// <param name="uid">PadInt identifier</param>
        /// <param name="value">Value of the write</param>
        /// <returns>True if successful</returns>
        internal override bool WritePadInt(int tid, int uid, int value)
        {
            Logger.Log(new String[] { "Server ", Server.ID.ToString(), " writePadInt ", "tid", tid.ToString(), "uid", uid.ToString(), "value", value.ToString() });

            try {
                /* Obtain the PadInt identified by uid */
                PadInt padInt = GetPadInt(uid);

                while (true)
                {
                    if (padInt.GetWriteLock(tid))
                    {
                        padInt.ActualValue = value;
                        /* updates the backup server */
                        backupReplyTimer.Start();
                        BackupServer.WritePadInt(tid, uid, value);
                        backupReplyTimer.Stop();
                        return(true);
                    }
                }
            } catch (PadIntNotFoundException) {
                throw;
            } catch (AbortException) {
                throw;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns the value of the PadInt when the transaction has the read/write lock.
        ///  Throws an exception if PadInt not found.
        /// </summary>
        /// <param name="tid">Transaction identifier</param>
        /// <param name="uid">PadInt identifier</param>
        /// <returns></returns>
        internal override int ReadPadInt(int tid, int uid)
        {
            Logger.Log(new String[] { "PrimaryServer", Server.ID.ToString(), "readPadInt ", "tid", tid.ToString(), "uid", uid.ToString() });

            try {
                /* Obtain the PadInt identified by uid */
                PadInt padInt = GetPadInt(uid);

                while (true)
                {
                    if (padInt.HasWriteLock(tid) || padInt.GetReadLock(tid))
                    {
                        /* updates the backup server */
                        backupReplyTimer.Start();
                        BackupServer.ReadPadInt(tid, uid);
                        backupReplyTimer.Stop();
                        return(padInt.ActualValue);
                    }
                }
            } catch (PadIntNotFoundException) {
                throw;
            } catch (AbortException) {
                throw;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Aborts a transaction on this server
        /// </summary>
        /// <param name="tid">transaction identifier</param>
        /// <param name="usedPadInts">Identifiers of PadInts involved</param>
        /// <returns>A predicate confirming the sucess of the operations</returns>
        internal override bool Abort(int tid, List <int> usedPadInts)
        {
            Logger.Log(new String[] { "BackupServer", Server.ID.ToString(), "abort", "tid", tid.ToString() });

            bool resultAbort = true;

            try {
                VerifyPadInts(usedPadInts);

                foreach (int padIntUid in usedPadInts)
                {
                    PadInt padInt = GetPadInt(padIntUid);
                    resultAbort = padInt.Abort(tid) && resultAbort;
                }
            } catch (PadIntNotFoundException) {
                throw;
            }

            return(resultAbort);
        }
Beispiel #5
0
        /* Returns the value of the PadInt when the transaction
         *  has the read/write lock.
         * Throw an exception if PadInt not found.
         */
        internal override int ReadPadInt(int tid, int uid)
        {
            Logger.Log(new String[] { "BackupServer", Server.ID.ToString(), "readPadInt ", "tid", tid.ToString(), "uid", uid.ToString() });

            try {
                /* Obtain the PadInt identified by uid */
                PadInt padInt = GetPadInt(uid);

                if (padInt.HasWriteLock(tid) || padInt.GetReadLock(tid))
                {
                    return(padInt.ActualValue);
                }
            } catch (PadIntNotFoundException) {
                throw;
            } catch (AbortException) {
                throw;
            }

            return(-1);
        }
Beispiel #6
0
        internal override bool WritePadInt(int tid, int uid, int value)
        {
            Logger.Log(new String[] { "Server ", Server.ID.ToString(), " writePadInt ", "tid", tid.ToString(), "uid", uid.ToString(), "value", value.ToString() });

            try {
                /* Obtain the PadInt identified by uid */
                PadInt padInt = GetPadInt(uid);

                if (padInt.GetWriteLock(tid))
                {
                    padInt.ActualValue = value;
                    return(true);
                }
            } catch (PadIntNotFoundException) {
                throw;
            } catch (AbortException) {
                throw;
            }

            return(false);
        }