#271 CACHEDB_COUCHBASE - Error reporting and reconnects

modules (179)

This patch updates the CACHEDB_COUCHBASE module. It adds better error reporting and handling as well as automatic reconnects for certain error codes.

Removed calls to lcb_get_last_error. Since we have callbacks set this is unnecessary and we can go off the last_error variable.
Moved error log messages to the callback only, to reduce noise in the logs. (Perhaps debug messages would be appropriate in the get, set, remove, and arithmetic methods?)

Return codes:
For both the get and remove methods I have made changes so that Non-existent keys return -1 and all other failures return -2. Since couchbase can be used as a primary data-store it is
very important to distinguish between no data and other failures at the script level, as the data may not be available elsewhere. This involved a change to the cachedb_fetch(), cachedb_counter_fetch(), and cachedb_remove() methods in cachedb.c to pass through the return code of the underlying drivers method. Compatibility with the other cachedb_* modules should be verified.

The libcouchbase library does a pretty good job of handling reconnects itself, there are however a few scenarios where it will get into a state where it will not reconnect. When one of these errors are detected we created a new handle and destroy the old one. This list of errors may need review.

Because of this we also support starting opensips without successfully connecting to couchbase, and are able to connect to it later once the service becomes available. We will still fail to start on certain connection errors that are deemed fatal. Again this list of errors may need review.


I updated the documentation to include an example of multiple hosts in the connection string. I have tested the following works:
modparam("cachedb_couchbase", "cachedb_url","couchbase:test://;")

If is not available it will still connect to the cluster via

I wrote this patch against 1.9, but I think it should apply against trunk just fine. It would be nice if this could be applied to 1.9 as well, however the changes for return codes may pose an issue there.

Happy to answer any questions!


  • Ryan Bullock

    Ryan Bullock - 2013-04-19

    Couchbase - improved errors, reconnect support and more

  • Vladut-Stefan Paiu

    Hi Ryan,

    Thanks for the patch.

    I have committed the cachedb_couchbase part of it on trunk and 1.9 as well .
    I've left out the propagation of the return code to script, since that could have broken some other cachedb_* modules. I'll go through each of the modules that use the interface, and make sure all modules respect the return codes convention.

    Thanks again for the patch.

    Best Regards,

  • Vladut-Stefan Paiu

    • assigned_to: nobody --> vladut-paiu
    • status: open --> closed-accepted

Log in to post a comment.