summaryrefslogtreecommitdiff
path: root/provider_base
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-08-22 02:20:13 -0700
committerelijah <elijah@riseup.net>2014-08-26 11:17:43 -0700
commita54b82ff7cdae2e44bc3c159473ca03e283f0746 (patch)
tree6258adc1fbef953042b2b3c00b00cb462cf6b1a0 /provider_base
parent3b93372bd9cc98f87e21b15308ef5079c2e18983 (diff)
default to multimaster if no nodes are defined as master
Diffstat (limited to 'provider_base')
-rw-r--r--provider_base/services/couchdb.rb62
1 files changed, 52 insertions, 10 deletions
diff --git a/provider_base/services/couchdb.rb b/provider_base/services/couchdb.rb
index 81f366e1..3bee3a67 100644
--- a/provider_base/services/couchdb.rb
+++ b/provider_base/services/couchdb.rb
@@ -1,18 +1,60 @@
+#######################################################################
+###
+### NOTE!
+###
+### Currently, mirrors do not work! The only thing that works is all
+### nodes multimaster or a single master.
+###
+#######################################################################
#
# custom logic for couchdb json resolution
+# ============================================
+#
+# There are three modes for a node:
+#
+# Multimaster
+# -----------
+#
+# Multimaster uses bigcouch (soon to use couchdb in replication mode
+# similar to bigcouch).
+#
+# Use "multimaster" mode when:
+#
+# * multiple nodes are marked couch.master
+# * OR no nodes are marked couch.master
+#
+# Master
+# ------
+#
+# Master uses plain couchdb that is readable and writable.
+#
+# Use "master" mode when:
+#
+# * Exactly one node, this one, is marked as master.
+#
+# Mirror
+# ------
+#
+# Mirror creates a read-only copy of the database. It uses plain coucdhb
+# with legacy couchdb replication (http based).
+#
+# This does not currently work, because http replication can't handle
+# the number of user databases.
+#
+# Use "mirror" mode when:
+#
+# * some nodes are marked couch.master
+# * AND this node is not a master
#
-unless nodes_like_me['services' => 'couchdb']['couch.master' => true].any?
- error('there must be at least one node with couch.master set to `true` for environment `%s`.' % @node.environment)
-end
+master_count = nodes_like_me['services' => 'couchdb']['couch.master' => true].size
-if couch.master
- if nodes_like_me['services' => 'couchdb']['couch.master' => true].size > 1
- apply_partial 'services/_couchdb_multimaster.json'
- else
- apply_partial 'services/_couchdb_master.json'
- end
+if master_count == 0
+ apply_partial 'services/_couchdb_multimaster.json'
+elsif couch.master && master_count > 1
+ apply_partial 'services/_couchdb_multimaster.json'
+elsif couch.master && master_count == 1
+ apply_partial 'services/_couchdb_master.json'
else
apply_partial 'services/_couchdb_mirror.json'
end
-