int c_zht_append_std(ZHTClient_c zhtClient, const char *pair) {

	ZHTClient * zhtcppClient = (ZHTClient *) zhtClient;

	string str(pair);

	return zhtcppClient->append(str);
}
Exemplo n.º 2
0
//pretty much same as benchmarkInsert.
int benchmarkAppend(ZHTClient &client, int numTest, int lenString) {
//	cout << "start to append"<<endl;
//      if (clientRet.initialize(cfgFile, memberList) != 0) { //zhouxb
	vector<string> pkgList_append;
	for (int i = 0; i < numTest; i++) {
		Package package, package_ret;
		package.set_virtualpath(randomString(lenString).append("-append")); //as key
		package.set_isdir(true);
		package.set_replicano(5); //orginal--Note: never let it be nagative!!!
		package.set_operation(4); // 3 for insert, 1 for look up, 2 for remove
		package.set_realfullpath(
				"Some-Real-longer-longer-and-longer-Paths--------");
		package.add_listitem("item-----2");
		package.add_listitem("item-----3");
		package.add_listitem("item-----4");
		package.add_listitem("item-----5");
		package.add_listitem("item-----6");
		string str = package.SerializeAsString();
//              cout << "package size = " << str.size() << endl;
//              cout<<"Client.cpp:benchmarkInsert: "<<endl;
//              cout<<"string: "<<str<<endl;
//              cout<<"Insert str: "<<str.c_str()<<endl;
//              cout<<"data(): "<< str.data()<<endl;
		pkgList_append.push_back(str);
	}
	double start = 0;
	double end = 0;
	start = getTime_msec();
	int errCount = 0;
	vector<string>::iterator it;
	int c = 0;
//cout << "-----0" << endl;
	for (it = pkgList_append.begin(); it != pkgList_append.end(); it++) {
		//      cerr <<"insert count "<< c << endl;
		c++;
		string str_ins = *it;
//cout << "-----1:about to append" << endl;
//	sleep(1);
		int ret = client.append(str_ins);
		if (ret != 0)
//			cout << "client: append ret = " << ret << endl;
//cout << "-----2" << endl;
			if (ret < 0) {
				errCount++;
			}
	}
//close(sock);
	end = getTime_msec();
	cout << "Appended " << numTest - errCount << " packages out of " << numTest
			<< ", cost " << end - start << " ms" << endl;
	return 0;
}
Exemplo n.º 3
0
int benchmarkAppend() {

    vector<string> pkgList_append;

    vector<string>::iterator it;
    for (it = pkgList.begin(); it != pkgList.end(); it++) {

        Package package;
        package.ParseFromString((*it));

        package.add_listitem("item-----6-append");

        pkgList_append.push_back(package.SerializeAsString());
    }

    double start = 0;
    double end = 0;
    start = TimeUtil::getTime_msec();
    int errCount = 0;

    int c = 0;
    for (it = pkgList_append.begin(); it != pkgList_append.end(); it++) {

        c++;

        string pkg_str = *it;
        Package pkg;
        pkg.ParseFromString(pkg_str);

        int ret = zc.append(pkg.virtualpath(), pkg_str);

        if (ret < 0) {
            errCount++;
        }
    }

    end = TimeUtil::getTime_msec();

    char buf[200];
    sprintf(buf, "Appended packages, %d, %d, cost(ms), %f", numOfOps - errCount,
            numOfOps, end - start);
    cout << buf << endl;

    return 0;
}
int c_zht_append_std(ZHTClient_c zhtClient, const char *key,
		const char *value) {

#ifdef IND_MUTEX
	LockGuard lock(&c_zht_append_mutex);
#elif SHARED_MUTEX
	LockGuard lock(&c_zht_client_mutex);
#else
#endif

	ZHTClient * zhtcppClient = (ZHTClient *) zhtClient;

	string skey(key);
	string sval(value);

	return zhtcppClient->append(skey, sval);

}
int c_zht_append2_std(ZHTClient_c zhtClient, const char *key,
		const char *value) {

	ZHTClient * zhtcppClient = (ZHTClient *) zhtClient;

	string sKey(key);
	string sValue(value);

	Package package;
	package.set_virtualpath(sKey); //as key
	package.set_isdir(true);
	package.set_replicano(5);
	package.set_operation(4); //1 for look up, 2 for remove, 3 for insert, 4 append
	if (!sValue.empty())
		package.set_realfullpath(sValue);

	return zhtcppClient->append(package.SerializeAsString());

}