Example #1
0
    def test_join_no_load(self):
        comm.create([('127.0.0.1', 7100)])

        rc = StrictRedisCluster(
            startup_nodes=[{
                'host': '127.0.0.1',
                'port': 7100
            }],
            decode_responses=True)
        rc.set('x-{h-893}', 'y')
        rc.set('y-{h-893}', 'zzZ')
        rc.set('z-{h-893}', 'w')
        rc.incr('h-893')

        comm.join_no_load('127.0.0.1', 7100, '127.0.0.1', 7101)
        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        n7100 = nodes[('127.0.0.1', 7100)]
        n7101 = nodes[('127.0.0.1', 7101)]

        self.assertEqual(16384, len(n7100.assigned_slots))
        self.assertEqual(0, len(n7101.assigned_slots))

        comm.join_no_load('127.0.0.1', 7100, '127.0.0.1', 7102)
        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101, [0])

        nodes = base.list_nodes('127.0.0.1', 7102)
        self.assertEqual(3, len(nodes))
        n7100 = nodes[('127.0.0.1', 7100)]
        n7101 = nodes[('127.0.0.1', 7101)]
        n7102 = nodes[('127.0.0.1', 7102)]

        self.assertEqual(16383, len(n7100.assigned_slots))
        self.assertEqual(1, len(n7101.assigned_slots))
        self.assertEqual(0, len(n7102.assigned_slots))

        try:
            t = n7101.get_conn()
            m = t.execute('get', 'h-893')
            self.assertEqual('1', m)

            m = t.execute('get', 'y-{h-893}')
            self.assertEqual('zzZ', m)

            comm.quit_cluster('127.0.0.1', 7102)
            comm.quit_cluster('127.0.0.1', 7101)
            t = n7100.get_conn()

            rc.delete('x-{h-893}')
            rc.delete('y-{h-893}')
            rc.delete('z-{h-893}')
            rc.delete('h-893')
            comm.shutdown_cluster('127.0.0.1', 7100)
        finally:
            n7100.close()
            n7101.close()
Example #2
0
    def test_join_no_load(self):
        comm.create([('127.0.0.1', 7100)])

        rc = StrictRedisCluster(startup_nodes=[{
            'host': '127.0.0.1',
            'port': 7100
        }],
                                decode_responses=True)
        rc.set('x-{h-893}', 'y')
        rc.set('y-{h-893}', 'zzZ')
        rc.set('z-{h-893}', 'w')
        rc.incr('h-893')

        comm.join_no_load('127.0.0.1', 7100, '127.0.0.1', 7101)
        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        n7100 = nodes[('127.0.0.1', 7100)]
        n7101 = nodes[('127.0.0.1', 7101)]

        self.assertEqual(16384, len(n7100.assigned_slots))
        self.assertEqual(0, len(n7101.assigned_slots))

        comm.join_no_load('127.0.0.1', 7100, '127.0.0.1', 7102)
        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101, [0])

        nodes = base.list_nodes('127.0.0.1', 7102)
        self.assertEqual(3, len(nodes))
        n7100 = nodes[('127.0.0.1', 7100)]
        n7101 = nodes[('127.0.0.1', 7101)]
        n7102 = nodes[('127.0.0.1', 7102)]

        self.assertEqual(16383, len(n7100.assigned_slots))
        self.assertEqual(1, len(n7101.assigned_slots))
        self.assertEqual(0, len(n7102.assigned_slots))

        try:
            t = n7101.get_conn()
            m = t.execute('get', 'h-893')
            self.assertEqual('1', m)

            m = t.execute('get', 'y-{h-893}')
            self.assertEqual('zzZ', m)

            comm.quit_cluster('127.0.0.1', 7102)
            comm.quit_cluster('127.0.0.1', 7101)
            t = n7100.get_conn()

            rc.delete('x-{h-893}')
            rc.delete('y-{h-893}')
            rc.delete('z-{h-893}')
            rc.delete('h-893')
            comm.shutdown_cluster('127.0.0.1', 7100)
        finally:
            n7100.close()
            n7101.close()
