private void BlockMapProcess(NetworkContext context, IBlockMapProcess process) { Out.WriteLine("Processing..."); // Refresh context.Network.Refresh(); MachineProfile manager = context.Network.ManagerServer; if (manager == null) throw new ApplicationException("Error: Manager currently not available."); // Generate a map of server guid value to MachineProfile for that machine // node currently available. MachineProfile[] blockServers = context.Network.BlockServers; long[] availableBlockGuids = new long[blockServers.Length]; Dictionary<long, MachineProfile> sguidToAddress = new Dictionary<long, MachineProfile>(); for (int i = 0; i < blockServers.Length; ++i) { long serverGuid = context.Network.GetBlockGuid(blockServers[i].Address); availableBlockGuids[i] = serverGuid; sguidToAddress[availableBlockGuids[i]] = blockServers[i]; } Array.Sort(availableBlockGuids); int blockServerCount = blockServers.Length; Out.WriteLine("Block servers currently available: " + blockServerCount); if (blockServerCount < 3) { Out.WriteLine("WARNING: There are currently less than 3 block servers available."); } // The map of block_id to list of server guids that contain the block, Dictionary<long, List<long>> blockIdMap = new Dictionary<long, List<long>>(); // For each block server, Dictionary<long, MachineProfile>.KeyCollection serverGuids = sguidToAddress.Keys; foreach (long serverGuid in serverGuids) { MachineProfile block = sguidToAddress[serverGuid]; // Fetch the list of blocks for the server, long[] blockIds = context.Network.GetBlockList(block.Address); foreach (long blockId in blockIds) { // Build the association, List<long> list = blockIdMap[blockId]; if (list == null) { list = new List<long>(5); blockIdMap[blockId] = list; } list.Add(serverGuid); } } // Now, 'block_id_map' contains the actual map of block id to servers as // reported by the block servers. We now need to compare this to the map // the manager server has. // The total number of mappings recorded by the manager, long count = context.Network.GetBlockMappingCount(); long[] m = context.Network.GetBlockMappingRange(0, Int64.MaxValue); long blCur = -1; List<long> list1 = new List<long>(); for (int i = 0; i < m.Length; i += 2) { long bl = m[i]; // the block id long sg = m[i + 1]; // the server guid if (bl != blCur) { if (list1.Count > 0) { // Check this block, List<long> in_list = blockIdMap[blCur]; process.ManagerProcess(blCur, list1, in_list, sguidToAddress); } list1.Clear(); blCur = bl; } list1.Add(sg); } // For each block, Dictionary<long, List<long>>.KeyCollection blockIds1 = blockIdMap.Keys; int minBlockThreshold = Math.Min(3, Math.Max(blockServerCount, 1)); foreach (long block_id in blockIds1) { List<long> blockIdOnSguids = blockIdMap[block_id]; List<long> availableSguids = new List<long>(); foreach (long block_sguid in blockIdOnSguids) { if (Array.BinarySearch(availableBlockGuids, block_sguid) >= 0) { availableSguids.Add(block_sguid); } } process.Process(block_id, availableSguids, availableBlockGuids, minBlockThreshold, sguidToAddress); } }
private void BlockMapProcess(NetworkContext context, IBlockMapProcess process) { Out.WriteLine("Processing..."); // Refresh context.Network.Refresh(); MachineProfile[] manager = context.Network.GetManagerServers(); if (manager.Length == 0) { throw new ApplicationException("Error: Manager currently not available."); } // Generate a map of server guid value to MachineProfile for that machine // node currently available. MachineProfile[] blockServers = context.Network.GetBlockServers(); long[] availableBlockGuids = new long[blockServers.Length]; Dictionary <long, MachineProfile> sguidToAddress = new Dictionary <long, MachineProfile>(); for (int i = 0; i < blockServers.Length; ++i) { long serverGuid = context.Network.GetBlockGuid(blockServers[i].ServiceAddress); availableBlockGuids[i] = serverGuid; sguidToAddress[availableBlockGuids[i]] = blockServers[i]; } Array.Sort(availableBlockGuids); int blockServerCount = blockServers.Length; Out.WriteLine("Block servers currently available: " + blockServerCount); if (blockServerCount < 3) { Out.WriteLine("WARNING: There are currently less than 3 block servers available."); } // The map of block_id to list of server guids that contain the block, Dictionary <long, List <long> > blockIdMap = new Dictionary <long, List <long> >(); // For each block server, Dictionary <long, MachineProfile> .KeyCollection serverGuids = sguidToAddress.Keys; foreach (long serverGuid in serverGuids) { MachineProfile block = sguidToAddress[serverGuid]; // Fetch the list of blocks for the server, long[] blockIds = context.Network.GetBlockList(block.ServiceAddress); foreach (long blockId in blockIds) { // Build the association, List <long> list = blockIdMap[blockId]; if (list == null) { list = new List <long>(5); blockIdMap[blockId] = list; } list.Add(serverGuid); } } // Now, 'block_id_map' contains the actual map of block id to servers as // reported by the block servers. We now need to compare this to the map // the manager server has. // The total number of mappings recorded by the manager, long count = context.Network.GetBlockMappingCount(); long[] m = context.Network.GetBlockMappingRange(0, Int64.MaxValue); long blCur = -1; List <long> list1 = new List <long>(); for (int i = 0; i < m.Length; i += 2) { long bl = m[i]; // the block id long sg = m[i + 1]; // the server guid if (bl != blCur) { if (list1.Count > 0) { // Check this block, List <long> in_list = blockIdMap[blCur]; process.ManagerProcess(blCur, list1, in_list, sguidToAddress); } list1.Clear(); blCur = bl; } list1.Add(sg); } // For each block, Dictionary <long, List <long> > .KeyCollection blockIds1 = blockIdMap.Keys; int minBlockThreshold = Math.Min(3, Math.Max(blockServerCount, 1)); foreach (long block_id in blockIds1) { List <long> blockIdOnSguids = blockIdMap[block_id]; List <long> availableSguids = new List <long>(); foreach (long block_sguid in blockIdOnSguids) { if (Array.BinarySearch(availableBlockGuids, block_sguid) >= 0) { availableSguids.Add(block_sguid); } } process.Process(block_id, availableSguids, availableBlockGuids, minBlockThreshold, sguidToAddress); } }