예제 #1
0
            public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
            {
                var slot = serverSelectionStrategy.HashSlot(Key);

                slot = serverSelectionStrategy.CombineSlot(slot, key1);
                return(slot);
            }
        internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, string nodes, EndPoint origin)
        {
            // Beware: Any exception thrown here will wreak silent havoc like inability to connect to cluster nodes or non returning calls
            this.serverSelectionStrategy = serverSelectionStrategy;
            this.Origin = origin;
            using (var reader = new StringReader(nodes))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }
                    var node = new ClusterNode(this, line, origin);

                    // Be resilient to ":0 {master,slave},fail,noaddr" nodes
                    if (node.IsNoAddr)
                    {
                        continue;
                    }

                    // Override the origin value with the endpoint advertised with the target node to
                    // make sure that things like clusterConfiguration[clusterConfiguration.Origin]
                    // will work as expected.
                    if (node.IsMyself)
                    {
                        this.Origin = node.EndPoint;
                    }

                    if (nodeLookup.ContainsKey(node.EndPoint))
                    {
                        // Deal with conflicting node entries for the same endpoint
                        // This can happen in dynamic environments when a node goes down and a new one is created
                        // to replace it.
                        if (!node.IsConnected)
                        {
                            // The node we're trying to add is probably about to become stale. Ignore it.
                            continue;
                        }
                        else if (!nodeLookup[node.EndPoint].IsConnected)
                        {
                            // The node we registered previously is probably stale. Replace it with a known good node.
                            nodeLookup[node.EndPoint] = node;
                        }
                        else
                        {
                            // We have conflicting connected nodes. There's nothing much we can do other than
                            // wait for the cluster state to converge and refresh on the next pass.
                            // The same is true if we have multiple disconnected nodes.
                        }
                    }
                    else
                    {
                        nodeLookup.Add(node.EndPoint, node);
                    }
                }
            }
        }
예제 #3
0
            public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
            {
                var slot = serverSelectionStrategy.HashSlot(Key);

                for (int i = 0; i < keys.Length; i++)
                {
                    slot = serverSelectionStrategy.CombineSlot(slot, keys[i]);
                }
                return(slot);
            }
            public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
            {
                int slot = ServerSelectionStrategy.NoSlot;

                for (int i = 0; i < conditions.Length; i++)
                {
                    int newSlot = conditions[i].Condition.GetHashSlot(serverSelectionStrategy);
                    slot = serverSelectionStrategy.CombineSlot(slot, newSlot);
                    if (slot == ServerSelectionStrategy.MultipleSlots)
                    {
                        return(slot);
                    }
                }
                for (int i = 0; i < operations.Length; i++)
                {
                    int newSlot = operations[i].Wrapped.GetHashSlot(serverSelectionStrategy);
                    slot = serverSelectionStrategy.CombineSlot(slot, newSlot);
                    if (slot == ServerSelectionStrategy.MultipleSlots)
                    {
                        return(slot);
                    }
                }
                return(slot);
            }
예제 #5
0
 internal override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
 {
     return(serverSelectionStrategy.HashSlot(key));
 }
예제 #6
0
 internal abstract int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy);
예제 #7
0
 public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
 {
     return(serverSelectionStrategy.HashSlot(Key));
 }
예제 #8
0
 public virtual int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
 {
     return(ServerSelectionStrategy.NoSlot);
 }
예제 #9
0
            public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
            {
                var slot = base.GetHashSlot(serverSelectionStrategy);

                return(serverSelectionStrategy.CombineSlot(slot, key1));
            }