/** * IMetadataToPM */ public void MetadataLocation(string metadataId, string location) { Console.WriteLine("METADATA LOCATION " + metadataId); IMetadataToMetadata metadata = (IMetadataToMetadata)Activator.GetObject( typeof(IMetadataToMetadata), location); metadatas[metadataId] = metadata; }
// 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); }
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(); } }
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(); } }
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(); } }
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(); } }
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; }