internal static bool recover(string url) { if (isFailedServer(url)) { int failed_id = getFailedID(url); failedServers.Remove(failed_id); // Sets the original URL availableServers[failed_id] = url; string failed_sucessorURL = getWorkerSucessor(failed_id); string failed_predecessorURL = getWorkerPredecessor(failed_id); IMasterWorker failed_predecessor = (IMasterWorker)Activator.GetObject( typeof(IMasterWorker), failed_predecessorURL + "MasterWorker"); IMasterWorker datastore = (IMasterWorker)Activator.GetObject( typeof(IMasterWorker), url + "MasterWorker"); // Set sucessor of the failed predecessor to the recovered server failed_predecessor.setSucessor(url); // Fetch data from from failed predecessor to put in his list of updates datastore.fetch_data(failed_predecessorURL); // Fetch recover data to recovered server to fetch the primary data of his sucessor // also sets his sucessor datastore.fetch_recover_data(failed_sucessorURL); return(true); } if (isFreezedServer(url)) { int freeze_id = getFreezeID(url); freezedServers.Remove(freeze_id); availableServers[freeze_id] = url; IMasterWorker worker = (IMasterWorker)Activator.GetObject(typeof(IMasterWorker), url + "MasterWorker"); worker.recover(); return(true); } return(false); }
// Master tells the worker to fail itself and stabilizes the system internal static bool fail(string url) { if (isFailedServer(url)) { return(false); } int id = getAvailableID(url); if (isFreezedServer(url)) { freezedServers.Remove(id); } failedServers.Add(id, url); string failed_sucessorURL = getWorkerSucessor(id); string failed_predecessorURL = getWorkerPredecessor(id); IMasterWorker failed_sucessor = (IMasterWorker)Activator.GetObject( typeof(IMasterWorker), failed_sucessorURL + "MasterWorker"); IMasterWorker failed_predecessor = (IMasterWorker)Activator.GetObject( typeof(IMasterWorker), failed_predecessorURL + "MasterWorker"); // Na posicao original dos available trocar o url pelo sucessor availableServers[id] = failed_sucessorURL; //Set sucessor of failed_predecessor to failed_sucessor -> Problema de concorrencia entre estas 2 operções? failed_predecessor.setSucessor(failed_sucessorURL); //Tell the sucessor to substitute the failed server failed_sucessor.substituteFailedServer(); //Tell the sucessor to fetch the original data from the failed_predecessor and put it in his the list of updates failed_sucessor.fetch_data(failed_predecessorURL); IMasterWorker datastore = (IMasterWorker)Activator.GetObject( typeof(IMasterWorker), url + "MasterWorker"); // Last thing to do is change the state, so that the library can continue working datastore.fail(); return(true); }