Beispiel #1
0
string HTWorker::run(const char *buf) {

	string result;

	ZPack zpack;
	string str(buf);
	zpack.ParseFromString(str);

	if (zpack.opcode() == Const::ZSC_OPC_LOOKUP) {

		result = lookup(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_INSERT) {

		result = insert(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_APPEND) {

		result = append(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_CMPSWP) {

		result = compare_swap(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_REMOVE) {

		result = remove(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_STCHGCB) {

		result = state_change_callback(zpack);
	} else {

		result = Const::ZSC_REC_UOPC;
	}

	return result;
}
Beispiel #2
0
string HTWorker::state_change_callback_internal(const ZPack &zpack) {

	string result;

	if (zpack.key().empty())
		return Const::ZSC_REC_EMPTYKEY; //-1

	string key = zpack.key();
	string *ret = PMAP->get(key);

	if (ret == NULL) {

		printf("thread[%lu] DB Error: lookup found nothing\n", pthread_self());
		fflush(stdout);

		result = Const::ZSC_REC_NONEXISTKEY;
	} else {

		ZPack rltpack;
		rltpack.ParseFromString(*ret);

		if (zpack.val() == rltpack.val()) {

			result = Const::ZSC_REC_SUCC; //0, succeed.
		} else {

			result = Const::ZSC_REC_SCCBPOLLTRY;
		}
	}

	return result;
}
Beispiel #3
0
string HTWorker::compare_swap_internal(const ZPack &zpack) {

	string ret;

	/*get Package stored by lookup*/
	string lresult = lookup_shared(zpack);
	ZPack lzpack;
	lresult = erase_status_code(lresult);
	lzpack.ParseFromString(lresult);

	/*get seen_value passed in*/
	string seen_value_passed_in = zpack.val();

	/*get seen_value stored*/
	string seen_value_stored = lzpack.val();

	/*	printf("{%s}:{%s,%s}\n", zpack.key().c_str(), zpack.val().c_str(),
	 zpack.newval().c_str());*/

	/*they are equivalent, compare and swap*/
	if (!seen_value_passed_in.compare(seen_value_stored)) {

		lzpack.set_val(zpack.newval());

		return insert_shared(lzpack);

	} else {

		return Const::ZSC_REC_SRVEXP;
	}
}
Beispiel #4
0
string ZHTClient::extract_value(const string &returnStr) {

	string val;

	StrTokenizer strtok(returnStr, ":");
	/*
	 * hello,zht:hello,ZHT ==> zht:ZHT
	 * */

	if (strtok.has_more_tokens()) {

		while (strtok.has_more_tokens()) {

			ZPack zpack;
			zpack.ParseFromString(strtok.next_token());

			if (zpack.valnull())
				val.append("");
			else
				val.append(zpack.val());

			val.append(":");
		}

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

	} else {

		ZPack zpack;
		zpack.ParseFromString(returnStr);

		if (zpack.valnull())
			val = "";
		else
			val = zpack.val();
	}

	return val;
}
Beispiel #5
0
string HTWorker::run(const char *buf) {

	string result;

	ZPack zpack;
	//string str(buf);
	string* str =(string*) buf;


	zpack.ParseFromString(*str);


	if(ZPack_Pack_type_BATCH_REQ  == zpack.pack_type()){//batch
		cout << "HTWrorker::run(): ZPack_Pack_type_BATCH_REQ received."<< endl;
		cout << "Batch contains "<< zpack.batch_item_size() << " items."<<endl;
		cout <<"zpack.key: "<< zpack.key() <<endl;
		cout <<"zpack.batch_item(i).val: "<<zpack.batch_item(0).val() << endl<< endl;
		result = Const::ZSC_REC_UOPC; // "OK";

	}else if(ZPack_Pack_type_SINGLE == zpack.pack_type()){//single

	if (zpack.opcode() == Const::ZSC_OPC_LOOKUP) {

		result = lookup(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_INSERT) {

		result = insert(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_APPEND) {

		result = append(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_CMPSWP) {

		result = compare_swap(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_REMOVE) {

		result = remove(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_STCHGCB) {

		result = state_change_callback(zpack);
	} else {

		result = Const::ZSC_REC_UOPC;
	}
	}
	return result;
}