Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | SDKs | SDKs

C++ Force Replication Between Clusters.

1 reply [Last post]
  • Login or register to post comments
Thu, 01/31/2013 - 20:58
simy307
Offline
Joined: 01/12/2013
Groups: None

I am using Couchbase 2.0 and C++.

In my program I am currently adding an item to couchbase using the lcb_store_cmd_st command. The one document I am setting is updated correctly. However, it takes a very long time for the item to be replicated across clusters to the main Couchbase node. Is there a function or a setting I can use to make the replication persistent and force the replication to happen on update?

Code:

    create_options.v.v0.host ="127.0.0.1:8091";
    create_options.v.v0.user = "username";
    create_options.v.v0.passwd = "password";
    create_options.v.v0.bucket  = "bucket";
    err = lcb_create(&instance, &create_options);
 
    if (err != LCB_SUCCESS) {
        qDebug("Failed to create libcouchbase instance");
    }
 
    if ((err = lcb_connect(instance)) != LCB_SUCCESS) {
        qDebug("Failed to initiate connect");
    }
    lcb_wait(instance);
    QDateTime datetime; datetime = datetime.currentDateTime();
    uint iStamp =datetime.toUTC().toTime_t();
    QString stamp; stamp.setNum(iStamp);
    QString tj = "{\"doc_type\": \"test\", \"update_time\": \""+stamp+"\"}";
    string json = tj.toStdString();
    string key;
    lcb_store_cmd_st *store = static_cast<lcb_store_cmd_st *>(calloc(1, sizeof(*store)));
    QString kt = QString("encoder_church_"+ churchID);
    key = kt.toStdString();
    store->v.v0.bytes = json.c_str();
    store->v.v0.nbytes = json.size();
    store->v.v0.key =  key.c_str();
    store->v.v0.nkey = key.size();
    store->v.v0.cas = 0x000;
    store->v.v0.operation = LCB_SET;
    lcb_store_cmd_st* commands[] = { store };
    err = lcb_store(instance, NULL, 1, commands);
    if (err != LCB_SUCCESS) {
        qDebug("Failed to set");
    }
    lcb_wait(instance);
    lcb_flush_buffers(instance,NULL);
    lcb_wait(instance);
    lcb_destroy(instance);

Top
  • Login or register to post comments
Mon, 02/04/2013 - 05:03
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello,

First of all, I am not a C developer, so I will answer in a generic way and give your some pointers.

You cannot "force" the replication, what you can do in the SDKs is to check the "Durability" so you will observe or be called back when the document is persisted and/or replicated to one or more nodes in the cluster.

Like that you can control in your application the fact that the document is "durable" and "replicated".

Take a look to the following chapters:
- http://www.couchbase.com/docs/couchbase-devguide-2.0/couchbase-sdk-when-...
- http://www.couchbase.com/docs/couchbase-devguide-2.0/couchbase-sdk-imple...

I am contacting the C experts to have them adding information to this post.

Regards

__________________

Tug
@tgrall

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