Example #1
0
        //Get endpoints
        public string GetPrimaryEndpoint(int uid)
        {
            ServerPair pair = lookupTable.GetServerPair(uid);

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

            return(pair.GetPrimary());
        }
Example #2
0
        public TableRow GetRowGivenPrimary(String primaryUrl)
        {
            foreach (TableRow row in lookupTable)
            {
                ServerPair pair = row.GetServerPair();

                if (primaryUrl.Equals(pair.GetPrimary()))
                {
                    return(row); //DEVIAMOS LANCAR EXCEPCAO CASO NAO EXISTA O MAIN SERVER.
                }
            }
            return(null);
        }
Example #3
0
        //Check if given string correspond to replica(false) or main server(true)
        public bool IsPrimary(String url)
        {
            foreach (TableRow row in lookupTable)
            {
                ServerPair pair = row.GetServerPair();
                if (url.Equals(pair.GetPrimary()))
                {
                    return(true);
                }

                //else if (url.Equals(pair.GetReplica()))
                //    return false;
            }

            //DEVERIA SER LANCADA UMA EXCEPCAO POR NAO EXISTIR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            return(false);
        }
Example #4
0
        public bool RemoveServer(string url)
        {
            Console.WriteLine("RemoveServer");

            bool isPrimary = lookupTable.IsPrimary(url);

            Console.WriteLine("isPrimary: " + isPrimary);


            ////Falhou deve remover server e replica
            //List<String> replicatedServers = serverReplicasTable.getReplicasFromServer(url);

            //if (replicatedServers.Count != 0)
            //{
            //    //NOTIFICAR DA ALTERACAO

            //    foreach (String replicatedServer in replicatedServers)
            //    {
            //        IServer server = (IServer)Activator.GetObject(typeof(IServer), replicatedServer);
            //        //AddTIDToPendingTable(string url, ulong tid, int startRange, int endRange)
            //        AddTIDToPendingTableAsyncDelegate remoteDel = new AddTIDToPendingTableAsyncDelegate(server.AddTIDToPendingTable);
            //        UIDRange primaryRange = lookupTable.GetRowGivenPrimary(replicatedServer).GetUIDRange();
            //        remoteDel.BeginInvoke(newReplica, server.GetMaxTID(), primaryRange.GetRangeStart(), primaryRange.GetRangeEnd(), null, null);
            //    }
            //}

            //IServer newPrimaryServer = (IServer)Activator.GetObject(typeof(IServer), newPrimary);
            //AddTIDToPendingTableAsyncDelegate primaryServerDel = new AddTIDToPendingTableAsyncDelegate(newPrimaryServer.AddTIDToPendingTable);
            //UIDRange newPrimaryRange = lookupTable.GetRowGivenPrimary(newPrimary).GetUIDRange();
            //primaryServerDel.BeginInvoke(newReplica, newPrimaryServer.GetMaxTID(), newPrimaryRange.GetRangeStart(), newPrimaryRange.GetRangeEnd(), null, null);

            //Console.WriteLine("Removeu! ");

            serverReplicasTable.removeServerAndReplicas(url);
            String newReplica = serverReplicasTable.getReplica();

            Console.WriteLine("newReplica: " + newReplica);

            String newPrimary = null;


            //if the failed server is a primary server we request another replica and set replica as primary
            if (isPrimary)
            {
                lookupTable.SwapPrimaryReplica(url, newReplica);
                Console.WriteLine("swap.");

                newPrimary = lookupTable.GetRowGivenReplica(newReplica).GetServerPair().GetReplica();

                Console.WriteLine("newPrimary");

                //if the failed server is a replica we get a new replica
            }
            else
            {
                lookupTable.SetNewReplica(url, newReplica);
                //Console.WriteLine("setNewReplica.");

                TableRow r = lookupTable.GetRowGivenReplica(newReplica);

                Console.WriteLine(r.ToString());


                ServerPair sp = r.GetServerPair();
                newPrimary = sp.GetPrimary();

                Console.WriteLine("newPrimary");
                //LANCAR EXCEPCAO CASO HAJA FALHA
            }


            return(true);
            //throw new NotImplementedException();
        }