C++ Force Replication Between Clusters.
Thu, 01/31/2013 - 20:58
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);
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