/*
         * 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));
                }
            }
        }
Beispiel #2
0
        public async Task <IEnumerable <PartitionServersDto> > OnListPartitions()
        {
            Conditions.AssertArgument(listPartitionHandler != null);
            WaitFreeze();
            await WaitDelay();

            return(listPartitionHandler());
        }
 public static void SetContext(NamingService namingService)
 {
     lock (instanceLock) {
         Conditions.AssertArgument(namingService != null);
         Conditions.AssertState(instance == null);
         instance = new SimpleKVSMessageLayer(namingService);
     }
 }
        public async Task OnBroadcastFailure(BroadcastFailureArguments arguments)
        {
            Conditions.AssertArgument(broadcastFailureHandler != null);
            WaitFreeze();
            await WaitDelay();

            broadcastFailureHandler(arguments);
        }
Beispiel #5
0
        public bool RegisterPartition(string partitionId, ImmutableHashSet <string> serverIds)
        {
            Conditions.AssertArgument(serverIds.Contains(selfId));

            return(partitionHandlers.TryAdd(
                       partitionId,
                       new PartitionReliableBroadcastHandler(
                           selfId,
                           partitionId,
                           serverIds,
                           writeMessageHandler)));
        }
Beispiel #6
0
        public async Task <string> OnLookupMaster(string partitionId)
        {
            Conditions.AssertArgument(lookupMasterHandler != null);
            WaitFreeze();
            await WaitDelay();

            if (lookupMasterHandler(partitionId, out string masterUrl))
            {
                return(masterUrl);
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
        public async Task <string> OnLookup(string serverId)
        {
            Conditions.AssertArgument(lookupHandler != null);
            WaitFreeze();
            await WaitDelay();

            if (lookupHandler(serverId, out string serverUrl))
            {
                return(serverUrl);
            }
            else
            {
                return(null);
            }
        }
Beispiel #8
0
 public static ImmutableVectorClock FromClocks(IEnumerable <KeyValuePair <string, int> > clocks)
 {
     Conditions.AssertArgument(clocks != null);
     return(new ImmutableVectorClock(ImmutableDictionary.CreateRange(clocks)));
 }
Beispiel #9
0
 public static ImmutableVectorClock CopyOf(VectorClock other)
 {
     Conditions.AssertArgument(other != null);
     return(new ImmutableVectorClock(other.Clocks));
 }