15399fc81SSangharsh Agarwal/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
25399fc81SSangharsh Agarwal/*
35399fc81SSangharsh Agarwal *     Copyright 2012-2013 Couchbase, Inc.
45399fc81SSangharsh Agarwal *
55399fc81SSangharsh Agarwal *   Licensed under the Apache License, Version 2.0 (the "License");
65399fc81SSangharsh Agarwal *   you may not use this file except in compliance with the License.
75399fc81SSangharsh Agarwal *   You may obtain a copy of the License at
85399fc81SSangharsh Agarwal *
95399fc81SSangharsh Agarwal *       http://www.apache.org/licenses/LICENSE-2.0
105399fc81SSangharsh Agarwal *
115399fc81SSangharsh Agarwal *   Unless required by applicable law or agreed to in writing, software
125399fc81SSangharsh Agarwal *   distributed under the License is distributed on an "AS IS" BASIS,
135399fc81SSangharsh Agarwal *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145399fc81SSangharsh Agarwal *   See the License for the specific language governing permissions and
155399fc81SSangharsh Agarwal *   limitations under the License.
165399fc81SSangharsh Agarwal */
175399fc81SSangharsh Agarwal#include <snappy-c.h>
185399fc81SSangharsh Agarwal#include <time.h>
195399fc81SSangharsh Agarwal#include <sys/time.h>
205399fc81SSangharsh Agarwal#include <stdio.h>
215399fc81SSangharsh Agarwal#include <vector>
225399fc81SSangharsh Agarwal#include <libcouchbase/couchbase.h>
235399fc81SSangharsh Agarwal#include <libcouchbase/durability.h>
245399fc81SSangharsh Agarwal#include <stdlib.h>
255399fc81SSangharsh Agarwal#include <string>
265399fc81SSangharsh Agarwal#include <cstring>
275399fc81SSangharsh Agarwal#include <stdint.h>
285399fc81SSangharsh Agarwal#ifdef _WIN32
295399fc81SSangharsh Agarwal#define PRIu64 "I64u"
305399fc81SSangharsh Agarwal#else
315399fc81SSangharsh Agarwal#include <inttypes.h>
325399fc81SSangharsh Agarwal#endif
335399fc81SSangharsh Agarwal
345399fc81SSangharsh Agarwalchar* getvaluebuf;
355399fc81SSangharsh Agarwalchar* statkeybuf;
365399fc81SSangharsh Agarwalchar* statvaluebuf;
375399fc81SSangharsh Agarwallcb_size_t* statkeysize;
385399fc81SSangharsh Agarwallcb_size_t* statvaluesize;
395399fc81SSangharsh Agarwallong* getvaluesize;
405399fc81SSangharsh Agarwallcb_datatype_t* getvaluedtype;
415399fc81SSangharsh Agarwalstd::vector<std::string> threadstate;
425399fc81SSangharsh Agarwalbool warmupdone = false;
435399fc81SSangharsh Agarwalbool gotwm_val_cn = false;
445399fc81SSangharsh Agarwalbool gotreplica_curr_items = false;
455399fc81SSangharsh Agarwalbool goteject_num_items = false;
465399fc81SSangharsh Agarwalbool got_active_resident = false;
475399fc81SSangharsh Agarwalchar* wm_val_cn;
485399fc81SSangharsh Agarwalchar* rep_val_cn;
495399fc81SSangharsh Agarwalchar* ejected_val_cn;
505399fc81SSangharsh Agarwalchar* resident_val_cn;
515399fc81SSangharsh Agarwalint* ep_warmup_value_count;
525399fc81SSangharsh Agarwal//extern double t1;
535399fc81SSangharsh Agarwalextern struct timeval tim;
545399fc81SSangharsh Agarwalstruct timeval reptim;
555399fc81SSangharsh Agarwalextern double t1;
565399fc81SSangharsh Agarwaldouble t2;
575399fc81SSangharsh Agarwalstd::vector<std::pair<std::string, double> > replatencies;
585399fc81SSangharsh Agarwaltypedef std::vector<std::pair<std::string, std::string> > StatsVector;
595399fc81SSangharsh Agarwalstruct stats_generic
605399fc81SSangharsh Agarwal{
615399fc81SSangharsh Agarwal	int refcount;
625399fc81SSangharsh Agarwal	StatsVector statsvec;
635399fc81SSangharsh Agarwal};
645399fc81SSangharsh Agarwalstruct stats_generic genericstats =
655399fc81SSangharsh Agarwal{ 0 };
665399fc81SSangharsh Agarwalextern int numReplicaget;
675399fc81SSangharsh Agarwal
685399fc81SSangharsh Agarwalstatic void error_callback(lcb_t instance, lcb_error_t error, const char *errinfo)
695399fc81SSangharsh Agarwal{
705399fc81SSangharsh Agarwal	fprintf(stderr, "ERROR: %s (0x%x), %s\n", lcb_strerror(instance, error), error, errinfo);
715399fc81SSangharsh Agarwal	//exit(EXIT_FAILURE);
725399fc81SSangharsh Agarwal}
735399fc81SSangharsh Agarwal
745399fc81SSangharsh Agarwalstatic void durability_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_durability_resp_t *resp)
755399fc81SSangharsh Agarwal{
765399fc81SSangharsh Agarwal	if (error == LCB_SUCCESS)
775399fc81SSangharsh Agarwal	{
785399fc81SSangharsh Agarwal		/*gettimeofday(&reptim, NULL);
795399fc81SSangharsh Agarwal		 t2 = (double) reptim.tv_usec - t1;
805399fc81SSangharsh Agarwal		 std::string key1((char *)resp->v.v0.key,(size_t)resp->v.v0.nkey);
815399fc81SSangharsh Agarwal		 std::pair <std::string,double> keylatency(key1,(double) (reptim.tv_sec*1000000+reptim.tv_usec));
825399fc81SSangharsh Agarwal		 replatencies.push_back(keylatency);
835399fc81SSangharsh Agarwal		 fprintf(stderr, "key: ");
845399fc81SSangharsh Agarwal		 fwrite(resp->v.v0.key, sizeof(char), resp->v.v0.nkey, stderr);
855399fc81SSangharsh Agarwal		 fprintf(stderr, " replicated to number of nodes:");
865399fc81SSangharsh Agarwal		 fprintf(stderr, "%x",resp->v.v0.nreplicated);
875399fc81SSangharsh Agarwal		 fprintf(stderr, " reptim is:");
885399fc81SSangharsh Agarwal		 fprintf(stderr, "%.6lf",((double) reptim.tv_usec)/1000);
895399fc81SSangharsh Agarwal		 fprintf(stderr, " replication latency is:");
905399fc81SSangharsh Agarwal		 fprintf(stderr, "%.6lf",t2/1000);
915399fc81SSangharsh Agarwal		 fprintf(stderr, "\n");*/
925399fc81SSangharsh Agarwal
935399fc81SSangharsh Agarwal	}
945399fc81SSangharsh Agarwal	else
955399fc81SSangharsh Agarwal	{
965399fc81SSangharsh Agarwal		fprintf(stderr, "ERROR: \n", lcb_strerror(instance, error), error);
975399fc81SSangharsh Agarwal		//exit(EXIT_FAILURE);
985399fc81SSangharsh Agarwal	}
995399fc81SSangharsh Agarwal}
1005399fc81SSangharsh Agarwal
1015399fc81SSangharsh Agarwalstatic void store_callback(lcb_t instance, const void *cookie, lcb_storage_t operation, lcb_error_t error, const lcb_store_resp_t *item)
1025399fc81SSangharsh Agarwal{
1035399fc81SSangharsh Agarwal	if (error == LCB_SUCCESS)
1045399fc81SSangharsh Agarwal	{
1055399fc81SSangharsh Agarwal		//fprintf(stderr, "STORED \"");
1065399fc81SSangharsh Agarwal		//fwrite(item->v.v0.key, sizeof(char), item->v.v0.nkey, stderr);
1075399fc81SSangharsh Agarwal	}
1085399fc81SSangharsh Agarwal	else
1095399fc81SSangharsh Agarwal	{
1105399fc81SSangharsh Agarwal		fprintf(stderr, "STORE ERROR: %s (0x%x)\n", lcb_strerror(instance, error), error);
1115399fc81SSangharsh Agarwal		//exit(EXIT_FAILURE);
1125399fc81SSangharsh Agarwal	}
1135399fc81SSangharsh Agarwal	(void) cookie;
1145399fc81SSangharsh Agarwal	(void) operation;
1155399fc81SSangharsh Agarwal}
1165399fc81SSangharsh Agarwal
1175399fc81SSangharsh Agarwalstatic void get_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_get_resp_t *item)
1185399fc81SSangharsh Agarwal{
1195399fc81SSangharsh Agarwal	if (error == LCB_SUCCESS)
1205399fc81SSangharsh Agarwal	{
1215399fc81SSangharsh Agarwal
1225399fc81SSangharsh Agarwal		std::string key;
1235399fc81SSangharsh Agarwal		key.assign((const char *) item->v.v0.key, item->v.v0.nkey);
1245399fc81SSangharsh Agarwal		if (key.compare(0, 7, "replica"))
1255399fc81SSangharsh Agarwal			numReplicaget++;
1265399fc81SSangharsh Agarwal		/*getvaluesize = (long *) calloc(1,sizeof(long));
1275399fc81SSangharsh Agarwal		 getvaluedtype = (lcb_datatype_t*) calloc(1,sizeof(lcb_datatype_t));
1285399fc81SSangharsh Agarwal		 getvaluebuf = (char *)item->v.v0.bytes;
1295399fc81SSangharsh Agarwal		 *getvaluesize = (long)item->v.v0.nbytes;
1305399fc81SSangharsh Agarwal		 *getvaluedtype = item->v.v0.datatype;
1315399fc81SSangharsh Agarwal
1325399fc81SSangharsh Agarwal		 fprintf(stderr, "GOT size of doc: %ld \n",(long)item->v.v0.nbytes);
1335399fc81SSangharsh Agarwal		 fwrite(item->v.v0.key, sizeof(char), item->v.v0.nkey, stderr);
1345399fc81SSangharsh Agarwal		 fwrite(item->v.v0.bytes, sizeof(char), item->v.v0.nbytes, stderr);
1355399fc81SSangharsh Agarwal		 fprintf(stderr, "\n");
1365399fc81SSangharsh Agarwal		 fprintf(stderr, "GOT CAS value: %ld \n",(long)item->v.v0.cas);
1375399fc81SSangharsh Agarwal		 if(item->v.v0.datatype==LCB_BINARY_DATATYPE_COMPRESSED_JSON||item->v.v0.datatype==LCB_BINARY_DATATYPE_COMPRESSED){
1385399fc81SSangharsh Agarwal		 char uncompressed[2560];
1395399fc81SSangharsh Agarwal		 size_t uncompressed_len = 2560;
1405399fc81SSangharsh Agarwal		 snappy_status status;
1415399fc81SSangharsh Agarwal		 status=snappy_uncompress((const char *)item->v.v0.bytes, item->v.v0.nbytes, uncompressed, &uncompressed_len);
1425399fc81SSangharsh Agarwal		 fprintf(stderr, "uncompressed length %d\n",(int)uncompressed_len);
1435399fc81SSangharsh Agarwal		 fwrite(uncompressed, sizeof(char), uncompressed_len, stderr);
1445399fc81SSangharsh Agarwal		 fprintf(stderr,"\n");
1455399fc81SSangharsh Agarwal		 }*/
1465399fc81SSangharsh Agarwal	}
1475399fc81SSangharsh Agarwal	else
1485399fc81SSangharsh Agarwal	{
1495399fc81SSangharsh Agarwal		fprintf(stderr, "GET ERROR: %s (0x%x)\n", lcb_strerror(instance, error), error);
1505399fc81SSangharsh Agarwal	}
1515399fc81SSangharsh Agarwal	(void) cookie;
1525399fc81SSangharsh Agarwal}
1535399fc81SSangharsh Agarwal
1545399fc81SSangharsh Agarwalbool isWarmupdone(const lcb_server_stat_resp_t *resp)
1555399fc81SSangharsh Agarwal{
1565399fc81SSangharsh Agarwal
1575399fc81SSangharsh Agarwal	char* keystr = (char *) calloc(resp->v.v0.nkey, sizeof(char));
1585399fc81SSangharsh Agarwal	memcpy(keystr, resp->v.v0.key, resp->v.v0.nkey);
1595399fc81SSangharsh Agarwal	std::string key = std::string(keystr);
1605399fc81SSangharsh Agarwal	std::string keyref("ep_warmup_state");
1615399fc81SSangharsh Agarwal
1625399fc81SSangharsh Agarwal	char* valstr = (char *) calloc(resp->v.v0.nbytes, sizeof(char));
1635399fc81SSangharsh Agarwal	memcpy(valstr, resp->v.v0.bytes, resp->v.v0.nbytes);
1645399fc81SSangharsh Agarwal	std::string val = std::string(valstr);
1655399fc81SSangharsh Agarwal	std::string valref("done");
1665399fc81SSangharsh Agarwal
1675399fc81SSangharsh Agarwal	if (keyref.compare(key) == 0 && valref.compare(val) == 0)
1685399fc81SSangharsh Agarwal	{
1695399fc81SSangharsh Agarwal		char* thstate = (char *) calloc(resp->v.v0.nbytes + 1, sizeof(char));
1705399fc81SSangharsh Agarwal		memcpy(thstate, resp->v.v0.bytes, resp->v.v0.nbytes);
1715399fc81SSangharsh Agarwal		thstate[resp->v.v0.nbytes] = '\0';
1725399fc81SSangharsh Agarwal		std::string str = std::string(thstate);
1735399fc81SSangharsh Agarwal		threadstate.push_back(str);
1745399fc81SSangharsh Agarwal		return true;
1755399fc81SSangharsh Agarwal	}
1765399fc81SSangharsh Agarwal
1775399fc81SSangharsh Agarwal	else if (keyref.compare(key) == 0 && valref.compare(val) != 0)
1785399fc81SSangharsh Agarwal	{
1795399fc81SSangharsh Agarwal		char* thstate = (char *) calloc(resp->v.v0.nbytes + 1, sizeof(char));
1805399fc81SSangharsh Agarwal		memcpy(thstate, resp->v.v0.bytes, resp->v.v0.nbytes);
1815399fc81SSangharsh Agarwal		thstate[resp->v.v0.nbytes] = '\0';
1825399fc81SSangharsh Agarwal		std::string str = std::string(thstate);
1835399fc81SSangharsh Agarwal		threadstate.push_back(str);
1845399fc81SSangharsh Agarwal		return false;
1855399fc81SSangharsh Agarwal	}
1865399fc81SSangharsh Agarwal
1875399fc81SSangharsh Agarwal	else
1885399fc81SSangharsh Agarwal		return false;
1895399fc81SSangharsh Agarwal}
1905399fc81SSangharsh Agarwal
1915399fc81SSangharsh Agarwalbool isWarmupvalcount(const lcb_server_stat_resp_t *resp)
1925399fc81SSangharsh Agarwal{
1935399fc81SSangharsh Agarwal
1945399fc81SSangharsh Agarwal	char* keystr = (char *) calloc(resp->v.v0.nkey, sizeof(char));
1955399fc81SSangharsh Agarwal	memcpy(keystr, resp->v.v0.key, resp->v.v0.nkey);
1965399fc81SSangharsh Agarwal	std::string key = std::string(keystr);
1975399fc81SSangharsh Agarwal	std::string keyref("ep_warmup_value_count");
1985399fc81SSangharsh Agarwal
1995399fc81SSangharsh Agarwal	if (key.compare(keyref) == 0)
2005399fc81SSangharsh Agarwal	{
2015399fc81SSangharsh Agarwal		return true;
2025399fc81SSangharsh Agarwal	}
2035399fc81SSangharsh Agarwal	else
2045399fc81SSangharsh Agarwal		return false;
2055399fc81SSangharsh Agarwal}
2065399fc81SSangharsh Agarwal
2075399fc81SSangharsh Agarwalbool isreplica_curr_items(const lcb_server_stat_resp_t *resp)
2085399fc81SSangharsh Agarwal{
2095399fc81SSangharsh Agarwal
2105399fc81SSangharsh Agarwal	char* keystr = (char *) calloc(resp->v.v0.nkey, sizeof(char));
2115399fc81SSangharsh Agarwal	memcpy(keystr, resp->v.v0.key, resp->v.v0.nkey);
2125399fc81SSangharsh Agarwal	std::string key = std::string(keystr);
2135399fc81SSangharsh Agarwal	std::string keyref("vb_replica_curr_items");
2145399fc81SSangharsh Agarwal
2155399fc81SSangharsh Agarwal	if (key.compare(keyref) == 0)
2165399fc81SSangharsh Agarwal	{
2175399fc81SSangharsh Agarwal		//char* valstr= (char *)calloc(resp->v.v0.nbytes,sizeof(char));
2185399fc81SSangharsh Agarwal		//memcpy(valstr,resp->v.v0.bytes,resp->v.v0.nbytes);
2195399fc81SSangharsh Agarwal		//std::string val = std::string(valstr);
2205399fc81SSangharsh Agarwal		//fprintf(stderr, "\n%s: %s",key.c_str(),val.c_str());
2215399fc81SSangharsh Agarwal		return true;
2225399fc81SSangharsh Agarwal	}
2235399fc81SSangharsh Agarwal	else
2245399fc81SSangharsh Agarwal		return false;
2255399fc81SSangharsh Agarwal}
2265399fc81SSangharsh Agarwal
2275399fc81SSangharsh Agarwalbool isactive_resident(const lcb_server_stat_resp_t *resp)
2285399fc81SSangharsh Agarwal{
2295399fc81SSangharsh Agarwal
2305399fc81SSangharsh Agarwal	char* keystr = (char *) calloc(resp->v.v0.nkey, sizeof(char));
2315399fc81SSangharsh Agarwal	memcpy(keystr, resp->v.v0.key, resp->v.v0.nkey);
2325399fc81SSangharsh Agarwal	std::string key = std::string(keystr);
2335399fc81SSangharsh Agarwal	std::string keyref("vb_active_perc_mem_resident");
2345399fc81SSangharsh Agarwal
2355399fc81SSangharsh Agarwal	if (key.compare(keyref) == 0)
2365399fc81SSangharsh Agarwal	{
2375399fc81SSangharsh Agarwal		return true;
2385399fc81SSangharsh Agarwal	}
2395399fc81SSangharsh Agarwal	else
2405399fc81SSangharsh Agarwal		return false;
2415399fc81SSangharsh Agarwal}
2425399fc81SSangharsh Agarwal
2435399fc81SSangharsh Agarwalbool isevicted_items(const lcb_server_stat_resp_t *resp)
2445399fc81SSangharsh Agarwal{
2455399fc81SSangharsh Agarwal
2465399fc81SSangharsh Agarwal	char* keystr = (char *) calloc(resp->v.v0.nkey, sizeof(char));
2475399fc81SSangharsh Agarwal	memcpy(keystr, resp->v.v0.key, resp->v.v0.nkey);
2485399fc81SSangharsh Agarwal	std::string key = std::string(keystr);
2495399fc81SSangharsh Agarwal	std::string keyref("ep_num_value_ejects");
2505399fc81SSangharsh Agarwal
2515399fc81SSangharsh Agarwal	if (key.compare(keyref) == 0)
2525399fc81SSangharsh Agarwal	{
2535399fc81SSangharsh Agarwal		return true;
2545399fc81SSangharsh Agarwal	}
2555399fc81SSangharsh Agarwal	else
2565399fc81SSangharsh Agarwal		return false;
2575399fc81SSangharsh Agarwal}
2585399fc81SSangharsh Agarwal
2595399fc81SSangharsh Agarwalstatic void stats_generic_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_server_stat_resp_t *resp)
2605399fc81SSangharsh Agarwal{
2615399fc81SSangharsh Agarwal	genericstats.refcount++;
2625399fc81SSangharsh Agarwal	if (error == LCB_SUCCESS)
2635399fc81SSangharsh Agarwal	{
2645399fc81SSangharsh Agarwal		if (resp->v.v0.nkey > 0)
2655399fc81SSangharsh Agarwal		{
2665399fc81SSangharsh Agarwal			std::string key;
2675399fc81SSangharsh Agarwal			key.assign((const char *) resp->v.v0.key, resp->v.v0.nkey);
2685399fc81SSangharsh Agarwal			std::string value;
2695399fc81SSangharsh Agarwal			value.assign((const char *) resp->v.v0.bytes, resp->v.v0.nbytes);
2705399fc81SSangharsh Agarwal			genericstats.statsvec.push_back(std::pair<std::string, std::string>(key, value));
2715399fc81SSangharsh Agarwal		}
2725399fc81SSangharsh Agarwal	}
2735399fc81SSangharsh Agarwal
2745399fc81SSangharsh Agarwal	else
2755399fc81SSangharsh Agarwal	{
2765399fc81SSangharsh Agarwal		fprintf(stderr, "GET ERROR: %s (0x%x)\n", lcb_strerror(instance, error), error);
2775399fc81SSangharsh Agarwal	}
2785399fc81SSangharsh Agarwal	(void) cookie;
2795399fc81SSangharsh Agarwal}
2805399fc81SSangharsh Agarwal
2815399fc81SSangharsh Agarwalstatic void stats_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_server_stat_resp_t *resp)
2825399fc81SSangharsh Agarwal{
2835399fc81SSangharsh Agarwal	if (error == LCB_SUCCESS)
2845399fc81SSangharsh Agarwal	{
2855399fc81SSangharsh Agarwal
2865399fc81SSangharsh Agarwal		//check if ep_warmup_state is done and mark bool variable warmupdone
2875399fc81SSangharsh Agarwal		if (isWarmupdone(resp))
2885399fc81SSangharsh Agarwal			warmupdone = true;
2895399fc81SSangharsh Agarwal
2905399fc81SSangharsh Agarwal		//read ep_warmup_value_count
2915399fc81SSangharsh Agarwal		if (isWarmupvalcount(resp))
2925399fc81SSangharsh Agarwal		{
2935399fc81SSangharsh Agarwal
2945399fc81SSangharsh Agarwal			if (warmupdone && !gotwm_val_cn)
2955399fc81SSangharsh Agarwal			{
2965399fc81SSangharsh Agarwal				wm_val_cn = (char *) calloc(resp->v.v0.nbytes, sizeof(char));
2975399fc81SSangharsh Agarwal				memcpy(wm_val_cn, resp->v.v0.bytes, resp->v.v0.nbytes);
2985399fc81SSangharsh Agarwal				gotwm_val_cn = true;
2995399fc81SSangharsh Agarwal				//*ep_warmup_value_count = atoi(num);
3005399fc81SSangharsh Agarwal				//fprintf(stderr, "\n%d\n",*ep_warmup_value_count);
3015399fc81SSangharsh Agarwal			}
3025399fc81SSangharsh Agarwal		}
3035399fc81SSangharsh Agarwal		if (isreplica_curr_items(resp))
3045399fc81SSangharsh Agarwal		{
3055399fc81SSangharsh Agarwal			if (!gotreplica_curr_items)
3065399fc81SSangharsh Agarwal			{
3075399fc81SSangharsh Agarwal				rep_val_cn = (char *) calloc(resp->v.v0.nbytes, sizeof(char));
3085399fc81SSangharsh Agarwal				memcpy(rep_val_cn, resp->v.v0.bytes, resp->v.v0.nbytes);
3095399fc81SSangharsh Agarwal				gotreplica_curr_items = true;
3105399fc81SSangharsh Agarwal			}
3115399fc81SSangharsh Agarwal		}
3125399fc81SSangharsh Agarwal		if (isactive_resident(resp))
3135399fc81SSangharsh Agarwal		{
3145399fc81SSangharsh Agarwal			if (!got_active_resident)
3155399fc81SSangharsh Agarwal			{
3165399fc81SSangharsh Agarwal				resident_val_cn = (char *) calloc(resp->v.v0.nbytes, sizeof(char));
3175399fc81SSangharsh Agarwal				memcpy(resident_val_cn, resp->v.v0.bytes, resp->v.v0.nbytes);
3185399fc81SSangharsh Agarwal				got_active_resident = true;
3195399fc81SSangharsh Agarwal			}
3205399fc81SSangharsh Agarwal		}
3215399fc81SSangharsh Agarwal		if (isevicted_items(resp))
3225399fc81SSangharsh Agarwal		{
3235399fc81SSangharsh Agarwal			if (!goteject_num_items)
3245399fc81SSangharsh Agarwal			{
3255399fc81SSangharsh Agarwal				ejected_val_cn = (char *) calloc(resp->v.v0.nbytes, sizeof(char));
3265399fc81SSangharsh Agarwal				memcpy(ejected_val_cn, resp->v.v0.bytes, resp->v.v0.nbytes);
3275399fc81SSangharsh Agarwal				goteject_num_items = true;
3285399fc81SSangharsh Agarwal			}
3295399fc81SSangharsh Agarwal		}
3305399fc81SSangharsh Agarwal	}
3315399fc81SSangharsh Agarwal	else
3325399fc81SSangharsh Agarwal	{
3335399fc81SSangharsh Agarwal		fprintf(stderr, "GET ERROR: %s (0x%x)\n", lcb_strerror(instance, error), error);
3345399fc81SSangharsh Agarwal	}
3355399fc81SSangharsh Agarwal	(void) cookie;
3365399fc81SSangharsh Agarwal}
3375399fc81SSangharsh Agarwal
3385399fc81SSangharsh Agarwalint callget(lcb_t* instance, const void* gkey, size_t gnkey)
3395399fc81SSangharsh Agarwal{
3405399fc81SSangharsh Agarwal	lcb_wait(*instance);
3415399fc81SSangharsh Agarwal	{
3425399fc81SSangharsh Agarwal		lcb_error_t err;
3435399fc81SSangharsh Agarwal		lcb_get_cmd_t cmd;
3445399fc81SSangharsh Agarwal		const lcb_get_cmd_t *commands[1];
3455399fc81SSangharsh Agarwal		commands[0] = &cmd;
3465399fc81SSangharsh Agarwal		memset(&cmd, 0, sizeof(cmd));
3475399fc81SSangharsh Agarwal		cmd.v.v0.key = gkey;
3485399fc81SSangharsh Agarwal		cmd.v.v0.nkey = gnkey;
3495399fc81SSangharsh Agarwal		err = lcb_get(*instance, NULL, 1, commands);
3505399fc81SSangharsh Agarwal		if (err != LCB_SUCCESS)
3515399fc81SSangharsh Agarwal		{
3525399fc81SSangharsh Agarwal			fprintf(stderr, "Failed to get: %s\n", lcb_strerror(NULL, err));
3535399fc81SSangharsh Agarwal			return 1;
3545399fc81SSangharsh Agarwal		}
3555399fc81SSangharsh Agarwal	}
3565399fc81SSangharsh Agarwal	lcb_wait(*instance);
3575399fc81SSangharsh Agarwal	//lcb_destroy(*instance);
3585399fc81SSangharsh Agarwal	return 0;
3595399fc81SSangharsh Agarwal}
360