Skip to content
Benoit Chesneau edited this page Jun 25, 2013 · 7 revisions

In Rcouch the source code base of Apache CouchDB has been significantly refactored to allows more customization of the distribution and improve the statbility. Rcouch is successfuly used by many customers of Enki Multimedia.

couch_core and rcouch

One of the goal of rcouch is to provide an embedable version of Apache CouchDB in Erlang OTP Applications. To allows it couchdb has been splitted in 2 parts:

  • couch_core, the couchdb core it provides the modules to handle databases, the HTTP, the M/R view enginge and the default couchdb replicator.
  • rcouch, which provides not only the files needed to build a full release of rcouch but also the files to create Debian, RPMs, solaris PKG and macosx DMG packages.

Both sources code repositories are built using rebar, an Erlang build tool that makes it easy to compile and test Erlang applications, port drivers and releases.

In rcouch only a makefile (bsd or gnu makefile) is needed to build a release, and autotools are only used in dependencies (ICU and Spidermonkey)

couch_core

The couch_core directory looks like this one:

.
├── apps
│   ├── couch
│   ├── couch_changes
│   ├── couch_httpd
│   ├── couch_index
│   ├── couch_mrview
│   ├── couch_replicator
│   └── couch_stats
├── ebin
│   └── couch_core.app
├── example
│   └── rel
├── LICENSE
├── Makefile
├── NOTICE
├── README.md
├── rebar.config
├── rebar_dev.config
└── test
    ├── couch_dev.config
    ├── files
    └── reltool.config

Compared to Apache CouchDB you can notice that main applications have been moved to the apps/ folder to follow a common pattern in Erlang world.

Also couchdb has been remaned to couch like it should be.

couch_core have the following dependencies:

couch_core applications in detail:

couch

The supervision tree has been changed:

  • applications and main servers are now launched by the release or the supervisor trees and aren't set any more in the ini file.
  • couch is now a real OTP application that can be started via your own Erlang application as a result that the boot is significantly cleaner than the one you have in Apache CouchDB and process are really supervised.

couch_httpd

The module modules handling the HTTP API have been extracted and put in their own Erlang applications. The couch_httpd application is started by the release and have its own supervision tree.

couch_httpd can be gracefully restarted without stopping the connections. In apache couchdb the only way to restart the HTTP module is to crash it (exit).

the couch_httpd module also replace the mochiweb acceptor loop by its own and is using ranch for that. This changes has been done to improve the reliability of the HTTP layer under the load resulting in less FDs leaks and a better supervision of the processes.

  • The module vhost has been improved to make sure it is correctly started or restarted when the configuration changes

couch_changes

The modules couch_changes has been extracted from couchdb to be eventually replaced and have also been refactored to make the HTTP part more readable. It has also the need source code changes to handle the [View Changes(View-Changes)

couch_stats

The module couch_stats has been extracted to allow the vendors to customize or replace it.

couch_index

couch_index has the following difference from Apache Couchdb :

  • A full applications with its own supervisor distinct from the couch application
  • changes needed for the include_deleted options and View Changes have been added

couch_mrview

Like the Apache CouchDB modules with the needed changes for the View Changes detailed in the hacking documentation.

couch_replicator

Changes from couchdb are:

  • A full applications with its own supervisor distinct from the couch application
  • changes needed for the View Changes have been added
  • many fixes

rcouch

rcouch allows you to build a fulll [Erlang release (http://www.erlang.org/doc/design_principles/release_structure.html) using rebar:

├── CHANGES
├── docs
│   ├── CNAME
│   ├── ghp-import
│   ├── make.bat
│   ├── Makefile
│   ├── site
│   ├── source
│   ├── sphinxtogithub.py
│   └── sphinxtogithub.pyc
├── ebin
│   └── rcouch.app
├── LICENSE
├── Makefile
├── NOTICE
├── pkg.vars.config
├── README.md
├── rebar
├── rebar.config
├── rel
│   ├── files
│   ├── rcouch.config
│   └── reltool.config
└── src
    └── etop_txt.erl

It also allows you to generate the documentation.

Third party applicatios are added to the release by editing the reltool.config file. main settings can be changed in the rcouch.config file.

If you observe the files directory in the rel folder, you can also observe that there is no more default.ini. The main configuration has been put in the couch.ini file and all the HTTP config in couch_httpd.ini files. The configuration settings can still be overiden using the local.ini file. This changes allows you to embed couchdb without launching the HTTP api or simply replace it eventually. Each modules can also have optionnaly their own ini file.

├── rel
│   ├── files
│   │   ├── app.config
│   │   ├── couch_httpd.ini
│   │   ├── couch.ini
│   │   ├── empty
│   │   ├── erica
│   │   ├── erica_exec
│   │   ├── local.ini
│   │   ├── refuge_logo.png
│   │   └── vm.args
│   ├── rcouch.config
│   └── reltool.config

rcouch ship the couch_core with the following extensions:

  • couch random doc handler
  • couch db updates handler
  • refuge spatial - spatial indexer forked from geocouch
  • erica: a console tools to help you to manage and build your couchapps

rcouch also allows you to build your own packages files.