示例#1
0
        /*
         * Creates a partition with the given name. Also stores all server ids and urls
         * Throws ArgumentException if a partition with the given name already exists or
         *                          if a url for an existing id is diferent from the previous id or
         *                          if partition does not have master id
         * Throws InvalidOperationException if the state of the object is incorrect
         *                                  (should never happen)
         */
        public void JoinPartition(JoinPartitionArguments arguments)
        {
            string partitionId = arguments.PartitionId;
            IEnumerable <Tuple <string, string> > members = arguments.Members;
            string masterId = arguments.MasterId;

            HashSet <string> partition = BuildPartition(members);

            lock (this) {
                Conditions.AssertArgument(!partitions.ContainsKey(partitionId));
                Conditions.AssertArgument(partition.Contains(masterId));

                foreach ((string serverId, string serverUrl) in members)
                {
                    bool alreadyExists = TryGetServer(serverId, out string currentUrl);

                    // Url mapping must not exist or be the same as before
                    Conditions.AssertArgument(
                        !alreadyExists || currentUrl.Equals(serverUrl));
                }

                // The following operations should never raise an error
                Conditions.AssertState(partitions.TryAdd(partitionId, partition));
                Conditions.AssertState(partitionMasters.TryAdd(partitionId, masterId));

                // Insert servers correspondence
                foreach ((string serverId, string serverUrl) in members)
                {
                    Conditions.AssertState(RegisterServer(serverId, serverUrl));
                }
            }
        }
        public void OnJoinPartitionRequest(JoinPartitionArguments arguments)
        {
            string partitionId = arguments.PartitionId;

            partitionsDB.JoinPartition(arguments);
            partitionsDB.TryGetPartition(partitionId, out ImmutableHashSet <string> serverIds);

            // Only register partitions that the server belongs to for broadcast
            if (serverIds.Contains(serverConfig.ServerId))
            {
                valueTimestamps.TryAdd(partitionId, MutableVectorClock.Empty());
                emitedWritesTimestamps.TryAdd(partitionId, MutableVectorClock.Empty());
                ReliableBroadcastLayer.Instance.RegisterPartition(partitionId, serverIds);
            }
        }
 public void JoinPartition(JoinPartitionArguments arguments)
 {
     partitionsDB.JoinPartition(arguments);
 }