Beispiel #1
0
        public void SendHeartbeat()
        {
            if (fail) return;
            if (freeze)
            {
                freezed.Enqueue(() => SendHeartbeat());
                return;
            }

            while (true)
            {
                try
                {
                    Heartbeat heartbeat = new Heartbeat(MyWeight(), new Dictionary<string, Weight>(weights));
                    //Console.WriteLine("HEARTBEAT TO " + master);
                    GarbageCollected toDelete = metadatas[master].Heartbeat(id, heartbeat);

                    foreach (string localFilename in toDelete)
                    {
                        Console.WriteLine("GARBAGE COLLECTOR = " + localFilename);
                        FileData ignoredFileData; files.TryRemove(localFilename, out ignoredFileData);
                        Weight ignoredStats; weights.TryRemove(localFilename, out ignoredStats);
                    }

                    return;
                }
                catch (ProcessFailedException)
                {
                    RandomMaster();
                }
                catch (NotTheMasterException e)
                {
                    master = e.NewMaster;
                }
            }
        }
Beispiel #2
0
        public GarbageCollected Heartbeat(string dataServerId, Heartbeat heartbeat)
        {
            if (fail) throw new ProcessFailedException(id);
            if (ImNoMaster()) throw new NotTheMasterException(id, master);

            //Console.WriteLine("HEARTBEAT FROM " + dataServerId);

            if (dataServers.Contains(dataServerId))
            {
                GarbageCollected toDelete = new GarbageCollected();

                // update data server weight
                dataServers.Touch(dataServerId, heartbeat.DataServerWeight);
                foreach (var entry in heartbeat.FileWeights)
                {
                    string localFilename = entry.Key;
                    Weight fileWeight = entry.Value;

                    // garbage collection
                    if (!dataServers.ContainsFile(dataServerId, localFilename))
                    {
                        toDelete.Add(localFilename);
                    }
                    else
                    {
                        // update file weights
                        dataServers.UpdateFileWeight(dataServerId, localFilename, fileWeight);
                    }
                }

                // pending files if this data server returned
                if (dataServers.Failed(dataServerId))
                {
                    CheckPending(dataServerId);
                }

                return toDelete;
            }

            return null;
        }