Example #3
0
    def test_api(self):
        comm.create([('127.0.0.1', 7100)])
        rc = StrictRedisCluster(startup_nodes=[{
            'host': '127.0.0.1',
            'port': 7100
        }],
                                decode_responses=True)
        rc.set('key', 'value')
        self.assertEqual('value', rc.get('key'))

        comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101)
        for i in range(20):
            rc.set('key_%s' % i, 'value_%s' % i)

        for i in range(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))

        nodes = base.list_nodes('127.0.0.1', 7100)

        self.assertEqual(2, len(nodes))
        self.assertEqual(list(range(8192)),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(list(range(8192, 16384)),
                         nodes[('127.0.0.1', 7100)].assigned_slots)

        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101, [8192])

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        self.assertEqual(list(range(8193)),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(list(range(8193, 16384)),
                         nodes[('127.0.0.1', 7100)].assigned_slots)

        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101,
                           [8193, 8194, 8195])

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        self.assertEqual(list(range(8196)),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(list(range(8196, 16384)),
                         nodes[('127.0.0.1', 7100)].assigned_slots)

        six.assertRaisesRegex(self, ValueError, 'Not all slot held by',
                              comm.migrate_slots, '127.0.0.1', 7100,
                              '127.0.0.1', 7101, [8192])

        six.assertRaisesRegex(self, ValueError, 'Not all slot held by',
                              comm.migrate_slots, '127.0.0.1', 7100,
                              '127.0.0.1', 7101, [8195, 8196])

        six.assertRaisesRegex(self, ValueError,
                              'Two nodes are not in the same cluster',
                              comm.migrate_slots, '127.0.0.1', 7100,
                              '127.0.0.1', 7102, [8196])

        comm.quit_cluster('127.0.0.1', 7100)

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(1, len(nodes))
        self.assertEqual(0, len(nodes[('127.0.0.1', 7100)].assigned_slots))
        nodes = base.list_nodes('127.0.0.1', 7101)
        self.assertEqual(1, len(nodes))
        self.assertEqual(list(range(16384)),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        rc = StrictRedisCluster(startup_nodes=[{
            'host': '127.0.0.1',
            'port': 7101
        }],
                                decode_responses=True)
        for i in range(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))
        self.assertEqual('value', rc.get('key'))

        six.assertRaisesRegex(self, RedisStatusError, 'still contains keys',
                              comm.shutdown_cluster, '127.0.0.1', 7101)

        rc.delete('key', *['key_%s' % i for i in range(20)])
        comm.shutdown_cluster('127.0.0.1', 7101)

        six.assertRaisesRegex(
            self, RedisClusterException,
            'All slots are not covered after query all startup_nodes. .*',
            rc.get, 'key')
Example #4
0
    def test_api(self):
        comm.start_cluster('127.0.0.1', 7100)
        rc = RedisCluster([{'host': '127.0.0.1', 'port': 7100}])
        rc.set('key', 'value')
        self.assertEqual('value', rc.get('key'))

        comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101)
        for i in xrange(20):
            rc.set('key_%s' % i, 'value_%s' % i)

        for i in xrange(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))

        nodes = base.list_nodes('127.0.0.1', 7100)

        self.assertEqual(2, len(nodes))
        self.assertEqual(range(8192),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(range(8192, 16384),
                         nodes[('127.0.0.1', 7100)].assigned_slots)

        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101, [8192])

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        self.assertEqual(range(8193),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(range(8193, 16384),
                         nodes[('127.0.0.1', 7100)].assigned_slots)

        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101,
                           [8193, 8194, 8195])

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        self.assertEqual(range(8196),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(range(8196, 16384),
                         nodes[('127.0.0.1', 7100)].assigned_slots)

        self.assertRaisesRegexp(ValueError, 'Not all slot held by',
                                comm.migrate_slots, '127.0.0.1', 7100,
                                '127.0.0.1', 7101, [8192])

        self.assertRaisesRegexp(ValueError, 'Not all slot held by',
                                comm.migrate_slots, '127.0.0.1', 7100,
                                '127.0.0.1', 7101, [8195, 8196])

        self.assertRaisesRegexp(ValueError,
                                'Two nodes are not in the same cluster',
                                comm.migrate_slots, '127.0.0.1', 7100,
                                '127.0.0.1', 7102, [8196])

        comm.quit_cluster('127.0.0.1', 7100)

        for i in xrange(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))
        self.assertEqual('value', rc.get('key'))

        nodes = base.list_nodes('127.0.0.1', 7101)
        self.assertEqual(1, len(nodes))
        self.assertEqual(range(16384),
                         nodes[('127.0.0.1', 7101)].assigned_slots)

        self.assertRaisesRegexp(RedisStatusError, 'Cluster containing keys',
                                comm.shutdown_cluster, '127.0.0.1', 7101)

        rc.delete('key', *['key_%s' % i for i in xrange(20)])
        comm.shutdown_cluster('127.0.0.1', 7101)

        self.assertRaisesRegexp(ResponseError, 'CLUSTERDOWN .*', rc.get, 'key')
