Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 1.8.x

Lose data when testing with multiple thread

1 reply [Last post]
  • Login or register to post comments
Thu, 04/19/2012 - 19:47
godsky
Offline
Joined: 04/19/2012
Groups: None

I have setup a cluster with 1 master and 2 slaves. and wrote a sample running on fourth computer to send the key/value to master. this sample runs two threads for writing 10000 records to master simulately. the key for one thread is from '0key0' to '0key9999', for another thread is from '1key0' to '1key9999'. when the test finished, I read the data which two threads wrote with one thread and found some data lost:
1. some key is duplicate.
2. key is correct but value is null
3. key non exists, means this key value not written.

following is the test code, any problems exists? please help me !!!

Compile common is : gcc main.c -lcouchbase -pthread -w -o main
Run common is : ./main 0 10000
after finished,there is only 18224 item in the cluster.

mainThread:
void *myThread(int id)
{
int i,mynum,mytotalnum;
mynum = num;
mytotalnum = totalnum;
i = mynum;
libcouchbase_t instance; /* our libcouchbase instance */
libcouchbase_error_t oprc; /* for checking various responses */
instance = libcouchbase_create(host, username,
passwd, bucket, NULL);
if (instance == NULL) {
fprintf(stderr, "Failed to create libcouchbase instance\n");
return 1;
}
if (libcouchbase_connect(instance) != LIBCOUCHBASE_SUCCESS) {
fprintf(stderr, "Failed to connect libcouchbase instance to server\n");
return 1;
}
libcouchbase_wait(instance);
memset(doc,'-',sizeof(doc));
for(;i

Top
  • Login or register to post comments
Thu, 04/19/2012 - 19:58
godsky
Offline
Joined: 04/19/2012
Groups: None

{
sprintf(key,"%dkey%d\0",id,i);
printf("key=%s\n",key);
/* Store doc to in the system */
oprc = libcouchbase_store(instance,NULL,LIBCOUCHBASE_SET,key, /* the key or _id of the document */strlen(key), /* the key length */doc,strlen(doc), /* length of */0, /* flags, */0, /* expiration */0); /* and CAS values, see API reference */

if (oprc != LIBCOUCHBASE_SUCCESS) {
printf("Failed to create hello store operation.\n");
return 1;
}
/* Wait for the operation to compelete */
libcouchbase_wait(instance);
oprc = libcouchbase_get_last_error(instance);
if (oprc == LIBCOUCHBASE_SUCCESS) {
// printf("key=%s\n",key);
} else {
printf("Could not set hello. Error received is %d\n", oprc);
printf("server---i:%d\n",i);
return 1;
}
}

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker