Пример #1
0
        public bool AddServer(string URL)
        {
            //Console.WriteLine("AddServer called");
            int index = getIndex();

            String primary_url = URL;
            String replica_url = String.Empty;

            UIDRange newUIDRange = null;

            if (lookupTable.Size() == 0)
            {
                //Primeiro servidor
                newUIDRange = lookupTable.DefaultUIDRange;

            }
            else
            {

                TableRow temp = lookupTable.GetRow(index);
                string oldPrimaryUrl = temp.GetServerPair().GetPrimary();
                newUIDRange = temp.GetUIDRange().Split();

                replica_url = serverReplicasTable.getReplica();

                IServer oldPrimaryServer = (IServer)Activator.GetObject(typeof(IServer), oldPrimaryUrl);
                ulong oldPrimaryTid = oldPrimaryServer.GetMaxTID();

                oldPrimaryServer.AddTIDToPendingTable(primary_url, oldPrimaryTid, newUIDRange.GetRangeStart(), newUIDRange.GetRangeEnd());

                IServer newPrimaryServer = (IServer)Activator.GetObject(typeof(IServer), primary_url);
                newPrimaryServer.Init(oldPrimaryTid, replica_url);

                //A tabela so temos o servidor 1 e entrou um novo srvidor
                //como agora temos 2 servidores, o novo servidor pode
                //ser replica do servidor 1

                if (lookupTable.Size() == 1)
                {
                    //Como era o unico servidor no sistema nao tinha replica
                    //adiciona-mos a replica agora que entrou um segundo
                    //servidor, e este o que entrou (primary_url) e a replica
                    //do anterior

                    //outlink
                    ServerPair sp = new ServerPair(temp.GetServerPair().GetPrimary(), primary_url);
                    lookupTable.ReplaceRow(index, new TableRow(sp, temp.GetUIDRange()));

                    //inlink
                    serverReplicasTable.addReplicaToServer(primary_url, temp.GetServerPair().GetPrimary());

                    oldPrimaryServer.SetReplica(primary_url);

                }

            }

            //outlinks
            ServerPair newServerPair = new ServerPair(primary_url, replica_url);
            TableRow newTableRow = new TableRow(newServerPair, newUIDRange);
            lookupTable.InsertRow(index, newTableRow);

            //inlinks
            //primary_url e adicionado como candidato para
            //ser escolhido como replica de qualquer outro
            //servidor
            serverReplicasTable.addPrimary(primary_url);

            //Se existir replica disponivel
            //replica_url e responsavel por primary_url
            if (!replica_url.Equals(String.Empty))
                serverReplicasTable.addReplicaToServer(replica_url, primary_url);

            return true;
        }
Пример #2
0
 public void ReplaceRow(int index, TableRow row)
 {
     lookupTable[index] = row;
 }
Пример #3
0
 public void InsertRow(int index, TableRow row)
 {
     lookupTable.Insert(index,row);
 }
Пример #4
0
 public void RemoveRow(TableRow row)
 {
     lookupTable.Remove(row);
 }