示例#1
0
 public void finishAllActiveTx(Dictionary <TransactionId, object> activeTX, Boolean isCommit)
 {
     lock (CLASS_LOCK)
     {
         Util.Log("In Finish active map count is {0}", activeTX.Count);
         keyList = new List <TransactionId>(activeTX.Keys);
         bool txCompleted = false;
         for (int i = 0; i < keyList.Count; i++)
         {
             TransactionId txId   = (TransactionId)(object)keyList[i];
             TxInfo        txInfo = (TxInfo)(object)activeTX[txId];
             try
             {
                 txCompleted = commit(txInfo);
                 Util.Log("Commit got {0}", txCompleted);
             }
             catch (Exception e)
             {
                 FwkTest <TKey, TVal> .CurrentTest.FwkException("Got this exception {0}", e);
             }
             finally
             {
                 activeTX.Remove(txId);
             }
             Util.Log("After commit/update the Active Map is {0}", activeTX.Count);
         }
     }
 }
示例#2
0
        public bool commit(TxInfo txInfo)
        {
            TransactionId           id        = (TransactionId)(object)txInfo.getTxId();
            bool                    commited  = false;
            CacheTransactionManager txManager = null;

            txManager = CacheHelper <TKey, TVal> .DCache.CacheTransactionManager;
            if (txManager.TryResume(id, 30000))
            {
                try
                {
                    txManager.Commit();
                    commited = true;
                }
                catch (CommitConflictException ex)
                {
                    //Expected exception with concurrent transactions.
                    Util.Log("Got expected exception {0}", ex);
                }
                catch (TransactionDataRebalancedException ex)
                {
                    FwkTest <TKey, TVal> .CurrentTest.FwkException("Got {0}", ex);
                }
                catch (TransactionDataNodeHasDepartedException ex)
                {
                    FwkTest <TKey, TVal> .CurrentTest.FwkException("Got {0}", ex);
                }
            }
            else
            {
                Util.Log("TxId {0} is not suspended in this member with tryResume time limit, cannot commit.  Expected, continuing test.");
            }
            Util.Log("Commited returning {0}", commited);
            return(commited);
        }
示例#3
0
        public TxInfo begin(IRegion <TKey, TVal> region)
        {
            CacheTransactionManager txManager = null;
            IRegion <TKey, TVal>    reg       = region;
            TransactionId           id        = null;
            TxInfo txInfo = new TxInfo();

            txManager = CacheHelper <TKey, TVal> .DCache.CacheTransactionManager;
            try
            {
                txManager.Begin();
                try
                {
                    kCount++;
                    TKey key   = (TKey)(object)(kCount);
                    TVal value = GetValue();
                    reg[key] = value;
                    Util.Log("The Key is={0} and value={1}", key.ToString(), value.ToString());
                }
                catch (Exception e)
                {
                    FwkTest <TKey, TVal> .CurrentTest.FwkException("Caught {0}", e);
                }
            }
            catch (IllegalStateException e)
            {
                FwkTest <TKey, TVal> .CurrentTest.FwkException("Caught {0}", e);
            }
            try
            {
                id = txManager.Suspend();
                Util.Log("Suspend() complete ");
            }
            catch (IllegalStateException e)
            {
                FwkTest <TKey, TVal> .CurrentTest.FwkException("Got {0}", e);
            }
            Util.Log("BEGIN_TX returning txId = {0}", id);
            try
            {
                txInfo.setTxId(id);
            }
            catch (Exception e)
            {
                FwkTest <TKey, TVal> .CurrentTest.FwkException("Got this {0}", e);
            }

            return(txInfo);
        }
示例#4
0
        public void rollback(TxInfo txInfo)
        {
            TransactionId           id        = (TransactionId)(object)txInfo.getTxId();
            CacheTransactionManager txManager = null;
            bool isRollBack = false;

            txManager = CacheHelper <TKey, TVal> .DCache.CacheTransactionManager;
            if (txManager.TryResume(id, 30000))
            {
                txManager.Rollback();
                isRollBack = true;
            }
            else
            {
                Util.Log("TxId {0} is not suspended in this member with tryResume time limit, cannot rollback.  Expected with concurrent execution, continuing test.");
            }
            Util.Log("RollbackTx returning {0}", isRollBack);
        }
