Beispiel #1
0
 def _ComputeMappingFromPercentages(self, mapping, newperc):
   """Builds a new mapping based on the new server range percentages."""
   newstart = 0
   n_servers = self.mapping.num_servers
   servers = list(mapping.servers)
   new_mapping = rdf_data_server.DataServerMapping(
       version=self.mapping.version + 1,
       num_servers=n_servers,
       pathing=self.mapping.pathing)
   for i, perc in enumerate(newperc):
     quant = int(perc * constants.MAX_RANGE)
     interval = rdf_data_server.DataServerInterval(start=newstart)
     end = newstart + quant
     if i == len(newperc) - 1:
       end = constants.MAX_RANGE
     interval.end = end
     old_server = servers[i]
     newstart = end
     new_mapping.servers.Append(
         index=old_server.index,
         address=old_server.address,
         port=old_server.port,
         state=old_server.state,
         interval=interval)
   return new_mapping
Beispiel #2
0
def CreateStartInterval(index, total):
    """Create initial range given index of server and number of servers."""
    part = int(constants.MAX_RANGE / float(total))
    start = part * index
    if total == index - 1:
        end = constants.MAX_RANGE
    else:
        end = part * (index + 1)
    ret = rdf_data_server.DataServerInterval(start=start, end=end)
    return ret