Example #5
0
    def test_api(self):
        comm.start_cluster('127.0.0.1', 7100)
        rc = RedisCluster([{'host': '127.0.0.1', 'port': 7100}])
        rc.set('key', 'value')
        self.assertEqual('value', rc.get('key'))

        comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101)
        for i in xrange(20):
            rc.set('key_%s' % i, 'value_%s' % i)

        for i in xrange(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))

        nodes = base.list_nodes('127.0.0.1', 7100)

        self.assertEqual(2, len(nodes))
        self.assertEqual(range(8192),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(range(8192, 16384),
                         nodes[('127.0.0.1', 7100)].assigned_slots)

        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101, [8192])

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        self.assertEqual(range(8193),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(range(8193, 16384),
                         nodes[('127.0.0.1', 7100)].assigned_slots)

        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101,
                           [8193, 8194, 8195])

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        self.assertEqual(range(8196),
                         nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(range(8196, 16384),
                         nodes[('127.0.0.1', 7100)].assigned_slots)

        self.assertRaisesRegexp(
            ValueError, 'Not all slot held by', comm.migrate_slots,
            '127.0.0.1', 7100, '127.0.0.1', 7101, [8192])

        self.assertRaisesRegexp(
            ValueError, 'Not all slot held by', comm.migrate_slots,
            '127.0.0.1', 7100, '127.0.0.1', 7101, [8195, 8196])

        self.assertRaisesRegexp(
            ValueError, 'Two nodes are not in the same cluster',
            comm.migrate_slots, '127.0.0.1', 7100, '127.0.0.1', 7102, [8196])

        comm.quit_cluster('127.0.0.1', 7100)

        for i in xrange(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))
        self.assertEqual('value', rc.get('key'))

        nodes = base.list_nodes('127.0.0.1', 7101)
        self.assertEqual(1, len(nodes))
        self.assertEqual(range(16384),
                         nodes[('127.0.0.1', 7101)].assigned_slots)

        self.assertRaisesRegexp(
            RedisStatusError, 'Cluster containing keys',
            comm.shutdown_cluster, '127.0.0.1', 7101)

        rc.delete('key', *['key_%s' % i for i in xrange(20)])
        comm.shutdown_cluster('127.0.0.1', 7101)

        self.assertRaisesRegexp(ResponseError, 'CLUSTERDOWN .*', rc.get, 'key')
Example #6
0
import time
import random
from redistrib import command