示例#5
0
        public void executeTxOps(TxInfo txInfo)
        {
            //This will do a resume+doOps+suspend
            TransactionId           id        = (TransactionId)(object)txInfo.getTxId();
            CacheTransactionManager txManager = null;

            txManager = CacheHelper <TKey, TVal> .DCache.CacheTransactionManager;
            bool executedOps  = false;
            int  numOfOpsToDo = 5;

            if (txManager.TryResume(id, 30000))
            {
                try
                {
                    doEntryOps(numOfOpsToDo);
                    executedOps = true;
                }
                catch (TransactionDataNodeHasDepartedException ex)
                {
                    FwkTest <TKey, TVal> .CurrentTest.FwkException("Caught {0}", ex);
                }
                catch (TransactionDataRebalancedException ex)
                {
                    FwkTest <TKey, TVal> .CurrentTest.FwkException("Caught {0}", ex);
                }
                catch (Exception ex)
                {
                    FwkTest <TKey, TVal> .CurrentTest.FwkException("Caught unexpected exception during doEntryOps task {0}", ex.Message);
                }
                finally
                {
                    id = txManager.Suspend();
                    Util.Log("Suspend() complete txId is {0}", id);
                }
            }
            Util.Log("EXECUTE_TX returned  {0}", executedOps);
        }
示例#6
0
        public void doTransactions(IRegion <TKey, TVal> region)//,Dictionary<TransactionId, object> m_maps)
        {
            Util.Log("Inside ResumableTx:doTransactions()");
            TransactionId txId = null;
            //String txIdStr = "";
            TxInfo txInfo            = null;
            IRegion <TKey, TVal> reg = region;
            int action = 0;

            FwkTest <TKey, TVal> .CurrentTest.ResetKey("minExecutions");

            int minExecutions = FwkTest <TKey, TVal> .CurrentTest.GetUIntValue("minExecutions");

            int numExecutions = 0;

            Util.Log("activeTx map count is {0}", activeTxns.Count);
            if (activeTxns.Count > 0)
            {
                try
                {
                    keyList = new List <TransactionId>(activeTxns.Keys);
                }
                catch (Exception e) { FwkTest <TKey, TVal> .CurrentTest.FwkException("Inside keylist exception  {0}", e); }
            }
            FwkTest <TKey, TVal> .CurrentTest.ResetKey("numThreads");

            string NUMTHREADS = "numThreads";

            FwkTest <TKey, TVal> .CurrentTest.ResetKey(NUMTHREADS);

            int numActiveThd = FwkTest <TKey, TVal> .CurrentTest.GetUIntValue(NUMTHREADS);

            int numActiveTx = activeTxns.Count;

            try
            {
                Util.Log("numAvtiveTx is {0} and no of AvtiveThread = {1} and activemap count= {2}", numActiveTx, numActiveThd, activeTxns.Count);
            }
            catch (Exception e) { FwkTest <TKey, TVal> .CurrentTest.FwkException("Caught exception {0}", e); }
            lock (CLASS_LOCK)
            {
                if (numActiveTx < numActiveThd)
                {
                    action = BEGIN_TX;
                }
                else
                {
                    for (int i = 0; i < keyList.Count; i++)
                    {
                        txId   = (TransactionId)(object)keyList[i];
                        txInfo = (TxInfo)(object)activeTxns[txId];

                        numExecutions = txInfo.getNumExecutions();
                        if (numExecutions > minExecutions)
                        {
                            bool isCommit = FwkTest <TKey, TVal> .CurrentTest.GetBoolValue("TxBool");

                            if (isCommit)
                            {
                                action = COMMIT_TX;
                            }
                            else
                            {
                                action = ROLLBACK_TX;
                            }
                            break;
                        }
                    }
                    if (action == 0)
                    {
                        action = EXECUTE_TX_OPS;
                        Random random = new Random();
                        int    rant   = random.Next(0, keyList.Count - 1);
                        txId   = (TransactionId)(object)keyList[rant];
                        txInfo = (TxInfo)(object)activeTxns[txId];
                    }
                }
            }
            Boolean success = false;

            try
            {
                lock (txlock)
                {
                    switch (action)
                    {
                    case (1001):
                        txInfo           = begin(reg);
                        txId             = txInfo.getTxId();
                        activeTxns[txId] = (Object)txInfo;
                        break;

                    case (1002):
                        executeTxOps(txInfo);
                        txId   = txInfo.getTxId();
                        txInfo = (TxInfo)(object)activeTxns[txId];
                        if (txInfo != null)
                        { // could happen if tx committed, entry removed
                            txInfo.incrementNumExecutions();
                            activeTxns[txId] = (Object)txInfo;
                        }
                        break;

                    case (1004):
                        success = commit(txInfo);
                        break;

                    case (1005):
                        rollback(txInfo);
                        txId = txInfo.getTxId();
                        activeTxns.Remove(txId);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                FwkTest <TKey, TVal> .CurrentTest.FwkException("The Test Threw this exception {0}", e);
            }
        }