public override void execute(MetaDataServer md) { Console.WriteLine("#MDS: Registering DS " + DataServerId); if ( md.DataServers.ContainsKey(DataServerId) ) { md.DataServers.Remove(DataServerId); } ServerObjectWrapper remoteObjectWrapper = new ServerObjectWrapper(DataServerPort, DataServerId, DataServerHost); md.DataServers.Add(DataServerId, remoteObjectWrapper); md.addServerToUnbalancedFiles(DataServerId); HeartbeatMessage heartbeat = new HeartbeatMessage(DataServerId, 0 , 0, 0, 0, new Dictionary<string,FileAccessCounter>()); md.receiveHeartbeat(heartbeat); md.makeCheckpoint(); }
void sendHeartbeat(object source, ElapsedEventArgs e) { HeartbeatMessage heartbeat = new HeartbeatMessage(Id, Files.Count, ReadCounter, ReadVersionCounter, WriteCounter, AccessCounter); Task[] tasks = new Task[MetaInformationReader.Instance.MetaDataServers.Count]; for (int md = 0; md < MetaInformationReader.Instance.MetaDataServers.Count; md++) { IMetaDataServer metadataServer = MetaInformationReader.Instance.MetaDataServers[md].getObject<IMetaDataServer>(); tasks[md] = Task.Factory.StartNew(() => { metadataServer.receiveHeartbeat(heartbeat); }); } Task.WaitAll(tasks); ReadCounter = 0; ReadVersionCounter = 0; WriteCounter = 0; }
public void receiveHeartbeat(HeartbeatMessage heartbeat) { string serverID = heartbeat.ServerId; if (!Heartbeats.ContainsKey(serverID)) { Heartbeats.Add(serverID, new Queue<HeartbeatMessage>()); } if (Heartbeats[serverID].Count == MAX_HEARTBEATS) { Heartbeats[serverID].Dequeue(); } Heartbeats[serverID].Enqueue(heartbeat); Dictionary<string, FileAccessCounter> heartbeatAccesses = heartbeat.AccessCounter; foreach (KeyValuePair<string, FileAccessCounter> entry in heartbeatAccesses) { addAccesses(serverID, entry.Key, entry.Value); if (entry.Value.WriteCounter > 0) { unregisterMigratingFile(entry.Value.FileName, serverID); } } double avg = calculateAverageLoad(); double serverLoad = calculateServerLoad(serverID); if ((serverLoad > 1) && (serverLoad > (avg * OVERLOAD_MULTIPLIER))) { //migration: Console.WriteLine("#MDS: Server " + serverID + " in overloaded state!"); List<FileMetadata> closedFiles = getClosedFiles(serverID); Console.WriteLine("\tFiles to move: " + closedFiles.Count); List<ServerObjectWrapper> servers = getSortedServers(DataServers.Count); string filename = getMostAccessedFile(closedFiles).FileName; List<ServerObjectWrapper> cleanServers = getUnderLoadServersWithoutFile(servers, avg, filename); Console.Write("\tServers available: " + cleanServers.Count + "\r\n\t[ "); foreach (ServerObjectWrapper srv in cleanServers) { Console.WriteLine(srv.Id + " "); } Console.WriteLine("]"); if (cleanServers.Count != 0) { executeOperation(new MetaDataMigrateOperation(serverID, cleanServers[0].Id, filename)); } } }