Esempio n. 1
0
File: main.cpp Progetto: eJon/common
void* inc_run(das_lib::conf_t* conf)
{
    ul_logstat_t ls;
    ls.spec = FLAGS_log_to_screen ? UL_LOGTTY : 0;
    ls.to_syslog = 15;
    ls.events = 15;
    if (ul_openlog_r("inc_thread", &ls) < 0) {
        DL_LOG_FATAL("Fail to open log for inc_thread");

        return NULL;
    }

    do {
        int ret = 0;
        
        DL_LOG_TRACE("Begin loading base indexes");
        ret = conf->bdlib.start_service();
        if (!ret) {
            DL_LOG_FATAL("failed to load base index!");
            break;
        }
        DL_LOG_TRACE("End loading base indexes");


        system("mv data/inc/dsp.event.1 data/inc/dsp.event.1_bak");

        system("echo all > dump_req");

        for (long i = 0; 0 == FLAGS_inc_rounds || i < FLAGS_inc_rounds; ++i) {
            //each time
            DL_LOG_TRACE("Begin bdlib.handle_inc, round(%ld)", i);
            ret = conf->bdlib.handle_inc();
            if(!ret) {
                DL_LOG_WARNING("Error occurred in bdlib.handle_inc()");
            }
            DL_LOG_TRACE("End bdlib.handle_inc");

            if (FLAGS_sleep_interval > 0) {
                DL_LOG_TRACE("Sleep for %d seconds", FLAGS_sleep_interval);
                sleep(FLAGS_sleep_interval);
            }
            system("mv data/inc/dsp.event.1_bak data/dsp.event.1");
        }

    } while (0);

    ul_closelog_r(0);
    return NULL;
}
Esempio n. 2
0
int DASIncReader::read_next(configio::DynamicRecord &record)
{
    int ret = 0;
    unsigned long long cur_event_id;

    // check lines.
    if (_max_lines_per_round > 0 &&
        _cur_lines == _max_lines_per_round) {
        DL_LOG_TRACE("read enough lines[%d], max lines[%d]",
                _cur_lines, _max_lines_per_round);
        _cur_lines = 0;
        return READ_END;
    }
       
    // read next record.
    ret = _reader.get_next_record(record);

    if (ret < 0) {
       return READ_FAIL;
    }

    if (ret == 1) {
        _cur_lines = 0;
        return READ_END;
    }

    // check event id.
    ret = record.get_uint64(1, cur_event_id);
    if (0 != ret) {
        DL_LOG_FATAL("fail to get event id from record");
        return -1;
    }

    if (cur_event_id < _last_event_ids) {
        DL_LOG_FATAL("current_event_id[%llu] is less than previous[%llu]",
                cur_event_id,
                _last_event_ids);
        return -1;
    }
            
    _last_event_ids = cur_event_id;
    _cur_lines++;
           
    return 0;

}
Esempio n. 3
0
File: main.cpp Progetto: eJon/common
int main(int argc,char** argv)
{
    
    int ret = 0;
    das_lib::conf_t conf;

    FLAGS_flagfile="./conf/startup/gflags.conf";
    ret = google::ParseCommandLineFlags(&argc, &argv, true);
    if (ret < 0) {
        DL_LOG_FATAL("Fail to parse flags");
        return -1;
    }

    ul_logstat_t ls;
    ls.spec = FLAGS_log_to_screen ? UL_LOGTTY : 0;
    ls.to_syslog = 15;
    ls.events = 15;
    if (ul_openlog("./log", FLAGS_log_prefix_name.c_str(), &ls, 100) < 0) {
        DL_LOG_FATAL("Fail to open log");
    }

    if (ret < 0) {
        DL_LOG_FATAL ("Fail to load_conf!");
        return -1;
    }

     mrf::ConfigureService &cs = *mrf::GlobalConfigureService::instance();
    if (!cs.load("./conf/startup/bs.conf")) {
        return -1;
    }

    ret = conf.bdlib.init(cs["lib_conf"]);
    if (! ret ) {
        DL_LOG_FATAL ("Fail to init bdlib!");
        return -1;
    }
    
    DL_LOG_TRACE("Create inc thread");
    
    inc_run(&conf);
        
    ul_closelog(0);
    
    return 0;
}
Esempio n. 4
0
bool LibManager::handle_inc()
{
    int ret = 0;
    st::Timer tm;

    event_id_t last_event_id = 0;
    event_id_t cur_eid = 0;
    uint32_t count = 0;
    configio::DynamicRecord record;

    ret = _inc_reader.read_next(record);
    if (ret < 0) {
        DL_LOG_FATAL("fail to read next inc");
        return false;
    } else if (DASIncReader::READ_END == ret) {
        DL_LOG_TRACE("No DAS inc to handle since last round");
        return true;
    }

    TableGroup* p_table = NULL;
    DL_LOG_TRACE("Begin creating new version of main_table_group");
    tm.start();

    int pos = _vm_tg.create_version();
    if (pos < 0) {
        DL_LOG_FATAL("Fail to create a new version of main_table_group");
        return false;
    }
    p_table = &_vm_tg[pos];

    tm.stop();
    DL_LOG_TRACE("End creating new version of main_table_group: %lums",
                 tm.m_elapsed());

    tm.start();
    do {
        // get current event id.
        count ++;
        if (0 != get_and_check_uint64(record, 1, "event_id", cur_eid)) {
            return -1;
        }

        ret = p_table->handle_inc(record);
        if (ret < 0) {
            DL_LOG_FATAL("fail to handle_inc, event_id=%llu", cur_eid);
            return -1;
        }
        last_event_id = cur_eid;

        // get next record
        ret = _inc_reader.read_next(record);
        if (ret < 0) {
            DL_LOG_FATAL("fail to read next budget inc");
            return -1;
        } else if (DASIncReader::READ_END == ret) {
            break;
        }

    } while (true);

    _vm_tg[pos].serialize();

    _vm_tg.freeze_version(pos);

    return ret;
}