Пример #1
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);
        }
Пример #2
0
        /// <summary>
        /// Remove the objects from the cluster.
        /// </summary>
        /// <param name="dest"></param>
        /// <param name="keys">keys of the entries.</param>
        /// <param name="ir"></param>
        /// <param name="cbEntry"></param>
        /// <param name="notify"></param>
        /// <param name="operationContext"></param>
        /// <returns>list of failed keys</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemove"/> on every server node in the cluster.
        /// </remarks>
        protected Hashtable Clustered_Remove(Address dest, object[] keys, ItemRemoveReason ir, CallbackEntry cbEntry, bool notify, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("PartCacheBase.RemoveBlk", "");
            }

            Hashtable removedEntries = new Hashtable();
            ArrayList dests          = new ArrayList();

            dests.Add(dest);
            try
            {
                Function func    = new Function((int)OpCodes.Remove, new object[] { keys, ir, notify, cbEntry, operationContext }, false);
                RspList  results = Cluster.Multicast(dests, func, GetFirstResponse, false);

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

                if (results.SuspectedMembers.Count == dests.Count)
                {
                    //All the members of this group has gone down.
                    //we must try this operation on some other group.
                    throw new Runtime.Exceptions.SuspectedException("operation failed because the group member was suspected");
                }

                ClusterHelper.ValidateResponses(results, typeof(Hashtable), Name);
                ArrayList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(Hashtable));

                if (rspList.Count <= 0)
                {
                    return(removedEntries);
                }

                IEnumerator ia = rspList.GetEnumerator();
                while (ia.MoveNext())
                {
                    Rsp       rsp     = (Rsp)ia.Current;
                    Hashtable removed = (Hashtable)rsp.Value;

                    IDictionaryEnumerator ide = removed.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        removedEntries.Add(ide.Key, ide.Value);
                    }
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            return(removedEntries);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// Remove the objects from the cluster.
        /// </summary>
        /// <param name="keys">keys of the entries.</param>
        /// <returns>list of failed keys</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemove"/> on every server node in the cluster.
        /// </remarks>
        protected Hashtable Clustered_Remove(object[] keys, ItemRemoveReason ir, CallbackEntry cbEntry, bool notify, OperationContext operationContext)
        {
            Hashtable removedEntries = new Hashtable();

            try
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.RemoveBlk", "enter");
                }
                Function func    = new Function((int)OpCodes.Remove, new object[] { keys, ir, notify, cbEntry, operationContext }, false);
                RspList  results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL);

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

                ClusterHelper.ValidateResponses(results, typeof(Hashtable), Name);
                ArrayList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(Hashtable));

                if (rspList.Count <= 0)
                {
                    return(removedEntries);
                }

                IEnumerator ia = rspList.GetEnumerator();
                while (ia.MoveNext())
                {
                    Rsp       rsp     = (Rsp)ia.Current;
                    Hashtable removed = (Hashtable)rsp.Value;

                    IDictionaryEnumerator ide = removed.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        removedEntries.Add(ide.Key, ide.Value);
                    }
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            finally
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.RemoveBlk", "exit");
                }
            }
            return(removedEntries);
        }
Пример #5
0
        /// <summary>
        /// Remove the object from the cluster.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <returns>cache entry.</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemove"/> on every server node in the cluster.
        /// </remarks>
        protected CacheEntry Clustered_Remove(object key, ItemRemoveReason ir, CallbackEntry cbEntry, bool notify, object lockId, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry retVal = null;

            try
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.Remove", "enter");
                }
                Function func    = new Function((int)OpCodes.Remove, new object[] { key, ir, notify, cbEntry, lockId, accessType, operationContext }, false, key);
                RspList  results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL, _asyncOperation);
                if (results == null)
                {
                    return(retVal);
                }

                ClusterHelper.ValidateResponses(results, typeof(OperationResponse), Name);

                Rsp rsp = ClusterHelper.FindAtomicRemoveStatusReplicated(results);
                if (rsp == null)
                {
                    return(retVal);
                }

                OperationResponse opRes = rsp.Value as OperationResponse;
                if (opRes != null)
                {
                    CacheEntry entry = opRes.SerializablePayload as CacheEntry;
                    if (entry != null)
                    {
                        entry.Value = opRes.UserPayload;
                    }
                    return(entry);
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            finally
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.Remove", "exit");
                }
            }
            return(retVal);
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
0
        /// <summary>
        /// Retrieve the list of keys fron the cache for the given group or sub group.
        /// </summary>
        protected Hashtable Clustered_GetData(ArrayList dests, string group, string subGroup, OperationContext operationContext)
        {
            Hashtable table = new Hashtable();

            try
            {
                Function func = new Function((int)OpCodes.GetData, new object[] { group, subGroup, operationContext }, true);
                func.Cancellable = true;
                RspList results = Cluster.Multicast(dests, func, GroupRequest.GET_ALL, false);
                if (results == null)
                {
                    return(null);
                }

                ClusterHelper.ValidateResponses(results, typeof(HashVector), Name);
                IList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(HashVector));

                if (rspList.Count <= 0)
                {
                    return(null);
                }
                else
                {
                    IEnumerator im = rspList.GetEnumerator();
                    while (im.MoveNext())
                    {
                        Rsp       rsp    = (Rsp)im.Current;
                        Hashtable cTable = (Hashtable)rsp.Value;
                        if (cTable != null)
                        {
                            IDictionaryEnumerator ide = cTable.GetEnumerator();
                            while (ide.MoveNext())
                            {
                                table[ide.Key] = ide.Value;
                            }
                        }
                    }
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }

            return(table);
        }
