示例#1
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);
        }
示例#2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="grid">Grid.</param>
        /// <param name="target">Target.</param>
        /// <param name="marsh">Marshaller.</param>
        /// <param name="flagSkipStore">Skip store flag.</param>
        /// <param name="flagKeepBinary">Keep binary flag.</param>
        /// <param name="flagNoRetries">No-retries mode flag.</param>
        public CacheImpl(Ignite grid, IUnmanagedTarget target, Marshaller marsh,
                         bool flagSkipStore, bool flagKeepBinary, bool flagNoRetries) : base(target, marsh)
        {
            Debug.Assert(grid != null);

            _ignite         = grid;
            _flagSkipStore  = flagSkipStore;
            _flagKeepBinary = flagKeepBinary;
            _flagNoRetries  = flagNoRetries;

            _txManager = GetConfiguration().AtomicityMode == CacheAtomicityMode.Transactional
                ? new CacheTransactionManager(grid.GetTransactions())
                : null;
        }
示例#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
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="target">Target.</param>
        /// <param name="flagSkipStore">Skip store flag.</param>
        /// <param name="flagKeepBinary">Keep binary flag.</param>
        /// <param name="flagNoRetries">No-retries mode flag.</param>
        /// <param name="flagPartitionRecover">Partition recover mode flag.</param>
        public CacheImpl(IPlatformTargetInternal target,
                         bool flagSkipStore, bool flagKeepBinary, bool flagNoRetries, bool flagPartitionRecover)
            : base(target)
        {
            _ignite               = target.Marshaller.Ignite;
            _flagSkipStore        = flagSkipStore;
            _flagKeepBinary       = flagKeepBinary;
            _flagNoRetries        = flagNoRetries;
            _flagPartitionRecover = flagPartitionRecover;

            _txManager = GetConfiguration().AtomicityMode == CacheAtomicityMode.Transactional
                ? new CacheTransactionManager(_ignite.GetIgnite().GetTransactions())
                : null;

            _readException = stream => ReadException(Marshaller.StartUnmarshal(stream));
        }
示例#5
0
        public void DoPopulateRegion()
        {
            CacheTransactionManager txManager = CacheHelper <TKey, TVal> .DCache.CacheTransactionManager;
            //TransactionId txId = CacheHelper<TKey, TVal>.DCache.CacheTransactionManager;
            IRegion <TKey, TVal> reg = GetRegion();

            for (int i = 0; i < 5; i++)
            {
                TKey key   = (TKey)(object)(i);
                TVal value = (TVal)(object)"Value_";
                txManager.Begin();
                reg[key] = value;
                txManager.Commit();
                Util.Log("The Key is={0} and value={1}", key.ToString(), value.ToString());
            }
        }
示例#6
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);
        }
        /// <summary>
        /// If ambient transaction is present, starts an Ignite transaction and enlists it.
        /// </summary>
        public void StartTxIfNeeded()
        {
            if (_transactions.Tx != null)
            {
                // Ignite transaction is already present.
                // We have either enlisted it already, or it has been started manually and should not be enlisted.
                // Java enlists existing Ignite tx in this case (see CacheJtaManager.java), but we do not.
                return;
            }

            var ambientTx = System.Transactions.Transaction.Current;

            if (ambientTx != null && ambientTx.TransactionInformation.Status == TransactionStatus.Active)
            {
                _transactions.TxStart(_transactions.DefaultTransactionConcurrency,
                                      CacheTransactionManager.ConvertTransactionIsolation(ambientTx.IsolationLevel),
                                      _transactions.DefaultTimeout);
                _enlistment.Value = ambientTx.EnlistVolatile(this, EnlistmentOptions.None);
            }
        }
示例#8
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);
        }
示例#9
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();

                Cache cache = cacheFactory.Create();

                Console.WriteLine("Created the Geode cache.");

                RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);

                Console.WriteLine("Created the RegionFactory.");

                // Create the example Region
                IRegion <string, string> region = regionFactory.Create <string, string>("exampleRegion");

                Console.WriteLine("Created the region with generics support.");

                // Get the cache transaction manager from the cache.
                CacheTransactionManager txManager = cache.CacheTransactionManager;

                // Starting a transaction
                txManager.Begin();
                Console.WriteLine("Transaction started.");

                region["Key1"] = "Value1";
                region["Key2"] = "Value2";

                Console.WriteLine("Put two entries into the region");

                try {
                    // Prepare the transaction
                    txManager.Prepare();
                    Console.WriteLine("Transaction Prepared");

                    // Commit the transaction
                    txManager.Commit();
                    Console.WriteLine("Transaction Committed");
                }
                catch (CommitConflictException e)
                {
                    Console.WriteLine("CommitConflictException encountered. Exception: {0}", e.Message);
                }

                if (region.ContainsKey("Key1"))
                {
                    Console.WriteLine("Obtained the first entry from the Region");
                }

                if (region.ContainsKey("Key2"))
                {
                    Console.WriteLine("Obtained the second entry from the Region");
                }

                //start a new transaction
                txManager.Begin();
                Console.WriteLine("Transaction Started");

                // Put a new entry
                region["Key3"] = "Value3";
                Console.WriteLine("Put the third entry into the Region");

                // remove the first key
                region.Remove("Key1", null);
                Console.WriteLine("remove the first entry");

                txManager.Prepare();
                Console.WriteLine("Transaction Prepared");

                txManager.Rollback();
                Console.WriteLine("Transaction Rollbacked");

                if (region.ContainsKey("Key1"))
                {
                    Console.WriteLine("Obtained the first entry from the Region");
                }

                if (region.ContainsKey("Key2"))
                {
                    Console.WriteLine("Obtained the second entry from the Region");
                }

                if (region.ContainsKey("Key3"))
                {
                    Console.WriteLine("ERROR: Obtained the third entry from the Region.");
                }

                cache.Close();

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("Transactions Geode Exception: {0}", gfex.Message);
            }
        }
