mysqlops.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:ops 作者: xiaomatech 项目源码 文件源码
def schema_verifier(**args):
    zk_prefix = SHARDED_DBS_PREFIX_MAP[args.instance_type]['zk_prefix']
    seed_instance = HostAddr(args.seed_instance)
    desired = show_create_table(seed_instance, args.seed_db, args.table)
    tbl_hash = hashlib.md5(desired).hexdigest()
    print("Desired table definition:\n{desired}").format(desired=desired)
    incorrect = check_schema(zk_prefix, args.table, tbl_hash)
    if len(incorrect) == 0:
        print "It appears that all schema is synced"
        sys.exit(0)

    d = difflib.Differ()
    for problem in incorrect.iteritems():
        represenative = list(problem[1])[0].split(' ')
        hostaddr = HostAddr(represenative[0])
        create = show_create_table(hostaddr, represenative[1], args.table)
        diff = d.compare(desired.splitlines(), create.splitlines())
        print 'The following difference has been found:'
        print '\n'.join(diff)
        print "It is present on the following db's:"
        print '\n'.join(list(problem[1]))
    sys.exit(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号