Beispiel #1
0
 def test_18_tweakBigPT(self):
     seed = repr(time.time())
     logging.info("using seed %r", seed)
     sn_count = 11
     sn = [
         self.createStorage(None, i + 1, NodeStates.RUNNING)
         for i in xrange(sn_count)
     ]
     for topo in 0, 1:
         r = random.Random(seed)
         if topo:
             for i, s in enumerate(sn, sn_count):
                 s.devpath = str(i % 5),
         pt = PartitionTable(1000, 2)
         pt.setID(1)
         for offset in xrange(pt.np):
             state = CellStates.UP_TO_DATE
             k = r.randrange(1, sn_count)
             for s in r.sample(sn, k):
                 pt._setCell(offset, s, state)
                 if k * r.random() < 1:
                     state = CellStates.OUT_OF_DATE
         pt.log()
         self.tweak(pt)
         self.update(pt)
Beispiel #2
0
 def test_13_outdate(self):
     # create nodes
     uuid1 = self.getStorageUUID()
     server1 = ("127.0.0.1", 19001)
     sn1 = self.createStorage(server1, uuid1)
     uuid2 = self.getStorageUUID()
     server2 = ("127.0.0.2", 19002)
     sn2 = self.createStorage(server2, uuid2)
     uuid3 = self.getStorageUUID()
     server3 = ("127.0.0.3", 19003)
     sn3 = self.createStorage(server3, uuid3)
     uuid4 = self.getStorageUUID()
     server4 = ("127.0.0.4", 19004)
     sn4 = self.createStorage(server4, uuid4)
     # create partition table
     num_partitions = 4
     num_replicas = 3
     pt = PartitionTable(num_partitions, num_replicas)
     pt._setCell(0, sn1, CellStates.OUT_OF_DATE)
     sn1.setState(NodeStates.RUNNING)
     pt._setCell(1, sn2, CellStates.UP_TO_DATE)
     sn2.setState(NodeStates.DOWN)
     pt._setCell(2, sn3, CellStates.UP_TO_DATE)
     sn3.setState(NodeStates.UNKNOWN)
     pt._setCell(3, sn4, CellStates.UP_TO_DATE)
     sn4.setState(NodeStates.RUNNING)
     # outdate nodes
     cells_outdated = pt.outdate()
     self.assertEqual(len(cells_outdated), 2)
     for offset, uuid, state in cells_outdated:
         self.assertIn(offset, (1, 2))
         self.assertIn(uuid, (uuid2, uuid3))
         self.assertEqual(state, CellStates.OUT_OF_DATE)
     # check each cell
     # part 1, already outdated
     cells = pt.getCellList(0)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 2, must be outdated
     cells = pt.getCellList(1)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 3, must be outdated
     cells = pt.getCellList(2)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.OUT_OF_DATE)
     # part 4, remains running
     cells = pt.getCellList(3)
     self.assertEqual(len(cells), 1)
     cell = cells[0]
     self.assertEqual(cell.getState(), CellStates.UP_TO_DATE)
Beispiel #3
0
 def test_18_tweak(self):
     s = repr(time.time())
     logging.info("using seed %r", s)
     r = random.Random(s)
     sn_count = 11
     sn = [
         self.createStorage(None, i + 1, NodeStates.RUNNING)
         for i in xrange(sn_count)
     ]
     pt = PartitionTable(1000, 2)
     pt.setID(1)
     for offset in xrange(pt.np):
         state = CellStates.UP_TO_DATE
         k = r.randrange(1, sn_count)
         for s in r.sample(sn, k):
             pt._setCell(offset, s, state)
             if k * r.random() < 1:
                 state = CellStates.OUT_OF_DATE
     pt.log()
     self.tweak(pt)
     self.update(pt)
