Checking the logs revealed that on of them had problems in the index.
Reindexing for most of our databases takes a few minutes, however one of them has about 5 million documents in it, and this takes a good 12 hours to re-index completely.
So to re-index a CouchDB database, take 4 steps:
1. Take it offline - move the work to another one in the cluster
2. Delete the current indexes - they're in a sub-directory of the CouchDB data directory, preceded by a . , named after the database and has _design appended. Renaming is another option for the faint hearted
3. Restart Couchdb, so it notices that the indexes have gone
4. Access one view for each design document - you only need to do one, since it will index against all the views at once.
I've done a script which automate step 4. One of the issues with CouchDB replication is that a replicated document doesn't update the view (unlike a directly saved document), so I've a script which pokes each view every minute or so to stop any staleness building up. We use couchrest model, so it uses those classes to do the accessing. This means the script is a little specific to us, so I hope you'll get the idea
#!/usr/bin/env ruby
# poke all the classes in the database
require 'couchrest'
require 'couchrest_model'
require 'will_paginate'
require 'will_paginate_couchrest'
SERVER = CouchRest.new("http://localhost:5984")
DB = SERVER.database!("databasename")
require '/opt/local/apps/couchrestclasses.rb'
while true do
puts "waking .... Starting CouchrestClass"# repeat the above once for each couchrest class
begin
blah=CouchrestClass.all(:limit => 10)
rescue
puts "CouchrestClass Done"
end
puts "done... sleeping"
sleep 20
end