Пример #9
0
        protected ArrayList Clustered_GetKeysByTag(ArrayList dests, string[] tags, TagComparisonType comparisonType, bool excludeSelf, OperationContext operationContext)
        {
            ArrayList keys = new ArrayList();

            try
            {
                Function func = new Function((int)OpCodes.GetKeysByTag, new object[] { tags, comparisonType, operationContext }, excludeSelf);
                func.Cancellable = true;
                RspList results = Cluster.Multicast(dests, func, GroupRequest.GET_ALL, false, Cluster.Timeout * 10);
                if (results == null)
                {
                    return(null);
                }

                ClusterHelper.ValidateResponses(results, typeof(ArrayList), Name);
                IList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(ClusteredArrayList));

                if (rspList.Count <= 0)
                {
                    return(null);
                }
                else
                {
                    IEnumerator im = rspList.GetEnumerator();
                    while (im.MoveNext())
                    {
                        Rsp         rsp     = (Rsp)im.Current;
                        ICollection entries = (ICollection)rsp.Value;
                        if (entries != null)
                        {
                            IEnumerator ide = entries.GetEnumerator();
                            while (ide.MoveNext())
                            {
                                keys.Add(ide.Current);
                            }
                        }
                    }
                }

                return(keys);
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
        }
Пример #10
0
        protected Hashtable Clustered_GetTag(ArrayList dests, string[] tags, TagComparisonType comparisonType, bool excludeSelf, OperationContext operationContext)
        {
            Hashtable keyValues = new Hashtable();

            try
            {
                Function func = new Function((int)OpCodes.GetTag, new object[] { tags, comparisonType, operationContext }, excludeSelf);
                func.Cancellable = true;
                RspList results = Cluster.BroadcastToMultiple(dests, func, GroupRequest.GET_ALL, false);
                if (results == null)
                {
                    return(null);
                }

                ClusterHelper.ValidateResponses(results, typeof(HashVector), Name);
                IList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(HashVector));

                if (rspList.Count <= 0)
                {
                    return(null);
                }
                else
                {
                    IEnumerator im = rspList.GetEnumerator();
                    while (im.MoveNext())
                    {
                        Rsp         rsp     = (Rsp)im.Current;
                        IDictionary entries = (IDictionary)rsp.Value;
                        if (entries != null)
                        {
                            IDictionaryEnumerator ide = entries.GetEnumerator();
                            while (ide.MoveNext())
                            {
                                keyValues[ide.Key] = ide.Value;
                            }
                        }
                    }
                }

                return(keyValues);
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
        }
Пример #11
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);
        }
Пример #12
0
        /// <summary>
        /// Remove the objects from the cluster.
        /// </summary>
        /// <param name="keys">keys of the entries.</param>
        /// <returns>list of failed keys</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemove"/> on every server node in the cluster.
        /// </remarks>
        protected Hashtable Clustered_RemoveGroup(string group, string subGroup, bool notify, OperationContext operationContext)
        {
            Hashtable removedEntries = new Hashtable();

            try
            {
                Function func = new Function((int)OpCodes.RemoveGroup, new object[] { group, subGroup, notify, operationContext }, false);
                func.Cancellable = true;
                RspList results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL, false);

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

                ClusterHelper.ValidateResponses(results, typeof(Hashtable), Name);
                IList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(Hashtable));

                if (rspList.Count <= 0)
                {
                    return(removedEntries);
                }

                IEnumerator ia = rspList.GetEnumerator();
                while (ia.MoveNext())
                {
                    Rsp       rsp     = (Rsp)ia.Current;
                    Hashtable removed = (Hashtable)rsp.Value;

                    IDictionaryEnumerator ide = removed.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        removedEntries.Add(ide.Key, ide.Value);
                    }
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }

            return(removedEntries);
        }
Пример #13
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);
        }
