예제 #1
0
void CleanWorker::doDelete(char** keys, int keynum) {
    std::vector<data_entry*> keys_v;
    for (int i = 0; i < keynum; ++i)
    {
      int pkeysize = 0;
      char *pkey = canonical_key(keys[i], &pkeysize);
      data_entry* key = new data_entry(pkey, pkeysize, false);
      keys_v.push_back(key);
    }
   
    for(int i = 0; i < keynum; ++i) {
        int ret, j;
        for(j = 0; j < _TRY_SEND_TIEMS; ++j) {
            ret = client_helper.remove(_area, *(keys_v[i]));
            if (ret == TAIR_RETURN_SUCCESS || TAIR_RETURN_DATA_NOT_EXIST) {
                break;
            }
        }
        if (j >= _TRY_SEND_TIEMS) {
            fprintf(stderr, "DELETE: %s, ret: %d\n", client_helper.get_error_msg(ret), ret);
        }
    }

    std::vector<data_entry*>::iterator vit = keys_v.begin();
    for ( ; vit != keys_v.end(); ++vit)
    {
        if (_key_format != NO_FORMAT) {
            char* data = (*vit)->get_data();
            free(data);
        }
        delete *vit;
        (*vit) = NULL;
    }
}
예제 #2
0
void CleanWorker::start() {
    client_helper.set_timeout(5000);
    bool done = client_helper.startup(_server_addr, NULL, _group_name);
    if (done == false) {
        fprintf(stderr, "file %s, line %d: %s cann't connect.\n",
                __FILE__, __LINE__, _server_addr);
        return;
    }
    int flag = pthread_create(&_work_thread, NULL, thread_func, this);
    if (flag < 0) {
        fprintf(stderr, "file %s, line %d: %s\n",
                __FILE__, __LINE__, strerror(errno));
        return;
    }
}
int main(int argc, const char *argv[])
{
    if (argc < 3) {
        log_error("Usage %s thread_number task_per_number", argv[0]);
        return EXIT_FAILURE;
    }
    int thread_number = atoi(argv[1]);
    int task_per_thread = atoi(argv[2]);

    TBSYS_LOGGER.setLogLevel("INFO");
    bool done = tairClient.startup("10.138.87.53", "10.138.87.54", "group_1");


    int rc = tairClient.remove_area(10);
    if (0 != rc) {
        log_error("remove area 10 failed, rc:%d", rc);
        return EXIT_FAILURE;
    }

    struct timeval begin_time;
    struct timeval end_time;
    gettimeofday(&begin_time, NULL);

    std::vector<boost::thread*> thread_vec;
    for (int i = 0; i < thread_number; i++) {
        boost::thread* thrd = new boost::thread(boost::bind(&zadd_data, i, task_per_thread));
        thread_vec.push_back(thrd);
    }   

    std::vector<boost::thread*>::iterator it = thread_vec.begin();
    for(; it != thread_vec.end(); ++it) {
        (*it)->join();
    }   

    gettimeofday(&end_time, NULL);
    log_info("used time:%ld success:%d failed:%d\n", diff_time(begin_time, end_time), success, failed);
    return 0;
}
void zadd_data(int index_thread, int task_number) {
    DVECT* dvect = vector_double_rand(10);
    VDE* vde = vector_data_entry_numeric_rand(task_number);
    for (size_t i = 0; i < vde->size(); i++) {
        char buf[32] = {0};
        sprintf(buf, "simple_zadd_case_%d_%d", index_thread, i);
        data_entry key(buf);
        int resultcode = tairClient.zadd(10, key, G(G(vde)[i]), G(dvect)[i%10], NOT_CARE_EXPIRE, (const int)NOT_CARE_VERSION);
        if ( 0 == resultcode ) {
            success += 1;
        }
        else {
            failed += 1;
            log_error("key:[%s] value:[%s] score:[%f], rc:[%d]", 
                    key.get_data(),  G(G(vde)[i]).get_data(), G(dvect)[i], resultcode);
        }
    }
    vector_data_entry_free(vde, true);
    delete dvect;
}