while True:
    slot = random.randint(0, 16383)
    src = random.randint(7001, 7003)
    dest = random.randint(7001, 7003)
    if src == dest:
        continue
    s = time.time()
    try:
        command.migrate_slots("127.0.0.1", src, "127.0.0.1", dest, [slot])
    except Exception as e:
        print e
        pass
    else:
        e = time.time()
        print ("migrate slot %d 127.0.0.1:%d -> 127.0.0.1:%d time: %f" % (slot, src, dest, e - s))

    time.sleep(1)
Example #7
0
import time
import random
from redistrib import command
while True:
    slot = random.randint(0, 16383)
    src = random.randint(7001, 7003)
    dest = random.randint(7001, 7003)
    if src == dest:
        continue
    s = time.time()
    try:
        command.migrate_slots('127.0.0.1', src, '127.0.0.1', dest, [
            slot,
        ])
    except Exception as e:
        print e
        pass
    else:
        e = time.time()
        print("migrate slot %d 127.0.0.1:%d -> 127.0.0.1:%d time: %f" %
              (slot, src, dest, e - s))

    time.sleep(1)
Example #8
0
    def test_api(self):
        comm.create([('127.0.0.1', 7100)])
        rc = StrictRedisCluster(
            startup_nodes=[{
                'host': '127.0.0.1',
                'port': 7100
            }],
            decode_responses=True)
        rc.set('key', 'value')
        self.assertEqual('value', rc.get('key'))

        comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101)
        for i in range(20):
            rc.set('key_%s' % i, 'value_%s' % i)

        for i in range(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))

        nodes = base.list_nodes('127.0.0.1', 7100)

        self.assertEqual(2, len(nodes))
        self.assertEqual(
            list(range(8192)), nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(
            list(range(8192, 16384)), nodes[('127.0.0.1',
                                             7100)].assigned_slots)

        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101, [8192])

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        self.assertEqual(
            list(range(8193)), nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(
            list(range(8193, 16384)), nodes[('127.0.0.1',
                                             7100)].assigned_slots)

        comm.migrate_slots('127.0.0.1', 7100, '127.0.0.1', 7101,
                           [8193, 8194, 8195])

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(2, len(nodes))
        self.assertEqual(
            list(range(8196)), nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(
            list(range(8196, 16384)), nodes[('127.0.0.1',
                                             7100)].assigned_slots)

        six.assertRaisesRegex(self, ValueError, 'Not all slot held by',
                              comm.migrate_slots, '127.0.0.1', 7100,
                              '127.0.0.1', 7101, [8192])

        six.assertRaisesRegex(self, ValueError, 'Not all slot held by',
                              comm.migrate_slots, '127.0.0.1', 7100,
                              '127.0.0.1', 7101, [8195, 8196])

        six.assertRaisesRegex(
            self, ValueError, 'Two nodes are not in the same cluster',
            comm.migrate_slots, '127.0.0.1', 7100, '127.0.0.1', 7102, [8196])

        comm.quit_cluster('127.0.0.1', 7100)

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(1, len(nodes))
        self.assertEqual(0, len(nodes[('127.0.0.1', 7100)].assigned_slots))
        nodes = base.list_nodes('127.0.0.1', 7101)
        self.assertEqual(1, len(nodes))
        self.assertEqual(
            list(range(16384)), nodes[('127.0.0.1', 7101)].assigned_slots)
        rc = StrictRedisCluster(
            startup_nodes=[{
                'host': '127.0.0.1',
                'port': 7101
            }],
            decode_responses=True)
        for i in range(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))
        self.assertEqual('value', rc.get('key'))

        six.assertRaisesRegex(self, RedisStatusError, 'still contains keys',
                              comm.shutdown_cluster, '127.0.0.1', 7101)

        rc.delete('key', *['key_%s' % i for i in range(20)])
        comm.shutdown_cluster('127.0.0.1', 7101)

        six.assertRaisesRegex(
            self, RedisClusterException,
            'All slots are not covered after query all startup_nodes. .*',
            rc.get, 'key')