Пример #1
0
 def __init__(self, name, representation):
     super(Deployment, self).__init__()
     self.original_representation = representation
     self.name = name
     self.buckets = {}
     for bucket_id, bucket in representation['buckets'].iteritems():
         nodes = dict((node_id, Node(node_id, bucket_id, address, port)) for node_id, (address, port) in bucket.iteritems())
         self.buckets[bucket_id] = Bucket(bucket_id, nodes)
     self.nodes = dict((node_id, node) for bucket in self.buckets.itervalues() for node_id, node in bucket.nodes.iteritems())
     self.consistent_hash = ConsistentHash(self.buckets.values(), **representation.get('hash', {}))
     self.read_repair_enabled = representation.get('read_repair', True)
     self.background_repair_enabled = representation.get('background_repair', True)
     self.background_repair_interval = parse_timedelta(representation.get('background_repair_interval', '1d'))
     self.background_repair_interval_seconds = timedelta_total_seconds(self.background_repair_interval)
     if self.background_repair_enabled:
         if not self.background_repair_interval_seconds:
             raise Exception('Parsing error')
Пример #2
0
class Deployment(object):
    def __init__(self, name, representation):
        super(Deployment, self).__init__()
        self.original_representation = representation
        self.name = name
        self.buckets = {}
        for bucket_id, bucket in representation['buckets'].iteritems():
            nodes = dict((node_id, Node(node_id, bucket_id, address, port)) for node_id, (address, port) in bucket.iteritems())
            self.buckets[bucket_id] = Bucket(bucket_id, nodes)
        self.nodes = dict((node_id, node) for bucket in self.buckets.itervalues() for node_id, node in bucket.nodes.iteritems())
        self.consistent_hash = ConsistentHash(self.buckets.values(), **representation.get('hash', {}))
        self.read_repair_enabled = representation.get('read_repair', True)
        self.background_repair_enabled = representation.get('background_repair', True)
        self.background_repair_interval = parse_timedelta(representation.get('background_repair_interval', '1d'))
        self.background_repair_interval_seconds = timedelta_total_seconds(self.background_repair_interval)
        if self.background_repair_enabled:
            if not self.background_repair_interval_seconds:
                raise Exception('Parsing error')

    def siblings(self, node_id):
        node = self.nodes[node_id]
        bucket = self.buckets[node.bucket_id]
        siblings = dict(bucket.nodes)
        del siblings[node_id]
        return siblings.values()

    def buckets_for_key(self, key):
        return self.consistent_hash.find_buckets(key)

    def representation(self):
        spec = {
                'read_repair': self.read_repair_enabled,
                'background_repair':self.background_repair_enabled,
                'background_repair_interval':str(self.background_repair_interval),
                'hash': {
                        'buckets_per_key': self.consistent_hash.buckets_per_key,
                },
                'buckets':dict((bucket_id, bucket.representation()) for bucket_id, bucket in self.buckets.iteritems()),
        }
        return spec

    def __str__(self):
        return 'Deployment(%s)' % self.spec()

    def __repr__(self):
        return str(self)
Пример #3
0
# coding=UTF-8
import Image, ImageDraw
import math
import logging

# Create a visualization of your consistent hash.
# Every node and it's virtual points will be plotted with a distinct color
# Requires PIL

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)s %(levelname)s %(message)s')

from consistenthash import ConsistentHash

c = ConsistentHash()

c.add_node(("127.0.0.1", "red"), 10)
c.add_node(("127.0.0.2", "white"), 10)
c.add_node(("127.0.0.3", "green"), 10)
c.add_node(("127.0.0.4", "purple"), 10)

entries = c.continuum

im = Image.new("RGB", (800, 800))
draw = ImageDraw.Draw(im)

offset = 400
size = 300
circSize = 5

tmp = entries[0]
Пример #4
0
# coding=UTF-8
import Image, ImageDraw
import math
import logging

# Create a visualization of your consistent hash.
# Every node and it's virtual points will be plotted with a distinct color
# Requires PIL

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s %(message)s')

from consistenthash import ConsistentHash
c = ConsistentHash()

c.add_node(("127.0.0.1", "red"), 10)
c.add_node(("127.0.0.2", "white"), 10)
c.add_node(("127.0.0.3", "green"), 10)
c.add_node(("127.0.0.4", "purple"), 10)

entries = c.continuum

im = Image.new("RGB", (800, 800))
draw = ImageDraw.Draw(im)

offset = 400
size = 300
circSize = 5

tmp = entries[0]
(tmp,_) = tmp