Commit 323fd636 authored by Julien Muchembled's avatar Julien Muchembled

In logs, dump the partition table in a more compact and readable way

parent 7fff11f6
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import math import math
from collections import defaultdict
from functools import partial
from . import logging, protocol from . import logging, protocol
from .locking import Lock from .locking import Lock
from .protocol import uuid_str, CellStates from .protocol import uuid_str, CellStates
...@@ -256,39 +258,32 @@ class PartitionTable(object): ...@@ -256,39 +258,32 @@ class PartitionTable(object):
def _format(self): def _format(self):
"""Help debugging partition table management. """Help debugging partition table management.
Output sample: Output sample (np=48, nr=0, just after a 3rd node is added):
pt: node 0: S1, R pt: 10v 20v 30v 40v
pt: node 1: S2, R pt: S1 R U.FOF.U.FOF.U.FOF.U.FOF.U.FOF.U.FOF.U.FOF.U.FOF.
pt: node 2: S3, R pt: S2 R .U.FOF.U.FOF.U.FOF.U.FOF.U.FOF.U.FOF.U.FOF.U.FOF
pt: node 3: S4, R pt: S3 R ..O..O..O..O..O..O..O..O..O..O..O..O..O..O..O..O
pt: 00: .UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.
pt: 11: U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U|.UU.|U..U The first line helps to locate a nth partition ('v' is an bottom arrow)
and it is omitted when the table has less than 10 partitions.
Here, there are 4 nodes in RUNNING state.
The first partition has 2 replicas in UP_TO_DATE state, on nodes 1 and
2 (nodes 0 and 3 are displayed as unused for that partition by
displaying a dot).
The first number on the left represents the number of the first
partition on the line (here, line length is 11 to keep the docstring
width under 80 column).
""" """
node_list = sorted(self.count_dict) node_list = sorted(self.count_dict)
result = ['pt: node %u: %s, %s' % (i, uuid_str(node.getUUID()), if not node_list:
protocol.node_state_prefix_dict[node.getState()]) return ()
for i, node in enumerate(node_list)] cell_state_dict = protocol.cell_state_prefix_dict
append = result.append node_dict = defaultdict(partial(bytearray, '.' * self.np))
line = [] for offset, row in enumerate(self.partition_list):
max_line_len = 20 # XXX: hardcoded number of partitions per line for cell in row:
prefix = 0 node_dict[cell.getNode()][offset] = \
prefix_len = int(math.ceil(math.log10(self.np))) cell_state_dict[cell.getState()]
for offset, row in enumerate(self._formatRows(node_list)): n = len(uuid_str(node_list[-1].getUUID()))
if len(line) == max_line_len: result = [''.join('%9sv' % x if x else 'pt:' + ' ' * (5 + n)
append('pt: %0*u: %s' % (prefix_len, prefix, '|'.join(line))) for x in xrange(0, self.np, 10))
line = [] ] if self.np > 10 else []
prefix = offset result.extend('pt: %-*s %s %s' % (n, uuid_str(node.getUUID()),
line.append(row) protocol.node_state_prefix_dict[node.getState()],
if line: node_dict[node])
append('pt: %0*u: %s' % (prefix_len, prefix, '|'.join(line))) for node in node_list)
return result return result
def _formatRows(self, node_list): def _formatRows(self, node_list):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment