當前位置: 首頁>>代碼示例>>Python>>正文


Python ConsistentHashRing.remove_node方法代碼示例

本文整理匯總了Python中carbon.hashing.ConsistentHashRing.remove_node方法的典型用法代碼示例。如果您正苦於以下問題:Python ConsistentHashRing.remove_node方法的具體用法?Python ConsistentHashRing.remove_node怎麽用?Python ConsistentHashRing.remove_node使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在carbon.hashing.ConsistentHashRing的用法示例。


在下文中一共展示了ConsistentHashRing.remove_node方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ConsistentHashingRouter

# 需要導入模塊: from carbon.hashing import ConsistentHashRing [as 別名]
# 或者: from carbon.hashing.ConsistentHashRing import remove_node [as 別名]
class ConsistentHashingRouter(DatapointRouter):
  plugin_name = 'consistent-hashing'

  def __init__(self, settings):
    replication_factor = settings.REPLICATION_FACTOR
    diverse_replicas = settings.DIVERSE_REPLICAS

    self.replication_factor = int(replication_factor)
    self.diverse_replicas = diverse_replicas
    self.instance_ports = {}  # { (server, instance) : port }
    self.ring = ConsistentHashRing([])

  def addDestination(self, destination):
    (server, port, instance) = destination
    if (server, instance) in self.instance_ports:
      raise Exception("destination instance (%s, %s) already configured" % (server, instance))
    self.instance_ports[(server, instance)] = port
    self.ring.add_node((server, instance))

  def removeDestination(self, destination):
    (server, port, instance) = destination
    if (server, instance) not in self.instance_ports:
      raise Exception("destination instance (%s, %s) not configured" % (server, instance))
    del self.instance_ports[(server, instance)]
    self.ring.remove_node((server, instance))

  def getDestinations(self, metric):
    key = self.getKey(metric)
    if self.diverse_replicas:
      used_servers = set()
      for (server, instance) in self.ring.get_nodes(key):
        if server in used_servers:
          continue
        else:
          used_servers.add(server)
          port = self.instance_ports[(server, instance)]
          yield (server, port, instance)
        if len(used_servers) >= self.replication_factor:
          return
    else:
      for (count, node) in enumerate(self.ring.get_nodes(key)):
        if count == self.replication_factor:
          return
        (server, instance) = node
        port = self.instance_ports[(server, instance)]
        yield (server, port, instance)

  def getKey(self, metric):
    return metric

  def setKeyFunction(self, func):
    self.getKey = func

  def setKeyFunctionFromModule(self, keyfunc_spec):
    module_path, func_name = keyfunc_spec.rsplit(':', 1)
    module_file = open(module_path, 'U')
    description = ('.py', 'U', imp.PY_SOURCE)
    module = imp.load_module('keyfunc_module', module_file, module_path, description)
    keyfunc = getattr(module, func_name)
    self.setKeyFunction(keyfunc)
開發者ID:criteo-forks,項目名稱:carbon,代碼行數:62,代碼來源:routers.py

示例2: ConsistentHashingRouter

# 需要導入模塊: from carbon.hashing import ConsistentHashRing [as 別名]
# 或者: from carbon.hashing.ConsistentHashRing import remove_node [as 別名]
class ConsistentHashingRouter(DatapointRouter):
    def __init__(self, replication_factor=1):
        self.replication_factor = int(replication_factor)
        self.instance_ports = {}  # { (server, instance) : port }
        self.ring = ConsistentHashRing([])

    def addDestination(self, destination):
        (server, port, instance) = destination
        if (server, instance) in self.instance_ports:
            raise Exception("destination instance (%s, %s) already configured" % (server, instance))
        self.instance_ports[(server, instance)] = port
        self.ring.add_node((server, instance))

    def removeDestination(self, destination):
        (server, port, instance) = destination
        if (server, instance) not in self.instance_ports:
            raise Exception("destination instance (%s, %s) not configured" % (server, instance))
        del self.instance_ports[(server, instance)]
        self.ring.remove_node((server, instance))

    def getDestinations(self, metric):
        key = self.getKey(metric)

        used_servers = set()
        for (server, instance) in self.ring.get_nodes(key):
            if server in used_servers:
                continue
            else:
                used_servers.add(server)
                port = self.instance_ports[(server, instance)]
                yield (server, port, instance)

            if len(used_servers) >= self.replication_factor:
                return

    def getKey(self, metric):
        return metric

    def setKeyFunction(self, func):
        self.getKey = func

    def setKeyFunctionFromModule(self, keyfunc_spec):
        module_path, func_name = keyfunc_spec.rsplit(":", 1)
        module_file = open(module_path, "U")
        description = (".py", "U", imp.PY_SOURCE)
        module = imp.load_module("keyfunc_module", module_file, module_path, description)
        keyfunc = getattr(module, func_name)
        self.setKeyFunction(keyfunc)
開發者ID:Cue,項目名稱:graphite,代碼行數:50,代碼來源:routers.py

示例3: ConsistentHashingRouter

# 需要導入模塊: from carbon.hashing import ConsistentHashRing [as 別名]
# 或者: from carbon.hashing.ConsistentHashRing import remove_node [as 別名]
class ConsistentHashingRouter(DatapointRouter):
  def __init__(self, replication_factor=1):
    self.replication_factor = int(replication_factor)
    self.instance_ports = {} # { (server, instance) : port }
    self.ring = ConsistentHashRing([])

  def addDestination(self, destination):
    (server, port, instance) = destination
    if (server, instance) in self.instance_ports:
      raise Exception("destination instance (%s, %s) already configured" % (server, instance))
    self.instance_ports[ (server, instance) ] = port
    self.ring.add_node( (server, instance) )

  def removeDestination(self, destination):
    (server, port, instance) = destination
    if (server, instance) not in self.instance_ports:
      raise Exception("destination instance (%s, %s) not configured" % (server, instance))
    del self.instance_ports[ (server, instance) ]
    self.ring.remove_node( (server, instance) )

  def getDestinations(self, metric):
    key = self.getKey(metric)

    for count,node in enumerate(self.ring.get_nodes(key)):
      if count == self.replication_factor:
        return
      (server, instance) = node
      port = self.instance_ports[ (server, instance) ]
      yield (server, port, instance)

  #def getKey(self, metric):
  #  return metric
  
  def getKey(self, metric):
    #RBA: modification done to ensure that all the metrics to be aggregated are processed by the same aggregator
    return metric.rsplit('.',1)[0]
  
  def setKeyFunction(self, func):
    self.getKey = func

  def setKeyFunctionFromModule(self, keyfunc_spec):
    module_path, func_name = keyfunc_spec.rsplit(':', 1)
    module_file = open(module_path, 'U')
    description = ('.py', 'U', imp.PY_SOURCE)
    module = imp.load_module('keyfunc_module', module_file, module_path, description)
    keyfunc = getattr(module, func_name)
    self.setKeyFunction(keyfunc)
開發者ID:dmichau,項目名稱:carbon,代碼行數:49,代碼來源:routers.py


注:本文中的carbon.hashing.ConsistentHashRing.remove_node方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。