Beispiel #1
0
float benchmarkLookup(vector<string> strList, ZHTClient &client) {
	vector<string>::iterator it;

	double start = 0;
	double end = 0;
	start = getTime_msec();
	int errCount = 0;
//cout << "Client: benchmarkLookup: start lookup \n";
	int c = 0;
	for (it = strList.begin(); it != strList.end(); it++) {
		string result;
//		cout << c << endl;
		c++;
//		cout<<"lookup: "<<c<<endl;
//sleep(1);
//
//		cout << "Client: What I want to find: \n";
//		cout <<"Lookup: "<< (*it).c_str() << endl;
		if (client.lookup((*it), result) < 0) {

			errCount++;
		} else if (result.empty()) { //empty string
			errCount++;
		}
//		cout << "Client: What I get: ";
//		cout << result.c_str() << endl;
	}

	end = getTime_msec();

	cout << "Lookup " << strList.size() - errCount << " packages out of "
			<< strList.size() << ", cost " << end - start << " ms" << endl;
	return 0;
}
int c_zht_lookup(const char *pair, char *result) {

	string pkg(pair);
	string returnStr;

	int ret = zhtClient.lookup(pkg, returnStr);

	char *chars = new char[returnStr.size() + 1];
	strcpy(chars, returnStr.c_str());

	result = chars;

	return ret;
}
Beispiel #3
0
float benchmarkLookup(vector<string> strList, ZHTClient &client) {
    vector<string>::iterator it;

    /*
     for (it = strList.begin(); it != strList.end(); it++) {
     Package package;
     package.ParseFromString((*it));
     package.set_operation(1); // 3 for insert, 1 for look up, 2 for remove
     package.set_replicano(3); //5: original, 3 not original

     strList.erase(it);
     string newStr = package.SerializeAsString();
     strList.push_back(newStr);
     }
    */
    double start = 0;
    double end = 0;
    start = getTime_msec();
    int errCount = 0;
    //cout << "Client: benchmarkLookup: start lookup \n";
    int c=0;
    for (it = strList.begin(); it != strList.end(); it++) {
        string result;
        //cout <<"insert count "<< c << endl;
        c++;

        //cout<<"lookup: "<<i<<endl;
        //cout << "Client: What I want to find: \n";
        //cout <<"Lookup: "<< (*it).c_str() << endl;
        if (client.lookup((*it), result) < 0) {

            errCount++;
        } else if (result.empty()) { //empty string
            errCount++;
        }
        //cout << "Client: What I get: ";
        //cout << result.c_str() << endl;
    }

    end = getTime_msec();

    cout << "Lookup " << strList.size() - errCount << " packages out of "
         << strList.size() << ", cost " << end - start << " ms" << endl;
    return 0;
}
int c_zht_lookup2_std(ZHTClient_c zhtClient, const char *key, char *result,
		size_t *n) {

	ZHTClient *zhtcppClient = (ZHTClient *) zhtClient;

	string sKey(key);

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

	string resultStr;
	int ret = zhtcppClient->lookup(package.SerializeAsString(), resultStr);

	/*
	 * hello,zht:hello,zht ==> hello,zht:zht
	 * */
	string store;
	char * pch, *sp;
	pch = strtok_r((char*) resultStr.c_str(), ":", &sp);
	Package package2;

	while (pch != NULL) {

		package2.ParseFromString(pch);
		string strRealfullpath = package2.realfullpath();

		store.append(strRealfullpath);
		store.append(":");

		pch = strtok_r(NULL, ":", &sp);
	}

	size_t found = store.find_last_of(":");
	store = store.substr(0, found);

	strncpy(result, store.c_str(), strlen(store.c_str()));
	*n = store.size();

	return ret;
}
int c_zht_lookup_std(ZHTClient_c zhtClient, const char *pair, char *result,
		size_t *n) {

	ZHTClient *zhtcppClient = (ZHTClient *) zhtClient;

	string sPair(pair);

	string resultStr;
	int ret = zhtcppClient->lookup(sPair, resultStr);

	/*
	 * hello,zht:hello,zht ==> hello,zht:zht
	 * */
	string store;
	char * pch, *sp;
	pch = strtok_r((char*) resultStr.c_str(), ":", &sp);
	Package package2;

	while (pch != NULL) {

		package2.ParseFromString(pch);
		string strRealfullpath = package2.realfullpath();

		store.append(strRealfullpath);
		store.append(":");

		pch = strtok_r(NULL, ":", &sp);
	}

	size_t found = store.find_last_of(":");
	store = store.substr(0, found);
	package2.set_realfullpath(store);

	store = package2.SerializeAsString();
	strncpy(result, store.c_str(), strlen(store.c_str()));
	*n = store.size();

	return ret;
}
int c_zht_lookup_std(ZHTClient_c zhtClient, const char *key, char *result) {

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

	ZHTClient *zhtcppClient = (ZHTClient *) zhtClient;

	string skey(key);

	string resultStr;
	int ret = zhtcppClient->lookup(skey, resultStr);

	memset(result, 0, strlen(result));

	strncpy(result, resultStr.c_str(), resultStr.size());

	return ret;
}
float benchmarkLookup() {

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

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

        string result;
        c++;

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

        int ret = zc.lookup(pkg.virtualpath(), result);

        if (ret < 0) {
            errCount++;
        } else if (result.empty()) { //empty string
            errCount++;
        }
    }

    end = TimeUtil::getTime_msec();

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

    return 0;
}
int c_zht_lookup2(const char *key, char *result, size_t *n) {

	string keyStr(key);
	string resultStr;

	if (keyStr.empty()) //empty key not allowed.
		return -1;

	Package package;
	package.set_virtualpath(keyStr); //as key
	package.set_isdir(true);
	package.set_replicano(5);
	package.set_operation(1); //1 for look up, 2 for remove, 3 for insert

	int ret = zhtClient.lookup(package.SerializeAsString(), resultStr);

	Package package2;
	package2.ParseFromString(resultStr);
	string strRealfullpath = package2.realfullpath();
	strncpy(result, strRealfullpath.c_str(), strRealfullpath.size());
	*n = strRealfullpath.size();

	return ret;
}
Beispiel #9
0
struct metadata * zht_lookup_meta(ZHTClient_c zhtClient, const char * key){

