Skip to content

Instantly share code, notes, and snippets.

@tilgovi
tilgovi / gist:841891
Created February 24, 2011 07:30
coffee-script, traits.js, and monads
coffee> [{List, Just}, fs] = [(require './lib/monad'), (require 'fs')]
[object Object]
coffee> files = (List ['src', 'lib']).bind ((dir) -> Just (fs.readdirSync dir))
[object Object]
coffee> files.log()
23 Feb 23:28:40 - [ [ 'monad.coffee~', 'list.coffee~', 'skuld.coffee~', 'skuld.coffee', 'monad.coffee' ],
[ 'skuld.js', 'monad.js' ] ]
[object Object]
@tilgovi
tilgovi / gist:824248
Created February 12, 2011 23:47
[CouchDB] Finding out what was replicated
You can do something like this:
@target host
GET /target => {... "update_seq": X, ...}
POST /_replicate {"source": "<source host>/source", "target": "target"} => {...}
GET /target/_changes?since=X => { //here are your replicated changes }
This last request to /target/_changes will also include any writes to the target database that occurred between the initial GET and /_replicate as well as any writes that occurred after the replication but before the /target/_changes request. If you can only make direct requests against the target database then it is impossible to guarantee an exact answer in the presence of concurrent updates to the target.
On the other hand, if you are performing a push replication from a local database or can otherwise afford to request changes from the source after the replication finishes, you can get exactly what you want even in the presence of concurrent updates to the source and/or the target using the response body from the replication request.
start_link(Name, Options0) ->
Options = case couch_config:get("httpd", "extra_opts") of
undefined -> Options0;
StrOpts ->
try
{ok, Tokens, _} = erl_scan:string(StrOpts),
{ok, Options1} = erl_parse:parse_term(Tokens),
Options0 ++ Options1
catch
_Err:Msg ->
#!/bin/sh
#
# couchdb This is the init script for starting up the CouchDB server
#
# chkconfig: - 26 74
# description: Starts and stops the CouchDB daemon that handles \
# all database requests.
### BEGIN INIT INFO
# Provides: couchdb
diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl
index 35bc80b..2980370 100644
--- a/src/couchdb/couch_view.erl
+++ b/src/couchdb/couch_view.erl
@@ -96,13 +96,19 @@ cleanup_index_files(Db) ->
FileList = list_index_files(Db),
- % regex that matches all ddocs
- RegExp = "("++ string:join(Sigs, "|") ++")",
diff --git a/src/couchdb/couch_btree.erl b/src/couchdb/couch_btree.erl
index 0e47bac..ce7c4e1 100644
--- a/src/couchdb/couch_btree.erl
+++ b/src/couchdb/couch_btree.erl
@@ -186,10 +186,15 @@ query_modify(Bt, LookupKeys, InsertValues, RemoveKeys) ->
less(Bt, A, B)
end
end,
- Actions = lists:sort(SortFun, lists:append([InsertActions, RemoveActions, FetchActions])),
- {ok, KeyPointers, QueryResults, Bt2} = modify_node(Bt, Root, Actions, []),
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index 19a4c16..6099d0a 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -439,15 +439,42 @@ refresh_validate_doc_funs(Db) ->
% rev tree functions
-flush_trees(_Db, [], AccFlushedTrees) ->
- {ok, lists:reverse(AccFlushedTrees)};
diff --git a/src/couchdb/couch_db.erl b/src/couchdb/couch_db.erl
index 7678f6c..df7c75b 100644
--- a/src/couchdb/couch_db.erl
+++ b/src/couchdb/couch_db.erl
@@ -645,7 +645,7 @@ update_docs(Db, Docs, Options, replicated_changes) ->
DocErrors = [],
DocBuckets3 = DocBuckets
end,
- DocBuckets4 = [[doc_flush_atts(check_dup_atts(Doc), Db#db.fd)
+ DocBuckets4 = [[check_dup_atts(Doc)
diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl
index 57b3008..301facb 100644
--- a/src/couchdb/couch_rep.erl
+++ b/src/couchdb/couch_rep.erl
@@ -648,7 +648,7 @@ do_checkpoint(State) ->
?LOG_INFO("recording a checkpoint for ~s -> ~s at source update_seq ~p",
[dbname(Source), dbname(Target), NewSeqNum]),
SessionId = couch_uuids:random(),
- NewHistoryEntry = {[
+ NewHistory = lists:sublist([{[
From becdc414824a787c267e608689bf4cfc8e608be2 Mon Sep 17 00:00:00 2001
From: Randall Leeds <randall.leeds@gmail.com>
Date: Thu, 12 Aug 2010 18:22:31 -0700
Subject: [PATCH] a reader queue makes couch_file fair to writers
---
src/couchdb/couch_db_updater.erl | 1 +
src/couchdb/couch_file.erl | 32 ++++++++++++++++++++++++++++++--
2 files changed, 31 insertions(+), 2 deletions(-)