示例#10
0
        public void doValidateTxOps(TransactionId txId, int txState)
        {
            FwkInfo("Inside Resumabletx:DoValidateTxOps");
            FwkInfo("Transactional Id is {0} and transaction state is={1}", txId, txState);
            //int cnt =0;
            //TKey key;
            int           txnState = txState;
            TransactionId txnId    = txId;

            ResetKey("entryCount");
            int EntryCount = GetUIntValue("entryCount");
            CacheTransactionManager txManager = CacheHelper <TKey, TVal> .DCache.CacheTransactionManager;

            try
            {
                switch (txnState)
                {
                case 1001:
                    FwkInfo("...txnState is Begin ...");
                    checkContainsKey(txnState);
                    break;

                case 2:
                    FwkInfo("...txnState is Suspend...");
                    if (!txManager.IsSuspended(txId) && !txManager.Exists(txId))
                    {
                        FwkException("After Suspend(),the Transaction should have been Suspended and should still exist");
                    }
                    checkContainsKey(txnState);
                    break;

                case 3:
                    FwkInfo("...txnState is Resume...");
                    if (txManager.IsSuspended(txnId))
                    {
                        FwkException("After Resume(),the Transaction should NOT have been Suspended");
                    }
                    if (!txManager.Exists(txnId))
                    {
                        FwkException("After Resume(),the Transaction should still exist");
                    }
                    checkContainsKey(txnState);
                    break;

                case 1004:
                    FwkInfo("...txnState is Commit...");
                    if (txManager.IsSuspended(txnId))
                    {
                        FwkException("After Commit(),the Transaction should NOT have been Suspended");
                    }
                    if (txManager.Exists(txnId))
                    {
                        FwkException("After Commit(),the Transaction should Not exist");
                    }
                    if (txManager.TryResume(txnId))
                    {
                        FwkException("After Commit(),the Transaction should Not be resumed");
                    }
                    checkContainsKey(txnState);
                    FwkInfo("Commit BeforeTxMap.Count={0} ", BeforeTxMap.Count);
                    break;
                }
            }
            catch (Exception ex)
            {
                FwkException("doValidateTxOps caught exception {0}", ex.Message);
            }
        }
示例#11
0
        public void DoBasicTX()
        {
            FwkInfo("Inside ResumableTx:DoBasicTX()");
            IRegion <TKey, TVal> region = GetRegion();
            string opcode  = null;
            int    action  = 0;
            int    minNoEx = GetUIntValue("minExecutions");

            if (region == null)
            {
                FwkSevere("ResumableTx:DoBasicTX(): No region to perform operations on.");
            }
            CacheTransactionManager txManager = null;
            TransactionId           txId      = null;

            int numOfEx = 0;

            try
            {
                txManager = CacheHelper <TKey, TVal> .DCache.CacheTransactionManager;
                if (numOfEx == 0)
                {
                    FwkInfo("Begin.() tx numOfEx={0} and minNoEx={1}", numOfEx, minNoEx);
                    txManager.Begin();
                    action = BEGIN_TX;
                    doValidateTxOps(txId, action);
                }
                while (!(numOfEx > minNoEx))
                {
                    try
                    {
                        FwkInfo("numOfEx={0} and minNoEx={1}", numOfEx, minNoEx);
                        txId   = txManager.Suspend();
                        action = SUSPEND;
                        doValidateTxOps(txId, action);

                        txManager.Resume(txId);
                        int numKeys = 100;
                        Dictionary <TKey, TVal> keyValMap = new Dictionary <TKey, TVal>();
                        TKey key;
                        TVal value;
                        for (int i = 0; i < numKeys; i++)
                        {
                            string keyName = String.Format("key_{0}", i);
                            key               = (TKey)(object)keyName.ToString();
                            value             = (TVal)(object)"Value_";
                            region[key]       = value;
                            keyValMap[key]    = value;
                            AfterTxMap["put"] = keyValMap;
                        }
                        action = RESUME;
                        FwkInfo("keyValMap count={0} and region count is {1}", keyValMap.Count, region.Keys.Count);
                        doValidateTxOps(txId, action);
                    }
                    catch (IllegalStateException ex)
                    {
                        FwkException("Got {0}", ex.Message);
                    }
                    catch (CommitConflictException ex)
                    {
                        FwkException("Got {0}", ex.Message);
                    }
                    numOfEx++;
                }
                if (numOfEx > minNoEx)
                {
                    try
                    {
                        txManager.Commit();
                    }
                    catch (CommitConflictException)
                    {
                        FwkInfo("Got Expected exception as there was a write conflict");
                    }
                    action = COMMIT;
                    doValidateTxOps(txId, action);
                }
            }
            catch (Exception ex)
            {
                FwkException("ResumableTx.DoEntryOpsWithTX() Caught unexpected " +
                             "exception during entry '{0}' operation: {1}.", opcode, ex);
            }
        }