cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Schuller (Commented) (JIRA)" <>
Subject [jira] [Commented] (CASSANDRA-3412) make nodetool ring ownership smarter
Date Mon, 13 Feb 2012 20:24:59 GMT


Peter Schuller commented on CASSANDRA-3412:

Our internal tool (external, in python, based on describe_ring) simply uses {{describe_ring}}
and looks at each range and their responsible nodes and just adds them all up. The ownership
we report for a node is the total amount of ringspace (regardless of primary/secondary/dc/etc
concerns) that the node has, compared to the overall total.

It ends up giving you the real number while completely blackboxing "why" we got there - whether
it be due to rack awareness (CASSANDRA-3810) or DC:s.

FWIW, here is the code for that. It's not self-contained and won't run, but it's an FYI. The
topology_xref is just post-processing the describe ring results to yield the map of range
-> nodes_responsible.

def cmd_effective_ownership(opts, args):
    Print effective ownership of nodes in a cluster.                                     
    Effective ownership means the actual amount of the ring for which                    
    it has data, whether or not it is because it is the primary or                       
    secondary (etc) owner of the ring segment. This is essentially the                   
    ownership you would want "nodetool ring" to print but doesn't.                       
    if not args and not opts.all:

    node_ranges, range_nodes = topology_xref(describe_ring(*((opts,) + split_hostport(seed(opts,
'localhost') if opts.all else args[0]))))

    if opts.all:
        args = node_ranges.keys()

    # acrobatics to handle wrap-around                                                   
    max_token = 0
    min_token = 2**127
    for r in range_nodes.keys():
        if r[0] < min_token:
            min_token = r[0]
        if r[1] > max_token:
            max_token = r[1]

    def ownership(start_token, end_token):
        start_token, end_token = int(start_token), int(end_token)
        if end_token < start_token:
            # wrap-around                                                                
            return end_token + (2**127 - start_token)
            return end_token - start_token

    toprint = [] # list of (owned, ranges), later to be sorted                           
    for node in (hostnames.normalize_hostname(arg) for arg in args):
        if not node in node_ranges:
            raise cmdline.UserError('node %s not in ring' % (node,))
        ranges = node_ranges[node]
        owned = reduce(lambda a, b: a + b, [ownership(r[0], r[1]) for r in ranges], 0)
        toprint.append((owned, node, ranges))

    toprint = sorted(toprint, reverse=True)
    for owned, node, ranges in toprint:
        print '%s %f%%' % (node, float(owned) / 2**127 * 100.0)
        if opts.print_ranges:
            for r in sorted(ranges):
                print '  %s - %s' % (r[0], r[1])

> make nodetool ring ownership smarter
> ------------------------------------
>                 Key: CASSANDRA-3412
>                 URL:
>             Project: Cassandra
>          Issue Type: Improvement
>            Reporter: Jackson Chung
>            Assignee: Vijay
>            Priority: Minor
> just a thought.. the ownership info currently just look at the token and calculate the
% between nodes. It would be nice if it could do more, such as discriminate nodes of each
DC, replica set, etc. 
> ticket is open for suggestion...

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message