Beispiel #4
0
    def test_17_tweak(self):
        sn = [self.createStorage(None, i + 1, NodeStates.RUNNING)
              for i in xrange(5)]
        pt = PartitionTable(5, 2)
        pt.setID(1)
        # part 0
        pt._setCell(0, sn[0], CellStates.DISCARDED)
        pt._setCell(0, sn[1], CellStates.UP_TO_DATE)
        # part 1
        pt._setCell(1, sn[0], CellStates.FEEDING)
        pt._setCell(1, sn[1], CellStates.FEEDING)
        pt._setCell(1, sn[2], CellStates.OUT_OF_DATE)
        # part 2
        pt._setCell(2, sn[0], CellStates.FEEDING)
        pt._setCell(2, sn[1], CellStates.UP_TO_DATE)
        pt._setCell(2, sn[2], CellStates.UP_TO_DATE)
        # part 3
        pt._setCell(3, sn[0], CellStates.UP_TO_DATE)
        pt._setCell(3, sn[1], CellStates.UP_TO_DATE)
        pt._setCell(3, sn[2], CellStates.UP_TO_DATE)
        pt._setCell(3, sn[3], CellStates.UP_TO_DATE)
        # part 4
        pt._setCell(4, sn[0], CellStates.UP_TO_DATE)
        pt._setCell(4, sn[4], CellStates.UP_TO_DATE)

        count_dict = defaultdict(int)
        self.assertPartitionTable(pt, (
            '.U...',
            'FFO..',
            'FUU..',
            'UUUU.',
            'U...U'))
        change_list = self.tweak(pt)
        self.assertPartitionTable(pt, (
            '.UO.O',
            'UU.O.',
            'UFU.O',
            '.UUU.',
            'U..OU'))
        for offset, uuid, state in change_list:
            count_dict[state] += 1
        self.assertEqual(count_dict, {CellStates.DISCARDED: 2,
                                      CellStates.FEEDING: 1,
                                      CellStates.OUT_OF_DATE: 5,
                                      CellStates.UP_TO_DATE: 3})
        self.update(pt)
        self.assertPartitionTable(pt, (
            '.UU.U',
            'UU.U.',
            'U.U.U',
            '.UUU.',
            'U..UU'))
        self.assertRaises(PartitionTableException, pt.dropNodeList, sn[1:4])
        self.assertEqual(6, len(pt.dropNodeList(sn[1:3], True)))
        self.assertEqual(3, len(pt.dropNodeList([sn[1]])))
        pt.addNodeList([sn[1]])
        self.assertPartitionTable(pt, (
            '..U.U',
            'U..U.',
            'U.U.U',
            '..UU.',
            'U..UU'))
        change_list = self.tweak(pt)
        self.assertPartitionTable(pt, (
            '.OU.U',
            'UO.U.',
            'U.U.U',
            '.OUU.',
            'U..UU'))
        self.assertEqual(3, len(change_list))
        self.update(pt, change_list)

        for np, i, expected in (
                (12, 0, ('U...|.U..|..U.|...U|'
                         'U...|.U..|..U.|...U|'
                         'U...|.U..|..U.|...U',)),
                (12, 1, ('UU...|..UU.|U...U|.UU..|...UU|'
                         'UU...|..UU.|U...U|.UU..|...UU|'
                         'UU...|..UU.',)),
                (13, 2, ('U.UU.|.U.UU|UUU..|..UUU|UU..U|'
                         'U.UU.|.U.UU|UUU..|..UUU|UU..U|'
                         'U.UU.|.U.UU|UUU..',
                         'UUU..|U..UU|.UUU.|UU..U|..UUU|'
                         'UUU..|U..UU|.UUU.|UU..U|..UUU|'
                         'UUU..|U..UU|.UUU.')),
                ):
            pt = PartitionTable(np, i)
            i += 1
            pt.make(sn[:i])
            pt.log()
            for n in sn[i:i+3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.update(pt, self.tweak(pt))
            self.assertPartitionTable(pt, expected[0])
            pt.clear()
            pt.make(sn[:i])
            for n in sn[i:i+3]:
                self.assertEqual([n], pt.addNodeList([n]))
                self.tweak(pt)
            self.update(pt)
            self.assertPartitionTable(pt, expected[-1])

        pt = PartitionTable(7, 0)
        pt.make(sn[:1])
        pt.addNodeList(sn[1:3])
        self.assertPartitionTable(pt, 'U..|U..|U..|U..|U..|U..|U..')
        self.update(pt, self.tweak(pt, sn[:1]))
        # See note in PartitionTable.tweak() about drop_list.
        #self.assertPartitionTable(pt,'.U.|..U|.U.|..U|.U.|..U|.U.')
        self.assertPartitionTable(pt, 'UU.|U.U|UU.|U.U|UU.|U.U|UU.')
Beispiel #5
0
    def test_15_dropNodeList(self):
        sn = [self.createStorage(None, i + 1, NodeStates.RUNNING)
              for i in xrange(3)]
        pt = PartitionTable(3, 0)
        pt._setCell(0, sn[0], CellStates.OUT_OF_DATE)
        pt._setCell(1, sn[1], CellStates.FEEDING)
        pt._setCell(1, sn[2], CellStates.OUT_OF_DATE)
        pt._setCell(2, sn[0], CellStates.OUT_OF_DATE)
        pt._setCell(2, sn[1], CellStates.FEEDING)
        pt._setCell(2, sn[2], CellStates.UP_TO_DATE)

        self.assertEqual(sorted(pt.dropNodeList(sn[:1], True)), [
            (0, 1, CellStates.DISCARDED),
            (2, 1, CellStates.DISCARDED),
            (2, 2, CellStates.UP_TO_DATE)])

        self.assertEqual(sorted(pt.dropNodeList(sn[2:], True)), [
            (1, 2, CellStates.UP_TO_DATE),
            (1, 3, CellStates.DISCARDED),
            (2, 2, CellStates.UP_TO_DATE),
            (2, 3, CellStates.DISCARDED)])

        self.assertRaises(PartitionTableException, pt.dropNodeList, sn[1:2])
        pt._setCell(1, sn[2], CellStates.UP_TO_DATE)
        self.assertEqual(sorted(pt.dropNodeList(sn[1:2])), [
            (1, 2, CellStates.DISCARDED),
            (2, 2, CellStates.DISCARDED)])

        pt._setCell(0, sn[0], CellStates.UP_TO_DATE)
        self.assertEqual(self.tweak(pt), [(2, 3, CellStates.FEEDING)])