Пример #14
0
        /// <summary>
        /// Retrieve the list of keys fron the cache for the given group or sub group.
        /// </summary>
        protected ArrayList Clustered_GetKeys(ArrayList dests, string group, string subGroup)
        {
            ArrayList list = new ArrayList();

            try
            {
                Function func = new Function((int)OpCodes.GetKeys, new object[] { group, subGroup }, true);
                func.Cancellable = true;
                RspList results = Cluster.Multicast(dests, func, GroupRequest.GET_ALL, false);
                if (results == null)
                {
                    return(null);
                }

                ClusterHelper.ValidateResponses(results, typeof(ArrayList), Name);
                IList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(ClusteredArrayList));

                if (rspList.Count <= 0)
                {
                    return(null);
                }
                else
                {
                    IEnumerator im = rspList.GetEnumerator();
                    while (im.MoveNext())
                    {
                        Rsp       rsp   = (Rsp)im.Current;
                        ArrayList cList = (ArrayList)rsp.Value;
                        if (cList != null)
                        {
                            list.AddRange(cList);
                        }
                    }
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            return(list);
        }
Пример #15
0
        protected QueryResultSet Clustered_Search(ArrayList dests, string queryText, IDictionary values, bool excludeSelf, OperationContext operationContext)
        {
            QueryResultSet resultSet = new QueryResultSet();

            try
            {
                Function func    = new Function((int)OpCodes.Search, new object[] { queryText, values, operationContext }, excludeSelf);
                RspList  results = Cluster.BroadcastToMultiple(dests, func, GroupRequest.GET_ALL, false);

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

                ClusterHelper.ValidateResponses(results, typeof(QueryResultSet), Name);
                ArrayList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(QueryResultSet));

                if (rspList.Count <= 0)
                {
                    return(null);
                }
                else
                {
                    IEnumerator im = rspList.GetEnumerator();
                    while (im.MoveNext())
                    {
                        Rsp            rsp         = (Rsp)im.Current;
                        QueryResultSet cRestultSet = (QueryResultSet)rsp.Value;
                        resultSet.Compile(cRestultSet);
                    }
                }

                return(resultSet);
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
        }
Пример #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);
                }
            }
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #21
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            if (IsHaveAllow(context.Filters))
            {
                return;
            }
            //需要登录权限的,先从header中拿
            string Authorization = context.HttpContext.Request.Headers["Authorization"].ToString();

            if (!string.IsNullOrEmpty(Authorization))
            {
                //验证token是否正常

                var cacheAuthor = _cache.Get(Authorization);
                if (cacheAuthor != null)
                {
                    //刷新当前token时间
                    _cache.Set(Authorization, cacheAuthor, new MemoryCacheEntryOptions
                    {
                        SlidingExpiration = TimeSpan.FromHours(3)
                    });
                }
                else
                {
                    //已经过期了
                    var jsonModel = Rsp.Fail("已过期", -999);
                    context.Result = new JsonResult(jsonModel);
                }
            }
            else
            {
                // 返回未登录的信息
                var jsonModel = Rsp.Fail("未登录", -999);
                context.Result = new JsonResult(jsonModel);
            }
        }
Пример #22
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);
        }
Пример #23
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);
        }
Пример #24
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);
            }
        }
Пример #25
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);
            }
        }
Пример #26
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);
        }
Пример #27
0
        /// <summary>
        /// 创建默认的成功响应
        /// </summary>
        /// <returns></returns>
        public static Rsp DefaultSuccessResponse()
        {
            Rsp response = new Rsp();

            return(SetSuccess <Rsp>(response));
        }
Пример #28
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);
            }
        }
Пример #29
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);
        }
Пример #30
0
        protected byte[] DownloadCore()
        {
            WebRequest  Web;
            WebResponse Rsp;

            System.IO.Stream Stm;

            Web = WebRequest.Create(_url);

            HttpRequest Request = HttpContext.Current.Request;

            string cookies = Request.Headers["Cookie"];

            Web.Headers.Add(HttpRequestHeader.Cookie, cookies);
            ((HttpWebRequest)Web).UserAgent = @"Mozilla/4.0 (compatible; Shotgun Webdownloader 1.0; Windows NT 5.1; )";

            if (_postdata != null)
            {//以post方式提交
                Web.Method = "POST";
                if (_Encoder == null)
                {
                    _Encoder = System.Text.ASCIIEncoding.UTF8;
                }
                ((HttpWebRequest)Web).ServicePoint.Expect100Continue = false;
                //Web.Headers[HttpRequestHeader.ContentLength] = _Encoder.EncodingName;
                Web.Headers[HttpRequestHeader.ContentEncoding] = _Encoder.WebName;
                ((HttpWebRequest)Web).ContentType = @"application/x-www-form-urlencoded";
                StreamWriter pdStm = new StreamWriter(Web.GetRequestStream(), _Encoder);
                pdStm.Write(_postdata);
                pdStm.Close();
                pdStm.Dispose();
            }

            //Web.Timeout = _timeOut;

            try
            {
                Rsp = Web.GetResponse();
            }
            catch (Exception ex)
            {
                if (Request.IsLocal)
                {
                    throw ex;
                }
                return(null);
            }

            int MaxLength, RecvicedLength, r;

            MaxLength      = (int)Rsp.ContentLength;
            RecvicedLength = 0;
            byte[] bin = new byte[MaxLength];

            Stm = Rsp.GetResponseStream();

            do
            {
                r = Stm.Read(bin, RecvicedLength, MaxLength - RecvicedLength);
                RecvicedLength += r;
            }while (RecvicedLength < MaxLength);
            Stm.Close();
            Stm.Dispose();
            Rsp.Close();
            return(bin);
        }