Last active
March 15, 2016 10:48
-
-
Save shaitan/e4f5226bdfa47e5d702d to your computer and use it in GitHub Desktop.
Check replicas consistency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from optparse import OptionParser | |
| import elliptics | |
| def iterate(s, group): | |
| route = s.routes.filter_by_group(group)[0] | |
| it_s = s.clone() | |
| it_s.cflags = 0 | |
| it_s.set_direct_id(route.address, route.backend_id) | |
| for r in it_s.start_iterator('', [], elliptics.iterator_types.network, elliptics.iterator_flags.no_meta, elliptics.Time(0,0), elliptics.Time(0,0)): | |
| if r.response.status == 0: | |
| yield r.response.key | |
| def print_mismatch(lookups, key): | |
| report = 'key: {} mismatch found:'.format(key) | |
| for r in lookups: | |
| result = r.get()[0] | |
| report += '\ngroup: #{} has '.format(result.group_id) | |
| if result.status != 0: | |
| report += 'failed lookup: {}'.format(result.status) | |
| else: | |
| report += 'checksum: {}'.format(result.checksum) | |
| print report + '\n' | |
| def main(): | |
| parser = OptionParser() | |
| parser.desription = __doc__ | |
| parser.add_option('-r', '--remote', action='append', dest='remotes', default=[], help='Elliptics node address') | |
| parser.add_option('-g', '--groups', action='store', dest='groups', help='Comma separated list of groups') | |
| options, args = parser.parse_args(None) | |
| groups = map(int, options.groups.split(',')) | |
| s = elliptics.Session(elliptics.create_node(remotes=options.remotes, | |
| flags=elliptics.config_flags.no_route_list, | |
| log_file='check.log', | |
| log_level=elliptics.log_level.info, | |
| io_thread_num=len(groups) + 1, | |
| net_thread_num=len(groups), | |
| nonblocking_io_thread_num=len(groups) + 1)) | |
| s.groups = groups | |
| s.cflags = elliptics.command_flags.checksum | elliptics.command_flags.nolock | |
| s.exceptions_policy = elliptics.exceptions_policy.no_exceptions | |
| s.set_filter(elliptics.filters.all_with_ack) | |
| for key in iterate(s, groups[0]): | |
| lookups = [] | |
| for g in groups: | |
| s.groups = [g] | |
| lookups.append(s.lookup(key)) | |
| try: | |
| csum = next(r.get()[0].checksum for r in lookups if r.get()[0].status == 0) | |
| except StopIteration: | |
| csum = None | |
| if any(r.get()[0].status != 0 or r.get()[0].checksum != csum for r in lookups): | |
| print_mismatch(lookups, key) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment