Beispiel #1
0
def remote_put(node_id, key, value):
    '''
    Store the key-value pair in to ring via node_id. It will 
    put into multiple nodes for replication.

    Args:
        node_id:    The node id.
        key:        The key of key-value pair.
        value:      The value of key-value pair.

    Returns:
        N/A

    Raises:
        N/A
    '''
    cname = hp._gen_net_id(node_id)
    key_id = hp._hash(key)
    logger.info('hash({}) -> {}'.format(key, key_id))
    succ = key_id
    for i in range(0, ct.BACKUP_SUCC_NUM + 1):  # put into successors and backups
        # find successor
        cmd = 'docker exec {} pipenv run python helper.py --local_find_successor {}'\
                .format(cname, succ)
        proc = sp.run(cmd, shell=True, stdout=sp.PIPE, check=True)
        succ = proc.stdout.splitlines()[0]
        logger.info('{}th successor is {}'.format(i, succ))
        # put value
        cmd = 'docker exec {} pipenv run python helper.py --local_put {} {}'\
                .format(hp._gen_net_id(succ), key, value)
        sp.run(cmd, shell=True, stdout=sp.PIPE, check=True)
        # next succ
        succ = hp._add(succ, 1)
Beispiel #2
0
 def test_in_range_ee(self):
     '''
     test the (start, end]
     '''
     h = 'b444ac06613fc8d63795be9ad0beaf55011936ac'
     node = Node(h)
     # start==end
     test = h
     start = h
     end = h
     self.assertFalse(node._in_range_ee(test, start, end))
     # end = start + 1
     test = h
     start = h
     end = helper._add(h, 1)
     self.assertFalse(node._in_range_ee(test, start, end))
     # start<test<end
     test = h
     start = helper._add(h, -10)
     end = helper._add(h, 10)
     self.assertTrue(node._in_range_ee(test, start, end))
     # start=h<end
     test = h
     start = h
     end = helper._add(h, 10)
     self.assertFalse(node._in_range_ee(test, start, end))
     # start<test=end
     test = h
     start = helper._add(h, -10)
     end = h
     self.assertFalse(node._in_range_ee(test, start, end))
     # test<start<end
     test = h
     start = helper._add(h, 10)
     end = helper._add(h, 20)
     self.assertFalse(node._in_range_ee(test, start, end))
     # start>end, test is in
     test = helper._format(1)
     start = h
     end = helper._format(int(h, 16)//2)
     self.assertTrue(node._in_range_ee(test, start, end))
Beispiel #3
0
 def test_add(self):
     h = helper._add('0000000000000000000000000000000000000000', -1)
     self.assertEqual(h, 'ffffffffffffffffffffffffffffffffffffffff')