Exemplo n.º 1
0
        /// <summary>
        /// Returns the next enumeration data chunk from the set of chunks returned by multiple nodes
        /// </summary>
        /// <param name="results"></param>
        /// <returns></returns>
        public static EnumerationDataChunk FindAtomicEnumerationDataChunkReplicated(RspList results)
        {
            EnumerationDataChunk nextChunk = null;

            if (results == null)
            {
                return(nextChunk);
            }


            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (!rsp.wasReceived() || rsp.wasSuspected())
                {
                    continue;
                }

                nextChunk = (EnumerationDataChunk)rsp.Value;

                if (nextChunk != null)
                {
                    return(nextChunk);
                }
            }
            return(nextChunk);
        }
Exemplo n.º 2
0
        public static LockOptions FindAtomicIsLockedStatusReplicated(RspList results, ref object lockId, ref DateTime lockDate)
        {
            LockOptions lockInfo = null;

            if (results == null)
            {
                return(lockInfo);
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    continue;
                }
                if (!rsp.wasReceived())
                {
                    continue;
                }

                lockInfo = (LockOptions)rsp.Value;
                if (lockInfo != null)
                {
                    if (lockInfo.LockId != null)
                    {
                        return(lockInfo);
                    }
                }
            }
            return(lockInfo);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the set of nodes where the addition was performed as an atomic operation.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static bool FindAtomicAddHintReplicated(RspList results)
        {
            bool res = false;

            if (results == null)
            {
                return(res);
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (!rsp.wasReceived() || rsp.wasSuspected())
                {
                    continue;
                }

                res = (bool)rsp.Value;
                if (res == false)
                {
                    return(res);
                }
            }
            return(res);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Remove the objects from the cluster. For efficiency multiple objects are sent as one.
        /// </summary>
        /// <param name="keys">list of keys to remove.</param>
        /// <returns>true if succeded, false otherwise.</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemoveRange"/> on every server node in the cluster.
        /// </remarks>
        protected bool Clustered_Remove(object[] keys, ItemRemoveReason reason, OperationContext operationContext)
        {
            try
            {
                Function func    = new Function((int)OpCodes.RemoveRange, new object[] { keys, reason, operationContext }, false);
                RspList  results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL, true);

                if (results != null)
                {
                    for (int i = 0; i < results.size(); i++)
                    {
                        Rsp rsp1 = (Rsp)results.elementAt(i);

                        if (!rsp1.wasReceived())
                        {
                            Context.NCacheLog.Error("ReplicatedBase.Remove[]", "timeout_failure :" + rsp1.Sender + " Keys :" + keys.Length);
                            continue;
                        }
                    }
                }
                Rsp rsp = ClusterHelper.FindAtomicRemoveStatusReplicated(results, Context.NCacheLog);

                return(true);
            }
            catch (Runtime.Exceptions.TimeoutException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Find first entry in the response list that is not null and didnt timeout.
        /// </summary>
        /// <param name="results">response list</param>
        /// <param name="type">type of response to fetch</param>
        /// <returns>found entry</returns>
        public static Rsp GetFirstNonNullRsp(RspList results, Type type)
        {
            if (results == null)
            {
                return(null);
            }

            Rsp rsp = null;

            for (int i = 0; i < results.size(); i++)
            {
                rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    results.removeElementAt(i);
                    continue;
                }
                if (!rsp.wasReceived())
                {
                    results.removeElementAt(i);
                    continue;
                }

                if (rsp.Value != null && rsp.Value.GetType().Equals(type))
                {
                    return(rsp);
                }
            }
            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Find all entries in the response list that are not null and didnt timeout.
        /// </summary>
        /// <param name="results">response list</param>
        /// <param name="type">type of response to fetch</param>
        /// <returns>List of entries found</returns>
        public static ArrayList GetAllNonNullRsp(RspList results, Type type)
        {
            ArrayList list = new ArrayList();

            if (results == null)
            {
                return(null);
            }

            Rsp rsp = null;

            for (int i = 0; i < results.size(); i++)
            {
                rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    results.removeElementAt(i);
                    continue;
                }
                if (!rsp.wasReceived())
                {
                    results.removeElementAt(i);
                    continue;
                }

                if (rsp.Value != null && rsp.Value.GetType().Equals(type))
                {
                    list.Add(rsp);
                }
            }
            return(list);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns the array of keys for which Bulk operation failed.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static Hashtable FindAtomicBulkRemoveStatusReplicated(RspList results, Address local)
        {
            Hashtable result = null;

            if (results == null)
            {
                return(new Hashtable());
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    continue;
                }
                if (!rsp.wasReceived())
                {
                    continue;
                }

                result = (Hashtable)rsp.Value;

                if (result != null)
                {
                    return(result);
                }
            }

            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns the set of nodes where the addition was performed as an atomic operation.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static bool FindAtomicResponseReplicated(RspList results)
        {
            bool res = false;

            if (results == null)
            {
                return(res);
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (!rsp.wasReceived() || rsp.wasSuspected())
                {
                    continue;
                }

                res = (bool)rsp.Value;
                //if(nTrace.isInfoEnabled) Trace.info("FindAtomicAddHintReplicated", "Sender = " + rsp.Sender + ", result = " + res);
                if (res == false)
                {
                    return(res);
                }
            }
            return(res);
        }
Exemplo n.º 9
0
        public static Hashtable VerifyAllTrueResopnses(RspList results)
        {
            Hashtable res = new Hashtable();

            if (results == null)
            {
                return(res);
            }
            Rsp rsp = null;

            for (int i = 0; i < results.size(); i++)
            {
                rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    throw new Alachisoft.NGroups.SuspectedException(rsp.Sender);
                }

                if (!rsp.wasReceived())
                {
                    throw new Runtime.Exceptions.TimeoutException("operation timeout");
                }
            }
            if (rsp != null)
            {
                return((Hashtable)rsp.Value);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns a .NET IEnumerator interface so that a client should be able
        /// to iterate over the elements of the cache store.
        /// </summary>
        /// <returns>IDictionaryEnumerator enumerator.</returns>
        protected IDictionaryEnumerator Clustered_GetEnumerator(ArrayList dests, IDictionaryEnumerator local)
        {
            IDictionaryEnumerator retVal = null;

            try
            {
                Function func    = new Function((int)OpCodes.KeyList, null);
                RspList  results = Cluster.BroadcastToMultiple(dests,
                                                               func,
                                                               GroupRequest.GET_ALL,
                                                               Cluster.Timeout * 10,
                                                               false);
                if (results == null)
                {
                    return(retVal);
                }

                ClusterHelper.ValidateResponses(results, typeof(object[]), Name);

                Rsp       rsp       = null;
                ArrayList validRsps = new ArrayList();
                for (int i = 0; i < results.size(); i++)
                {
                    rsp = (Rsp)results.elementAt(i);

                    if (rsp.Value != null)
                    {
                        validRsps.Add(rsp);
                    }
                }

                int index      = (local == null ? 0 : 1);
                int totalEnums = validRsps.Count + index;
                IDictionaryEnumerator[] enums = new IDictionaryEnumerator[totalEnums];
                if (local != null)
                {
                    enums[0] = local;
                }
                for (int i = 0; i < validRsps.Count; i++)
                {
                    rsp            = (Rsp)validRsps[i];
                    enums[index++] = new LazyPartitionedKeysetEnumerator(this,
                                                                         rsp.Value as object[],
                                                                         rsp.Sender as Address,
                                                                         false);
                }
                retVal = new AggregateEnumerator(enums);
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            return(retVal);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Verifies that joining node has no data integrity conflicts with other nodes of the
        /// cluster.
        /// </summary>
        /// <returns>True, if no data integrity conflicts found, other wise false</returns>
        /// <remarks>Each partitioned node can have his data affinity. Data groups other than the
        /// strongly affiliated groups can be loadbalanced to any of the existing node. In such a
        /// situaltion if a new node joins and it has strong affinity with the groups whose data
        /// was previously distributed evenly, then a data integrity conflict arises. To avoid such
        /// conflicts each joining node first varifes that no other node on the cluster has data
        /// of his groups. If it is so, then he has to leave the cluster.</remarks>
        public bool VerifyDataIntegrity()
        {
            bool integrityVarified = true;
            bool integrityIssue    = false;


            try
            {
                if (Cluster.Servers.Count > 1)
                {
                    if (_stats != null && _stats.LocalNode.DataAffinity != null)
                    {
                        DataAffinity affinity = _stats.LocalNode.DataAffinity;

                        if (affinity.Groups != null && affinity.Groups.Count > 0)
                        {
                            Function fun     = new Function((int)OpCodes.VerifyDataIntegrity, (object)affinity.Groups, false);
                            RspList  results = Cluster.BroadcastToServers(fun, GroupRequest.GET_ALL, false);

                            if (results != null)
                            {
                                ClusterHelper.ValidateResponses(results, typeof(bool), Name);
                                Rsp response;
                                for (int i = 0; i < results.size(); i++)
                                {
                                    response = (Rsp)results.elementAt(i);
                                    if (response.wasReceived())
                                    {
                                        integrityIssue = Convert.ToBoolean(response.Value);
                                        if (integrityIssue)
                                        {
                                            Context.NCacheLog.Error("PartitionedCacheBase.Verifydataintegrity()", "data integrity issue from " + response.Sender.ToString());
                                            integrityVarified = false;
                                        }
                                    }
                                    else
                                    {
                                        Context.NCacheLog.Error("PartitionedCacheBase.Verifydataintegrity()", "data integrity varification not received from " + response.Sender.ToString());
                                        integrityVarified = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (Context != null)
                {
                    Context.NCacheLog.Error("PartitionedCacheBase.Verifydataintegrity()", e.ToString());
                }
                integrityVarified = false;
            }

            return(integrityVarified);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Returns the set of nodes where the addition was performed as an atomic operation.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static Rsp FindAtomicRemoveStatusReplicated(RspList results, ILogger NCacheLog)
        {
            Rsp retRsp = null;

            if (results == null)
            {
                return(retRsp);
            }
            int timeoutCount   = 0;
            int suspectedCount = 0;
            int successCount   = 0;

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);


                if (!rsp.wasReceived() && !rsp.wasSuspected())
                {
                    //throw new Alachisoft.NGroups.TimeoutException();
                    //failedNodes += rsp.Sender + ";";
                    timeoutCount++;
                    continue;
                }
                if (rsp.wasSuspected())
                {
                    //throw new Alachisoft.NGroups.SuspectedException(rsp.Sender);
                    suspectedCount++;
                    continue;
                }
                if (rsp.Value != null)
                {
                    retRsp = rsp;
                }
                successCount++;
            }
            if (suspectedCount > 0 && successCount > 0 && (suspectedCount + successCount == results.size()))
            {
                //as operation is successfull on all other nodes other than suspected node(s).
                return(retRsp);
            }
            if (timeoutCount > 0 && (timeoutCount + successCount == results.size()))
            {
                throw new Runtime.Exceptions.TimeoutException("Operation Timeout");
            }
            if (timeoutCount > 0 && suspectedCount > 0)
            {
                throw new Runtime.Exceptions.TimeoutException("Operation Timeout");
            }

            return(retRsp);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Returns the set of nodes where the insertion was performed as an atomic operation.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>key and value pairs for inserted items</returns>
        public static Hashtable FindAtomicBulkInsertStatusReplicated(RspList results)
        {
            Hashtable insertedKeys = new Hashtable();
            Hashtable result       = null;
            Hashtable prvResult    = null;

            if (results == null)
            {
                return(insertedKeys);
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    //throw new Alachisoft.NGroups.SuspectedException(rsp.Sender);
                    continue;
                }
                if (!rsp.wasReceived())
                {
                    //throw new Alachisoft.NGroups.TimeoutException();
                    continue;
                }

                result = (Hashtable)rsp.Value;

                if (prvResult == null)
                {
                    insertedKeys = result;
                    prvResult    = result;
                }
                else
                {
                    foreach (object key in prvResult.Keys)
                    {
                        if (result.Contains(key) == false)
                        {
                            if (insertedKeys.Contains(key))
                            {
                                insertedKeys.Remove(key);
                            }
                        }
                    }

                    prvResult = result;
                }
            }
            return(insertedKeys);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Find first entry in the response list that is not null and didnt timeout.
        /// </summary>
        /// <param name="results">response list</param>
        /// <param name="type">type of response to fetch</param>
        /// <returns>found entry</returns>
        public static Rsp GetFirstNonNullRsp(RspList results, Type type)
        {
            if (results == null)
            {
                return(null);
            }

            Rsp       rsp        = null;
            bool      found      = false;
            ArrayList removeRsps = null;

            for (int i = 0; i < results.size(); i++)
            {
                rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected() || !rsp.wasReceived())
                {
                    if (removeRsps == null)
                    {
                        removeRsps = new ArrayList();
                    }

                    removeRsps.Add(i);
                    continue;
                }

                if (rsp.Value != null && rsp.Value.GetType().Equals(type))
                {
                    found = true;
                    break;
                }
            }


            if (removeRsps != null && removeRsps.Count > 0)
            {
                for (int index = 0; index < removeRsps.Count; index++)
                {
                    int removeAt = (int)removeRsps[index];
                    results.removeElementAt(removeAt);
                }
            }

            if (found)
            {
                return(rsp);
            }

            return(null);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Returns the array of keys for which Bulk operation failed.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static object[] FindAtomicBulkOpStatusReplicated(RspList results, Address local)
        {
            Hashtable failedKeys = new Hashtable();

            object[] result = null;
            if (results == null)
            {
                return(null);
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    continue;
                }
                if (!rsp.wasReceived())
                {
                    continue;
                }

                result = (object[])rsp.Value;

                for (int j = 0; j < result.Length; j++)
                {
                    if (failedKeys.Contains(result[j]) == false)
                    {
                        failedKeys[result[j]] = result[j];
                    }
                }

                /*
                 * if(Trace.isInfoEnabled) Trace.info("FindAtomicAddStatusReplicated", "Sender = " + rsp.Sender + ", result = " + res);
                 * if(res != CacheAddResult.Success && res != CacheAddResult.KeyExists)
                 * {
                 *  return res;
                 * }
                 */
            }

            object[] failed = new object[failedKeys.Count];
            failedKeys.Keys.CopyTo(failed, 0);

            return(failed);
        }
Exemplo n.º 16
0
        public static void VerifySuspectedResponses(RspList results)
        {
            if (results == null)
            {
                return;
            }

            Rsp rsp = null;

            for (int i = 0; i < results.size(); i++)
            {
                rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    throw new NGroups.SuspectedException(rsp.Sender);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Returns the array of keys for which Bulk operation failed.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static object[] FindAtomicBulkOpStatusReplicated(RspList results, Address local)
        {
            //CacheAddResult res = CacheAddResult.Failure;
            Hashtable failedKeys = new Hashtable();

            object[] result = null;
            if (results == null)
            {
                return(null);
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    //throw new Alachisoft.NGroups.SuspectedException(rsp.Sender);
                    continue;
                }
                if (!rsp.wasReceived())
                {
                    //throw new Alachisoft.NGroups.TimeoutException();
                    continue;
                }

                result = (object[])rsp.Value;

                for (int j = 0; j < result.Length; j++)
                {
                    if (failedKeys.Contains(result[j]) == false)
                    {
                        failedKeys[result[j]] = result[j];
                    }
                }
            }

            object[] failed = new object[failedKeys.Count];
            failedKeys.Keys.CopyTo(failed, 0);

            return(failed);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Find all entries in the response list that are not null and didnt timeout.
        /// </summary>
        /// <param name="results">response list</param>
        /// <param name="type">type of response to fetch</param>
        /// <returns>List of entries found</returns>
        public static IList GetAllNonNullRsp(RspList results, Type type)
        {
            IList list = new ClusteredArrayList();

            if (results == null)
            {
                return(null);
            }

            Rsp         rsp        = null;
            IList <Rsp> removeRsps = null;

            for (int i = 0; i < results.size(); i++)
            {
                rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected() || !rsp.wasReceived())
                {
                    if (removeRsps == null)
                    {
                        removeRsps = new List <Rsp>();
                    }
                    removeRsps.Add(rsp);
                    continue;
                }

                if (rsp.Value != null && rsp.Value.GetType().Equals(type))
                {
                    list.Add(rsp);
                }
            }

            if (removeRsps != null && removeRsps.Count > 0)
            {
                foreach (Rsp r in removeRsps)
                {
                    results.removeRsp(r);
                }
            }

            return(list);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Returns the array of keys for which Bulk operation failed.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static object[] FindAtomicBulkOpStatusReplicated(RspList results, Address local)
        {
            Hashtable failedKeys = new Hashtable();

            object[] result = null;
            if (results == null)
            {
                return(null);
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    continue;
                }

                if (!rsp.wasReceived())
                {
                    continue;
                }

                result = (object[])rsp.Value;

                for (int j = 0; j < result.Length; j++)
                {
                    if (failedKeys.Contains(result[j]) == false)
                    {
                        failedKeys[result[j]] = result[j];
                    }
                }
            }

            object[] failed = new object[failedKeys.Count];

            failedKeys.Keys.CopyTo(failed, 0);

            return(failed);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Returns the array of keys for which Bulk operation failed.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static Hashtable FindAtomicBulkRemoveStatusReplicated(RspList results, Address local)
        {
            //Hashtable removedKeys = new Hashtable();
            Hashtable result = null;

            //Hashtable lastRes = null;

            if (results == null)
            {
                return(new Hashtable());
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    //throw new Alachisoft.NGroups.SuspectedException(rsp.Sender);
                    continue;
                }
                if (!rsp.wasReceived())
                {
                    //throw new Alachisoft.NGroups.TimeoutException();
                    continue;
                }

                result = (Hashtable)rsp.Value;

                if (result != null)
                {
                    return(result);
                }
            }

            return(result);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Returns the set of nodes where the insertion was performed as an atomic operation.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static CacheInsResultWithEntry FindAtomicInsertStatusReplicated(RspList results)
        {
            int needEvictCount = 0;
            int timeoutCount   = 0;
            int suspectedCount = 0;
            int successCount   = 0;

            CacheInsResultWithEntry res = new CacheInsResultWithEntry();

            if (results == null)
            {
                return(res);
            }

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);
                if (!rsp.wasReceived() && !rsp.wasSuspected())
                {
                    timeoutCount++;
                    continue;
                }

                if (rsp.wasSuspected())
                {
                    suspectedCount++;
                    continue;
                }


                res = (CacheInsResultWithEntry)((OperationResponse)rsp.Value).SerializablePayload;
                if (res.Result == CacheInsResult.Success || res.Result == CacheInsResult.SuccessOverwrite)
                {
                    successCount++;
                }
                if (res.Result != CacheInsResult.Success && res.Result != CacheInsResult.SuccessOverwrite && res.Result != CacheInsResult.NeedsEviction)
                {
                }

                /* If all the nodes in the Cluster return NeedsEviction response then we do not need to remove */
                if (res.Result == CacheInsResult.NeedsEviction)
                {
                    needEvictCount++;
                }
            }

            if (needEvictCount == results.size())
            {
                //every node returned the NeedEviction; so we need not remove the item
                //as data is not corrupted.
                res.Result = CacheInsResult.NeedsEvictionNotRemove;
            }
            if (suspectedCount > 0 && successCount > 0 && (suspectedCount + successCount == results.size()))
            {
                //as operation is successfull on all other nodes other than suspected node(s).
            }
            if (timeoutCount > 0 && (timeoutCount + successCount == results.size()))
            {
                if (successCount > 0)
                {
                    //operation is not succeeded on some of the nodes; therefore we throw timeout exception.
                    res.Result = CacheInsResult.PartialTimeout;
                }
                else
                {
                    //operation timed out on all of the node; no need to rollback.
                    res.Result = CacheInsResult.FullTimeout;
                }
            }
            if (timeoutCount > 0 && suspectedCount > 0)
            {
                if (successCount > 0)
                {
                    //operation is not succeeded on some of the nodes; therefore we throw timeout exception.
                    res.Result = CacheInsResult.PartialTimeout;
                }
                else
                {
                    //operation timed out on all of the node; no need to rollback.
                    res.Result = CacheInsResult.FullTimeout;
                }
            }

            return(res);
        }
Exemplo n.º 22
0
        public static ClusterOperationResult FindAtomicClusterOperationStatusReplicated(RspList results)
        {
            ClusterOperationResult res = null;

            if (results == null)
            {
                return(res);
            }
            int timeoutCount   = 0;
            int suspectedCount = 0;
            int successCount   = 0;

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    suspectedCount++;
                    continue;
                }
                if (!rsp.wasReceived() && !rsp.wasSuspected())
                {
                    timeoutCount++;
                    continue;
                }

                res = rsp.Value as ClusterOperationResult;
                if (res.ExecutionResult == ClusterOperationResult.Result.Completed)
                {
                    successCount++;
                }
            }
            if (suspectedCount > 0 && successCount > 0 && (suspectedCount + successCount == results.size()))
            {
                //as operation is successfull on all other nodes other than suspected node(s).
                return(res);
            }
            if (timeoutCount > 0 && (timeoutCount + successCount == results.size()))
            {
                if (successCount > 0)
                {
                    //operation is not succeeded on some of the nodes; therefore we throw timeout exception.
                    res.ExecutionResult = ClusterOperationResult.Result.ParitalTimeout;
                    return(res);
                }
                else
                {
                    //operation timed out on all of the node; no need to rollback.
                    res = new OpenStreamResult(ClusterOperationResult.Result.FullTimeout, false);
                    return(res);
                }
            }
            if (timeoutCount > 0 && suspectedCount > 0)
            {
                if (successCount > 0)
                {
                    res.ExecutionResult = ClusterOperationResult.Result.ParitalTimeout;
                    return(res);
                }
                else
                {
                    res = new OpenStreamResult(ClusterOperationResult.Result.FullTimeout, false);
                    return(res);
                }
            }

            return(res);
        }
Exemplo n.º 23
0
        public static void ValidateResponses(RspList results, Type type, string serializationContext)
        {
            if (results == null)
            {
                return;
            }

            //muds:

            ArrayList parserExceptions = new ArrayList();
            ArrayList exceptions       = new ArrayList(11);

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    continue;
                }

                if (!rsp.wasReceived())
                {
                    continue;
                }

                if (rsp.Value != null)
                {
                    object rspValue = rsp.Value;

                    if (rspValue is ParserException)
                    {
                        parserExceptions.Add((Exception)rspValue);
                        continue;
                    }

                    if (rspValue is Exception)
                    {
                        exceptions.Add((Exception)rspValue);
                        continue;
                    }

                    if (type != null && !rspValue.GetType().Equals(type))
                    {
                        exceptions.Add(new BadResponseException("bad response returned by group member " + rsp.Sender));
                        continue;
                    }
                }
            }
            //muds:
            //in case or partitioned caches search requests are broadcasted.
            //it is possible that tag index are defined on one node but not defined on some other node.
            //we will throw the exception back only if we receive exception from every node.
            if (parserExceptions.Count == results.size())
            {
                Exception e = parserExceptions[0] as Exception;
                throw e;
            }

            if (exceptions.Count == 1)
            {
                Exception e = exceptions[0] as Exception;
                if (e is CacheException)
                {
                    throw e;
                }
                else
                {
                    throw new RemoteException((Exception)exceptions[0]);
                }
            }
            else if (exceptions.Count > 0)
            {
                for (int i = 0; i < exceptions.Count; i++)
                {
                    Exception e = exceptions[i] as Exception;
                    if (e is LockingException)
                    {
                        throw e;
                    }
                    else if (e is CacheException)
                    {
                        continue;
                    }
                    else
                    {
                        exceptions[i] = new RemoteException(e);
                    }
                }
                throw new Runtime.Exceptions.AggregateException(exceptions);
            }
        }
Exemplo n.º 24
0
        public static bool FindAtomicLockStatusReplicated(RspList results, ref object lockId, ref DateTime lockDate)
        {
            bool        res      = true;
            LockOptions lockInfo = null;

            if (results == null)
            {
                return(res);
            }
            int lockAcquired = 0;
            int itemNotFound = 0;
            int rspReceived  = results.size();

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    rspReceived--;
                    continue;
                }
                if (!rsp.wasReceived())
                {
                    rspReceived--;
                    continue;
                }

                lockInfo = (LockOptions)rsp.Value;
                if (Object.Equals(lockInfo.LockId, lockId))
                {
                    lockDate = lockInfo.LockDate;
                    lockAcquired++;
                }
                else
                {
                    if (lockInfo.LockId == null)
                    {
                        //item was not present on the node.
                        lockId   = null;
                        lockDate = new DateTime();
                        itemNotFound++;
                    }
                    else
                    {
                        res      = false;
                        lockId   = lockInfo.LockId;
                        lockDate = lockInfo.LockDate;
                        break;
                    }
                }
            }
            if (lockAcquired > 0 && (lockAcquired + itemNotFound == rspReceived))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 25
0
        public static void ValidateResponses(RspList results, Type type, string serializationContext, Boolean throwSuspected = false)
        {
            if (results == null)
            {
                return;
            }
            ArrayList parserExceptions = new ArrayList();
            ArrayList exceptions       = new ArrayList(11);

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    if (throwSuspected)
                    {
                        throw new NGroups.SuspectedException(rsp.Sender);
                    }
                    continue;
                }

                if (!rsp.wasReceived())
                {
                    continue;
                }

                if (rsp.Value != null)
                {
                    object rspValue = rsp.Value;
                    if ((rspValue as Exception) is Alachisoft.NCache.Runtime.Exceptions.InvalidReaderException)
                    {
                        Exception invlidReader = rspValue as Exception;
                        throw invlidReader;
                    }
                    if (rspValue is ParserException)
                    {
                        parserExceptions.Add((ParserException)rspValue);
                        continue;
                    }



                    var licenseException = rspValue as LicensingException;

                    if (licenseException != null)
                    {
                        throw licenseException;
                    }

                    if (rspValue is Exception)
                    {
                        exceptions.Add((Exception)rspValue);
                        continue;
                    }

                    if (type != null && !rspValue.GetType().Equals(type))
                    {
                        exceptions.Add(new Alachisoft.NCache.Runtime.Exceptions.BadResponseException("bad response returned by group member " + rsp.Sender));
                        continue;
                    }
                }
            }
            //in case or partitioned caches search requests are broadcasted.
            //it is possible that tag index are defined on one node but not defined on some other node.
            //we will throw the exception back only if we receive exception from every node.
            try
            {
                if (parserExceptions.Count == results.size())
                {
                    if (parserExceptions[0] is ParserException)
                    {
                        throw parserExceptions[0] as ParserException;
                    }
                }
            }
            catch (Exception e)
            {
                if (NCacheLogger != null && NCacheLogger.IsErrorEnabled)
                {
                    NCacheLogger.Error("ClusterHelper.ValidateResponses()", "parserExceptions Count: " + parserExceptions.Count + " results Count: " + results.size() + " Error: " + e.ToString());
                }
                throw;
            }
            bool aggregateVerified = true;

            if (exceptions.Count == 1)
            {
                Exception e = exceptions[0] as Exception;
                if (e is CacheException)
                {
                    throw e;
                }
                else
                {
                    throw new RemoteException((Exception)exceptions[0]);
                }
            }
            else if (exceptions.Count > 0)
            {
                for (int i = 0; i < exceptions.Count; i++)
                {
                    Exception e = exceptions[i] as Exception;
                    if (e is LockingException)
                    {
                        throw e;
                    }
                    else if (e is CacheException)
                    {
                        continue;
                    }
                    else
                    {
                        exceptions[i] = new RemoteException(e);
                    }
                    if (i > 0)
                    {
                        if (!(exceptions[i] as Exception).Message.Equals((exceptions[i - 1] as Exception).Message))
                        {
                            aggregateVerified = false;
                        }
                    }
                }
                if (aggregateVerified)
                {
                    throw exceptions[0] as Exception;
                }
                throw new Runtime.Exceptions.AggregateException(exceptions);
            }
        }
Exemplo n.º 26
0
        /// <summary> Cast a message to all members, and wait for <code>mode</code> responses. The responses are returned in a response
        /// list, where each response is associated with its sender.<p> Uses <code>GroupRequest</code>.
        ///
        /// </summary>
        /// <param name="dests">  The members to which the message is to be sent. If it is null, then the message is sent to all
        /// members
        /// </param>
        /// <param name="msg">    The message to be sent to n members
        /// </param>
        /// <param name="mode">   Defined in <code>GroupRequest</code>. The number of responses to wait for: <ol> <li>GET_FIRST:
        /// return the first response received. <li>GET_ALL: wait for all responses (minus the ones from
        /// suspected members) <li>GET_MAJORITY: wait for a majority of all responses (relative to the grp
        /// size) <li>GET_ABS_MAJORITY: wait for majority (absolute, computed once) <li>GET_N: wait for n
        /// responses (may block if n > group size) <li>GET_NONE: wait for no responses, return immediately
        /// (non-blocking) </ol>
        /// </param>
        /// <param name="timeout">If 0: wait forever. Otherwise, wait for <code>mode</code> responses <em>or</em> timeout time.
        /// </param>
        /// <returns> RspList A list of responses. Each response is an <code>Object</code> and associated to its sender.
        /// </returns>
        public virtual RspList castMessage(ArrayList dests, Message msg, byte mode, long timeout)
        {
            GroupRequest _req = null;
            ArrayList    real_dests;

            ArrayList clusterMembership = channel.View.Members != null ? (ArrayList)channel.View.Members.Clone() : null;

            // we need to clone because we don't want to modify the original
            // (we remove ourselves if LOCAL is false, see below) !
            real_dests = dests != null ? (ArrayList)dests.Clone() : clusterMembership;
            //real_dests = dests != null ? (ArrayList) dests.Clone():null;

            // if local delivery is off, then we should not wait for the message from the local member.
            // therefore remove it from the membership
            if (channel != null && channel.getOpt(Channel.LOCAL).Equals(false))
            {
                real_dests.Remove(channel.LocalAddress);
            }

            // don't even send the message if the destination list is empty
            if (NCacheLog.IsInfoEnabled)
            {
                NCacheLog.Info("MsgDispatcher.castMessage()", "real_dests=" + Global.CollectionToString(real_dests));
            }

            if (real_dests == null || real_dests.Count == 0)
            {
                if (NCacheLog.IsInfoEnabled)
                {
                    NCacheLog.Info("MsgDispatcher.castMessage()", "destination list is empty, won't send message");
                }
                //((GroupChannel)channel).MsgProvider.SubmittObject(msg);
                return(new RspList());                // return empty response list
            }

            _req = new GroupRequest(msg, corr, real_dests, clusterMembership, mode, timeout, 0, this._ncacheLog);


            _req.execute();


            if (mode != GroupRequest.GET_NONE)
            {
                ((GroupChannel)channel).Stack.perfStatsColl.IncrementClusteredOperationsPerSecStats();
            }


            RspList rspList = _req.Results;


            if (rspList != null)
            {
                for (int i = 0; i < rspList.size(); i++)
                {
                    Rsp rsp = rspList.elementAt(i) as Rsp;
                    if (rsp != null)
                    {
                        if (!rsp.wasReceived() && !rsp.wasSuspected())
                        {
                            if (corr.CheckForMembership((Address)rsp.sender))
                            {
                                rsp.suspected = true;
                            }
                        }
                    }
                }
            }
            return(rspList);
        }
Exemplo n.º 27
0
        /// <summary> Sends a message to a single member (destination = msg.dest) and returns the response. The message's destination
        /// must be non-zero !
        /// </summary>
        public virtual object sendMessage(Message msg, byte mode, long timeout)
        {
            RspList      rsp_list = null;
            object       dest     = msg.Dest;
            Rsp          rsp;
            GroupRequest _req = null;

            if (dest == null)
            {
                return(null);
            }

            ArrayList mbrs = ArrayList.Synchronized(new ArrayList(1));

            mbrs.Add(dest);             // dummy membership (of destination address)

            ArrayList clusterMembership = channel.View.Members != null ? (ArrayList)channel.View.Members.Clone() : null;

            _req = new GroupRequest(msg, corr, mbrs, clusterMembership, mode, timeout, 0, this._ncacheLog);

            _req.execute();

            if (mode == GroupRequest.GET_NONE)
            {
                return(null);
            }

            ((GroupChannel)channel).Stack.perfStatsColl.IncrementClusteredOperationsPerSecStats();

            rsp_list = _req.Results;

            if (rsp_list.size() == 0)
            {
                NCacheLog.Warn("MsgDispatcher.sendMessage()", " response list is empty");
                return(null);
            }
            if (rsp_list.size() > 1)
            {
                NCacheLog.Warn("MsgDispatcher.sendMessage()", "response list contains more that 1 response; returning first response !");
            }
            rsp = (Rsp)rsp_list.elementAt(0);
            if (rsp.wasSuspected())
            {
                throw new SuspectedException(dest);
            }
            if (!rsp.wasReceived())
            {
                //we verify for the destination whether it is still part of the cluster or not.
                if (corr.CheckForMembership((Address)rsp.Sender))
                {
                    throw new Runtime.Exceptions.TimeoutException("operation timeout");
                }

                else
                {
                    rsp.suspected = true;
                    throw new SuspectedException(dest);
                }
            }
            return(rsp.Value);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Returns the set of nodes where the addition was performed as an atomic operation.
        /// </summary>
        /// <param name="results">responses collected from all members of cluster.</param>
        /// <returns>list of nodes where the operation succeeded</returns>
        public static CacheAddResult FindAtomicAddStatusReplicated(RspList results)
        {
            CacheAddResult res = CacheAddResult.Failure;

            if (results == null)
            {
                return(res);
            }
            int timeoutCount   = 0;
            int suspectedCount = 0;
            int successCount   = 0;

            for (int i = 0; i < results.size(); i++)
            {
                Rsp rsp = (Rsp)results.elementAt(i);

                if (rsp.wasSuspected())
                {
                    //throw new Alachisoft.NGroups.SuspectedException(rsp.Sender);
                    suspectedCount++;
                    continue;
                }
                if (!rsp.wasReceived() && !rsp.wasSuspected())
                {
                    //throw new Alachisoft.NGroups.TimeoutException();
                    timeoutCount++;
                    continue;
                }
                res = (CacheAddResult)rsp.Value;
                if (res == CacheAddResult.Success)
                {
                    successCount++;
                }
                if (res != CacheAddResult.Success && res != CacheAddResult.KeyExists)
                {
                    return(res);
                }
            }
            if (suspectedCount > 0 && successCount > 0 && (suspectedCount + successCount == results.size()))
            {
                //as operation is successfull on all other nodes other than suspected node(s).
                return(CacheAddResult.Success);
            }
            if (timeoutCount > 0 && (timeoutCount + successCount == results.size()))
            {
                if (successCount > 0)
                {
                    //operation is not succeeded on some of the nodes; therefore we throw timeout exception.
                    return(CacheAddResult.PartialTimeout);
                }
                else
                {
                    //operation timed out on all of the node; no need to rollback.
                    return(CacheAddResult.FullTimeout);
                }
            }
            if (timeoutCount > 0 && suspectedCount > 0)
            {
                if (successCount > 0)
                {
                    return(CacheAddResult.PartialTimeout);
                }
                else
                {
                    return(CacheAddResult.FullTimeout);
                }
            }

            return(res);
        }