Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

lay down cloudant build system.

  • Loading branch information...
commit bb9e2cef0c8f681dc38e09ee4e427649d89d1b44 1 parent 6d18638
@bradnoble bradnoble authored kocolosk committed
113 .gitignore
@@ -1,104 +1,19 @@
-# ./configure
+# building
-# for make
-# for make dev
-# for make check
-# for make cover
-# for rebar
+# testing
3  .rebar/templates/dev.template
@@ -0,0 +1,3 @@
+{variables, [{base_dir, "/opt/dbcore"}]}.
+{template, "./etc/default.ini", "rel/overlay/etc/default.ini"}.
+{file, "rebar-dev.config", "rebar.config"}.
123 .rebar/templates/etc/default.ini
@@ -0,0 +1,123 @@
+database_dir = {{data_dir}}
+view_index_dir = {{view_dir}}
+max_document_size = 67108864
+os_process_timeout = 5000
+max_dbs_open = 500
+max_view_index_lag = 9999999999
+delayed_commits = false
+port = 5984
+backlog = 512
+docroot = {{core_dir}}/var/share/www
+port = 5986
+bind_address =
+authentication_handlers = {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}
+default_handler = {couch_httpd_db, handle_request}
+WWW-Authenticate = Basic realm="Cloudant Private Database"
+backlog = 512
+secure_rewrites = true
+file = /dev/null
+level = info
+db = metrics_specs
+authentication_redirect = /_utils/session.html
+authentication_db = users
+secret = replace this with a real secret in your local.ini file
+require_valid_user = false
+timeout = 600 ; number of seconds before automatic logout
+auth_cache_size = 50 ; size is number of cache entries
+javascript = {{core_dir}}/bin/couchjs {{core_dir}}/var/share/server/main.js
+reduce_limit = true
+view_manager={couch_view, start_link, []}
+external_manager={couch_external_manager, start_link, []}
+query_servers={couch_query_servers, start_link, []}
+httpd={couch_httpd, start_link, []}
+stats_aggregator={couch_stats_aggregator, start, []}
+stats_collector={couch_stats_collector, start, []}
+uuids={couch_uuids, start, []}
+auth_cache={couch_auth_cache, start_link, []}
+/ = {couch_httpd_misc_handlers, handle_welcome_req, <<"Welcome">>}
+favicon.ico = {couch_httpd_misc_handlers, handle_favicon_req, "{{core_dir}}/var/share/www"}
+_utils = {couch_httpd_misc_handlers, handle_utils_dir_req, "{{core_dir}}/var/share/www"}
+_all_dbs = {couch_httpd_misc_handlers, handle_all_dbs_req}
+_active_tasks = {couch_httpd_misc_handlers, handle_task_status_req}
+_config = {couch_httpd_misc_handlers, handle_config_req}
+_replicate = {couch_httpd_misc_handlers, handle_replicate_req}
+_uuids = {couch_httpd_misc_handlers, handle_uuids_req}
+_restart = {couch_httpd_misc_handlers, handle_restart_req}
+_stats = {couch_httpd_stats_handlers, handle_stats_req}
+_log = {couch_httpd_misc_handlers, handle_log_req}
+_session = {couch_httpd_auth, handle_session_req}
+_oauth = {couch_httpd_oauth, handle_oauth_req}
+_user = {couch_httpd_auth, handle_user_req}
+_metrics = {couch_httpd_metrics_handlers, handle_metrics_req}
+_system = {chttpd_misc, handle_system_req}
+_cloudant = {showroom_httpd_admin, handle_cloudant_req}
+_membership = {membership_httpd, handle_membership_req}
+_view_cleanup = {couch_httpd_db, handle_view_cleanup_req}
+_compact = {couch_httpd_db, handle_compact_req}
+_design = {couch_httpd_db, handle_design_req}
+_temp_view = {couch_httpd_view, handle_temp_view_req}
+_changes = {couch_httpd_db, handle_changes_req}
+_search = {couch_httpd_external, handle_external_req, <<"search">>}
+_view = {couch_httpd_view, handle_view_req}
+_show = {couch_httpd_show, handle_doc_show_req}
+_list = {couch_httpd_show, handle_view_list_req}
+_info = {couch_httpd_db, handle_design_info_req}
+_rewrite = {couch_httpd_rewrite, handle_rewrite_req}
+_update = {couch_httpd_show, handle_doc_update_req}
+; Known algorithms:
+; random - 128 bits of random awesome
+; All awesome, all the time.
+; sequential - monotonically increasing ids with random increments
+; First 26 hex characters are random. Last 6 increment in
+; random amounts until an overflow occurs. On overflow, the
+; random prefix is regenerated and the process starts over.
+; utc_random - Time since Jan 1, 1970 UTC with microseconds
+; First 14 characters are the time in hex. Last 18 are random.
+algorithm = sequential
+; rate is in milliseconds
+rate = 1000
+; sample intervals are in seconds
+samples = [0, 60, 300, 900]
+compression_level = 8 ; from 1 (lowest, fastest) to 9 (highest, slowest), 0 to disable compression
+compressible_types = text/*, application/javascript, application/json, application/xml
+max_http_sessions = 10
+max_http_pipeline_size = 10
5 .rebar/templates/make.template
@@ -0,0 +1,5 @@
+{variables, [{prefix, "/opt"},
+ {data, "/srv/db"},
+ {view, "/srv/view_index"},
+ {user, "dbcore"}]}.
+{template, "./Makefile", "Makefile"}.
8 .rebar/templates/production.template
@@ -0,0 +1,8 @@
+{variables, [{prefix, "{{prefix}}"},
+ {core_dir, "{{prefix}}/dbcore"},
+ {data_dir, "/srv/db"},
+ {view_dir, "/srv/view_index"}]}.
+{template, "./etc/default.ini", "rel/overlay/etc/default.ini"}.
+{file, "rebar.config", "rebar.config"}.
+{file, "/usr/local/lib/erlang/lib/erl_interface-3.6.5/bin/erl_call", "rel/overlay/erts-vsn/bin/erl_call"}.
+{chmod, 8#755, "rel/overlay/erts-vsn/bin/erl_call"}.
14 .rebar/templates/rebar-dev.config
@@ -0,0 +1,14 @@
+{sub_dirs, [
+ "apps/chttpd",
+ "apps/couch",
+ "apps/etap",
+ "apps/fabric",
+ "apps/ibrowse",
+ "apps/mem3",
+ "apps/mochiweb",
+ "apps/oauth",
+ "apps/rexi",
+ "apps/showroom",
+ "rel"
+{erl_opts, [debug_info]}.
15 .rebar/templates/rebar.config
@@ -0,0 +1,15 @@
+{sub_dirs, [
+ "apps/chttpd",
+ "apps/couch",
+ "apps/etap",
+ "apps/fabric",
+ "apps/ibrowse",
+ "apps/mem3",
+ "apps/mochiweb",
+ "apps/oauth",
+ "apps/rexi",
+ "apps/showroom",
+ "rel"
+{cover_enabled, true}.
+{erl_opts, [debug_info, fail_on_warning]}.
@@ -0,0 +1,33 @@
+1. Getting Started
+Cloudant-core uses a rebar-based build system. Custom build paths and the like
+are available using templates. If you want to customize those templates, run
+the `bootstrap` command to install the defaults into ~/.rebar and go from there.
+This step is optional.
+2. Dependencies
+ * Erlang R13B03 or higher
+ * ICU (4.2 is preferable)
+ * Spidermonkey (1.9.2 preferable, [][6]) and symlink /usr/lib/ to /usr/lib/ to make things easier
+ * OpenSSL
+ * make
+On OS X the Erlang and ICU dependencies are easily satisfied by Homebrew:
+ brew install erlang icu4c
+ brew ln icu4c
+Once the dependencies are installed you can use `make` to build the code,
+`make check` to run unit tests, and `make clean` to reset.
+3. Release Generation
+The `make dist` command will build a standard release in `rel/dbcore`. The
+release includes a start script at `rel/dbcore/bin/dbcore`
+4. Caveats
+The build system really really wants the couch .ini files to be in
+`/opt/dbcore/etc`, and the data files to be in `/srv`. It wouldn't be too
+difficult to template this. But for now, the recommended installation is to move the rel/dbcore folder to /opt/
@@ -0,0 +1,178 @@
+ Apache License
+ Version 2.0, January 2004
+ 1. Definitions.
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ implied, including, without limitation, any warranties or conditions
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
@@ -0,0 +1,108 @@
+## cloudant-dbcore
+### Overview
+Cloudant-dbcore is a highly available, fault-tolerant, clustered, fully api-compliant version of [Apache CouchDB][1]. While it appears to the end-user as one CouchDB instance, it is in fact one or more nodes in an elastic cluster, acting in concert to store and retrieve documents, index and serve views, and serve CouchApps. Dbcore has been developed and is continually maintained by [Cloudant][2] who offer hosted CouchDB as a service.
+Clusters behave according to concepts outlined in [Amazon's Dynamo paper][4], namely that each node can accept requests, data is placed on partitions based on a consistent hashing algorithm, and quorum protocols are for read/write operations.
+### Contents
+ * this file
+ * INSTALL instructions on how to install dbcore
+ * LICENSE open-source license governing dbcore
+### Getting Started
+For detailed installation instructions, please consult the INSTALL file
+#### Prerequisites
+ * Erlang R13B03 or higher
+ * ICU (4.2 is preferable)
+ * Spidermonkey (1.9.2 preferable, [][6]) and symlink /usr/lib/ to /usr/lib/ to make things easier
+ * OpenSSL
+ * make
+#### Building and installing dbcore
+`$CLOUDANT_SRC` is the directory holding your downloaded source files, while `$CLOUDANT_PREFIX` is the prefix to which the software is installed (defaults to `/opt`):
+ $ ./configure -p $CLOUDANT_PREFIX
+ $ make
+ $ sudo make install
+#### Starting dbcore
+ $ $CLOUDANT_PREFIX/dbcore/bin/dbcore
+Now, visit http://localhost:5984/_utils in a browser to verify the CouchDB node is operational.
+Note: see the rel/sv/README file for information on using runit to stop/start dbcore.
+#### Joining a new node to the cluster
+First, dbcore listens on two ports. Defaults and explanations:
+ * 5984 - front door, cluster-aware port, appears as a standalone CouchDB.
+ * 5986 - back door, single-node port, used for admin functions
+Next, once the first node is started, and assuming its hostname is 'node1_host' start dbcore on another node, with hostname 'node2_host'. Once it's started successfully, on node1_host, join the new node:
+ $ curl -X PUT http://localhost:5986/nodes/dbcore@node2_host -d {}
+To verify the two-node cluster has been linked properly, on either node, try:
+ $ curl http://locahost:5984/_membership
+You should see something similar to this:
+ {"all_nodes":["dbcore@node1_host","dbcore@node2_host"],"cluster_nodes":["dbcore@node1_host","dbcore@node2_host"]}
+#### Now What?
+If the above steps were successful, you should have a running dbcore cluster that looks just like a standalone CouchDB. You may interact with it the same way you would a standalone CouchDB, via the HTTP REST interface.
+Because every node can handle requests equally, you may want to put a load balancer in front of the cluster and set up a round-robin strategy for distributing incoming requests across all of your cluster's nodes.
+##### Create a database:
+ curl -X PUT http://loadbalancer:5984/test_db
+Also note that 'q' and 'n' are query string arguments that may be specified. These are Cloudant-specific options, and their values and defaults are discussed in the Configuration section below. Ex: &q=12 or &n=4.
+##### Create a document:
+ curl -X PUT http://loadbalancer:5984/test_db/doc_1 -d '{"a":1,"b":2}'
+You may also provide 'r' and 'w' on the GET and PUT/POST document operations respectively. Their values and defaults are discussed in the Configuration section below. Ex: &r=3 for high consistency reads, or &w=1 for higher throughput writes.
+##### Check out Futon, CouchDB's web UI:
+ * [http://loadbalancer:5984/_utils][5]
+### Configuration
+#### Cluster constants
+_Q_ - number of partitions per database. Q is specified in the default.ini file, but may be provided as a URL parameter when creating a database. Default value is 8, query parameter is &q=12 or similar.
+_N_ - replication constant. N defaults to 3, but can vary by database just as Q can vary. N copies of each document will be written to the data store, on N different nodes.
+_R_ - read quorum constant. N writes have occurred for each document, as noted above. When reads are requested, N reads are sent to the N nodes that store the particular document. The system will return to the requesting client with the document when R successful reads have returned, and agree on versioning. R defaults to 2. Lower R values often result in faster reads at the expense of consistency. Higher R values usually result in slower reads, but more consistent, or agreed-upon data values returning.
+_W_ - write quorum constant. When writing the N copies, the data store will respond to the write client after W successful writes have completed. The remaining N-W writes are still being attempted in the background, but the client receives a 201 Created status and can resume execution. W defaults to 2. Lower W values mean more write throughput, and higher W values mean more data durability.
+### Contact
+Cloudant folks are usually hanging out in IRC. Freenode, channel #cloudant. We may also be reached:
+ * [][2]
+ * [][3]
+[5]: http://loadbalancer:5984/_utils
10 apps/chttpd/Makefile
@@ -1,10 +0,0 @@
-all: compile
- @./rebar compile
- @./rebar clean
- @./rebar compile erl_opts=native
BIN  apps/chttpd/rebar
Binary file not shown
5 bootstrap
@@ -0,0 +1,5 @@
+# copy templates into place
+echo "copying default rebar templates to ~/.rebar"
+cp -R .rebar ~/
51 configure
@@ -0,0 +1,51 @@
+function quit {
+ exit
+while [ $# -gt 0 ]
+ case $1
+ in
+ -p)
+ shift 2
+ ;;
+ -t)
+ shift 2
+ ;;
+ -d)
+ DATA=$2
+ shift 2
+ ;;
+ -v)
+ VIEW=$2
+ shift 2
+ ;;
+ -u)
+ shift 2
+ ;;
+ *)
+ echo "usage: $0 [-p {prefix} -t {template} -d {data_dir} -v {view_dir} -u {user}]"
+ quit
+ ;;
+ esac
+echo "configuring dbcore"
+rm -f rebar.config
+# Makefile
+./rebar create template=make prefix=$PREFIX data=$DATA view=$VIEW user=$DBCORE_USER force=1
+# dbcore template
+./rebar create template=$TEMPLATE prefix=$PREFIX force=1
Please sign in to comment.
Something went wrong with that request. Please try again.