示例#1
0
def _check_tlog_dirs(node, n):
    (home_dir, _, tlf_dir, head_dir) = Common.build_node_dir_names(node)

    tlogs = X.listFilesInDir(home_dir, filter="*.tlog")
    tlxs = X.listFilesInDir(tlf_dir, filter="*.tlx")
    logging.info("tlogs:%s", tlogs)
    logging.info("tlxs:%s", tlxs)
    print tlxs

    assert_equals(len(tlogs) + len(tlxs),
                  n,
                  msg="(%s + %s) should have %i file(s)" % (tlogs, tlxs, n))
    assert_true(X.fileExists(head_dir + "/head.db"))
    logging.info("tlog_dirs are as expected")
示例#2
0
    def _assert_n_running(self, n):
        cluster = self._getCluster()
        status = cluster.getStatus()
        logging.debug('status=%s', status)
        c = 0
        for key in status.keys():
            if status[key] == X.AppStatusType.RUNNING:
                c = c + 1
        if c != n:
            for node in status.keys():
                if status[node] == X.AppStatusType.HALTED:
                    cfg = cluster._getConfigFile()
                    logDir = cfg.get(node, "log_dir")
                    fn = "%s/%s.log" % (logDir, node)
                    logging.info("fn=%s", fn)

                    def cat_log(fn):
                        with open(fn, 'r') as f:
                            lines = f.readlines()
                            logging.info("fn:%s for %s", fn, node)
                            for l in lines:
                                ls = l.strip()
                                logging.info(ls)

                    #crash log ?
                    cat_log(fn)
                    filter = '%s.debug.*' % node
                    crash = X.listFilesInDir(logDir, filter=filter)
                    if len(crash):
                        crash_fn = crash[0]
                        cat_log(crash_fn)

        msg = "expected %i running nodes, but got %i" % (n, c)
        assert_equals(c, n, msg=msg)
def test_copy_db_to_head():
    # fill cluster until they have at least 10 tlogs
    C.iterate_n_times(5000, C.set_get_and_delete)

    slave = C.node_names[1]
    # n < 1 fails
    assert_raises( Exception, lambda: C.copyDbToHead(slave, 0))
    # fails on master
    assert_raises( Exception, lambda: C.copyDbToHead(C.node_names[0], 2))

    C.copyDbToHead(slave, 1)

    C.stop_all()

    (home_dir, _, tlf_dir, head_dir) = C.build_node_dir_names(slave)
    tlogs_count = len(X.listFilesInDir( home_dir, filter="*.tlog" ))
    tlf_count = len(X.listFilesInDir( tlf_dir, filter="*.tlf" ))
    assert(tlogs_count + tlf_count < 5)
    assert(X.fileExists(head_dir + "/head.db"))
    a = C.get_i(slave, True)
    logging.info("slave_head_i='%s'", a)
    assert(a >= 5000)
def get_last_tlog_id ( node_id ):
    cluster = _getCluster()
    node_home_dir = cluster.getNodeConfig(node_id ) ['home']
    tlog_max_id = 0
    tlog_id = None
    tlogs_for_node = X.listFilesInDir( node_home_dir, filter="*.tlog" )
    for tlog in tlogs_for_node:
        tlog = tlog [ len(node_home_dir):]
        tlog = tlog.strip('/')
        tlog_id = tlog.split(".")[0]
        tlog_id = int( tlog_id )
        if tlog_id > tlog_max_id :
            tlog_max_id = tlog_id
    if tlog_id is not None:
        logging.debug("get_last_tlog_id('%s') => %s" % (node_id, tlog_id))
    else :
        raise Exception ("Not a single tlog found in %s" % node_home_dir )

    return tlog_max_id