示例#1
0
        /**
         * IMetadataToPM
         */

        public void MetadataLocation(string metadataId, string location)
        {
            Console.WriteLine("METADATA LOCATION " + metadataId);

            IMetadataToMetadata metadata = (IMetadataToMetadata)Activator.GetObject(
                typeof(IMetadataToMetadata),
                location);

            metadatas[metadataId] = metadata;
        }
示例#2
0
        // Tries to elect himself as the new master sending a vote to
        // each alive metadata with its id:clock
        // Other metadatas compare the votes, the one with the highest clock / lowest id
        // wins, and returns that vote
        public string Master()
        {
            if (fail)
            {
                throw new ProcessFailedException(id);
            }

            Console.WriteLine("MASTER ELECTION");

            // if I'm the master
            if (ImMaster)
            {
                return(id);
            }

            // checks if the master I know is down
            try
            {
                return(metadatas[master].Master());
            }
            catch (ProcessFailedException) { }

            // previous master is down, starting Uprising
            MasterVote masterVote = new MasterVote(id, clock);

            foreach (var entry in metadatas)
            {
                IMetadataToMetadata metadata = entry.Value;
                try
                {
                    // chooses better vote between previous master and the one from the metadata
                    masterVote = MasterVote.Choose(metadata.Uprising(masterVote), masterVote);
                }
                catch (ProcessFailedException) { }
            }
            // second round to confirm votes
            foreach (var entry in metadatas)
            {
                IMetadataToMetadata metadata = entry.Value;
                try
                {
                    // chooses better vote between previous master and the one from the metadata
                    metadata.Uprising(masterVote, true);
                }
                catch (ProcessFailedException) { }
            }

            master = masterVote.Id;

            return(master);
        }
示例#3
0
 private void DataServerOnMetadatas(string dataServerId, string location, int sequence)
 {
     foreach (var entry in metadatas)
     {
         string metadataId            = entry.Key;
         IMetadataToMetadata metadata = entry.Value;
         Thread request = new Thread(() =>
         {
             try
             {
                 metadata.DataServerOnMetadata(dataServerId, location, sequence);
             }
             catch (ProcessFailedException) { }
         });
         request.Start();
     }
 }
示例#4
0
 private void DeleteOnMetadatas(string filename, int sequence)
 {
     foreach (var entry in metadatas)
     {
         string metadataId            = entry.Key;
         IMetadataToMetadata metadata = entry.Value;
         Thread request = new Thread(() =>
         {
             try
             {
                 metadata.DeleteOnMetadata(filename, sequence);
             }
             catch (ProcessFailedException) { }
         });
         request.Start();
     }
 }
示例#5
0
 private void CreateOnMetadatas(string clientId, string filename, int nbDataServers, int readQuorum, int writeQuorum, int sequence)
 {
     foreach (var entry in metadatas)
     {
         string metadataId            = entry.Key;
         IMetadataToMetadata metadata = entry.Value;
         Thread request = new Thread(() =>
         {
             try
             {
                 metadata.CreateOnMetadata(clientId, filename, nbDataServers, readQuorum, writeQuorum, sequence);
             }
             catch (ProcessFailedException) { }
         });
         request.Start();
     }
 }
示例#6
0
 private void MigrateFileOnMetadatas(string filename, string oldDataServerId, string newDataServerId, string oldLocalFilename, string newLocalFilename, int sequence)
 {
     foreach (var entry in metadatas)
     {
         string metadataId            = entry.Key;
         IMetadataToMetadata metadata = entry.Value;
         Thread request = new Thread(() =>
         {
             try
             {
                 metadata.MigrateFileOnMetadata(filename, oldDataServerId, newDataServerId, oldLocalFilename, newLocalFilename, sequence);
             }
             catch (ProcessFailedException) { }
         });
         request.Start();
     }
 }
示例#7
0
        public void Recover()
        {
            Console.WriteLine("RECOVER");

            // metadata bootup
            // since we force a metadata to start with recover
            if (master == string.Empty)
            {
                MetadataBootup();
            }

            foreach (var entry in metadatas)
            {
                try
                {
                    IMetadataToMetadata metadata = entry.Value;

                    // stops on the first not failed metadata
                    master = metadata.Master();
                    // sets fail to false so it starts receiving requests
                    int sequence = clock;
                    fail = false;
                    // updates its state with the master
                    if (!ImMaster)
                    {
                        MetadataDiff diff = metadatas[master].UpdateMetadata(id, sequence);

                        Console.WriteLine("--RECEIVING STATE UPDATE--");
                        log.MergeDiff(this, diff);
                        Console.WriteLine("--STATE UPDATE FINISHED--");
                    }
                    return;
                }
                catch (ProcessFailedException) { }
            }

            // sets fail to false so it starts receiving requests
            master = id;
            fail   = false;
        }