diff options
-rw-r--r-- | vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb index df859f3ef..fae31475c 100644 --- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb +++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb @@ -599,24 +599,36 @@ module ActsAsXapian raise "found existing " + new_path + " which is not Xapian flint database, please delete for me" if not File.exist?(File.join(new_path, "iamflint")) FileUtils.rm_r(new_path) end - ActsAsXapian.writable_init(".new") # Index everything batch_size = 1000 for model_class in model_classes - model_class.transaction do 0.step(model_class.count, batch_size) do |i| - STDOUT.puts("ActsAsXapian: New batch. From #{i} to #{i + batch_size}") if verbose - models = model_class.find(:all, :limit => batch_size, :offset => i, :order => :id) - for model in models - STDOUT.puts("ActsAsXapian.rebuild_index #{model_class} #{model.id}") if verbose - model.xapian_index + # We fork here, so each batch is run in a different process. This is + # because otherwise we get a memory "leak" and you can't rebuild very + # large databases (however long you have!) + pid = Process.fork # XXX this will only work on Unix, tough + if pid + Process.waitpid(pid) + if not $?.success? + raise "batch fork child failed, exiting also" + end + ActiveRecord::Base.connection.reconnect! + else + ActsAsXapian.writable_init(".new") + STDOUT.puts("ActsAsXapian: New batch. #{model_class.to_s} from #{i} to #{i + batch_size} pid #{Process.pid.to_s}") if verbose + models = model_class.find(:all, :limit => batch_size, :offset => i, :order => :id) + for model in models + STDOUT.puts("ActsAsXapian.rebuild_index #{model_class} #{model.id}") if verbose + model.xapian_index + end + ActsAsXapian.writable_db.flush + ActiveRecord::Base.connection.disconnect! + Kernel.exit! 0 end + end - end end - - ActsAsXapian.writable_db.flush # Rename into place old_path = ActsAsXapian.db_path |