	//1. Lookup in ZHT
	ZHTClient * zhtcppClient = (ZHTClient *) zhtClient;

	string keyStr(key);
	string resSerializedPackage;
	
	Package keyPackage;
	keyPackage.set_virtualpath(keyStr); //as key
	keyPackage.set_isdir(false);
	keyPackage.set_replicano(1);
	keyPackage.set_operation(1); //1 for look up, 2 for remove, 3 for insert
	
	int res = zhtcppClient->lookup(keyPackage.SerializeAsString(),resSerializedPackage);

	dbgprintf("Package Length:%i\n",resSerializedPackage.size());

	
	//2. Parse Package and fill meta
	Package package;
	package.ParseFromString(resSerializedPackage);
	
	struct metadata* meta = (struct metadata*)malloc(sizeof(struct metadata));
	
	//2.1 General file infos
	meta->key = package.virtualpath().c_str();
	meta->k = package.k();
	meta->m = package.m();
	meta->bufsize = package.bufsize();
	meta->fileSize = package.filesize();
	meta->encodingLib = package.encodinglib();
	
	//2.2 Locations
	meta->loc = (struct comLocations *) malloc(sizeof(struct comLocations));

	struct comTransfer * current;
	struct comTransfer * prev = NULL;

	for (int j = package.location_size() -1 ; j >= 0; j--) {
		current = (struct comTransfer *) malloc(sizeof(struct comTransfer));
	
		const Package_Location& location = package.location(j);
	
		//const std::string host = location.hostname();
		current->hostName = (char *) malloc((location.hostname()).size()+1);
		strcpy(current->hostName,location.hostname().c_str());
		
		current->port = location.port();
		
		current->distantChunkName = (char *) malloc((location.distantchunkname()).size()+1);
		strcpy(current->distantChunkName,location.distantchunkname().c_str());
		
		dbgprintf("Host (%i):%s - port: %i - chunkname: %s\n",j,location.hostname().c_str(),location.port(), location.distantchunkname().c_str());
		
		current->next = prev;
		prev = current;
	}
	meta->loc->transfers = current;
	
	
	return meta;
}
void *execTask(void *popTask)
{
	string result, update, task, key, cmd, dataTask[4] = "";
	int i, k = 0, rc, data;
	char intstr[10];

	task = (char *) popTask;

	for(i = 0; i < strlen(task.c_str()); i++)
	{
		if (task[i] == ',')
			k = k + 1;
		else
			dataTask[k] = dataTask[k] + task[i];
		//key = key + task[i];
	}

	key = dataTask[0];
	cmd = dataTask[1] + " " + dataTask[2];

	//rc = system("netstat | grep 50000 | wc -l");
	rc = system(cmd.c_str());

	pthread_mutex_lock( &mutex1 );
	if ( rc == 0)
	{
		rc = zc.lookup(key, result);
		cout << "Lookup Result: " << (atoi(result.c_str()) - 1000) << endl;

		if ( rc == 0)
		{
			data = atoi(result.c_str());
			data = data + 1;

			sprintf(intstr, "%d", data);
			update = string(intstr);

			rc = zc.insert(key, update);
			cout << "Updating the Key with the Value: " << (atoi(update.c_str()) - 1000) << endl;

			if (rc == 0)
				printf("INSERT OK, rc(%d)\n", rc);
			else
				printf("INSERT ERR, rc(%d)\n", rc);
		}
		else
		{
			rc = zc.insert(key, "1001");
		}
	}
	else
	{
		cout << "********************************************************************" << endl;
		cout << "Job Failed execution: " << task << endl;
		cout << "Pushing the failed job back to queue" << endl;
		rc = zc.push((key + ".x" +dataTask[3]), task, "q1", result);

		if (rc == 0)
			printf("PUSH OK, rc(%d)\n", rc);
		else
			printf("PUSH ERR, rc(%d)\n", rc);
	}
	threadCount = threadCount - 1;
	pthread_mutex_unlock( &mutex1 );
}