Skip to content

Instantly share code, notes, and snippets.

@fdmanana
fdmanana / gist:832610
Created February 17, 2011 20:27
The CouchDB replicator database

1. Introduction to the replicator database

A database where you PUT/POST documents to trigger replications and you DELETE to cancel ongoing replications. These documents have exactly the same content as the JSON objects we used to POST to /_replicate/ (fields "source", "target", "create_target", "continuous", "doc_ids", "filter", "query_params".

Replication documents can have a user defined "_id". Design documents (and _local documents) added to the replicator database are ignored.

The default name of this database is _replicator. The name can be changed in the .ini configuration, section [replicator], parameter db.

2. Basics

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index da41a0c371bc..1e77371035ac 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1846,6 +1846,29 @@ static ssize_t check_direct_IO(struct btrfs_fs_info *fs_info,
return 0;
}
+static size_t dio_fault_in_size(const struct iov_iter *iov, size_t prev_left)
+{
@fdmanana
fdmanana / gist:1199903
Created September 7, 2011 06:21
Erlang OTP R14B, Mac OS X Lion 64bits and XCode 4.1

Issue

On Mac OS X Lion (64bits at least), we get random "Bus error 10" (or "Segmentation fault: 11") crashes if init:restart/0 is called and the crypto application is loaded. Why? XCode 4.1 ships an OpenSSL version that deprecates many functions used by OTP's crypto NIF (lib/crypto/c_src/crypto.c).

Example:

$ erl
From b3895efe1cff61182dfe76fed25c00d6cb590a71 Mon Sep 17 00:00:00 2001
From: Filipe David Borba Manana <fdmanana@apache.org>
Date: Wed, 16 Jan 2013 10:18:36 +0000
Subject: [PATCH] Fix memory leak in efile_drv
When the port's stop callback (file_stop) is invoked, we
schedule a file close task (FILE_CLOSE_ON_PORT_EXIT) that
will be picked up by an async thread, to avoid blocking the
scheduler thread for too long. However, because after this
task is executed the port is not alive anymore, its callback
@fdmanana
fdmanana / gist:2160061
Created March 22, 2012 17:17
OS X 64bits release target
From 0a8c3023b5c29463b58d09fc574c5f8f3bd36b99 Mon Sep 17 00:00:00 2001
From: Filipe David Borba Manana <fdmanana@gmail.com>
Date: Fri, 23 Mar 2012 13:48:15 +0000
Subject: [PATCH] Add support for Mac OS X 64bit builds with GYP
Note that in order to build for 64bits mode, you'll have
to specify the target architecture explicitely, the default
is still 32bits for Mac OS X.
Example with make:
Before COUCHDB-1186
fdmanana 23:21:05 ~/git/hub/slow_couchdb (master)> docs=500000 batch=5000 ./bench.sh wow.tpl
Server: CouchDB/1.2.0a-a68a792-git (Erlang OTP/R14B03)
{"couchdb":"Welcome","version":"1.2.0a-a68a792-git"}
[INFO] Created DB named `db1'
[INFO] Uploaded 5000 documents via _bulk_docs
(....)
[INFO] Uploaded 5000 documents via _bulk_docs
# comment lines start with a sharp (#)
{
"type": "#{pick(human,orc,elf,dwarf)}",
"category": "#{pick(warrior,assassin,thief,wizard)}",
"ratio": #{random_int(0, 1)}.#{random_int(0, 9)},
"level": #{random_int(1, 20)},
"data1": "#{random_string(40)}",
"data2": "#{random_string(50)}",
"data3": "#{random_string(35)}",
@fdmanana
fdmanana / gist:1343454
Created November 6, 2011 20:47
Erlang/OTP gen_server simplified API, basics

Client side API

Start a gen_server programmatically

gen_server:start(ModuleName, Arguments, Options) -> {ok, Pid} | {error, Reason}

gen_server:start(ServerName, ModuleName, Arguments, Options) -> {ok, Pid} | {error, Reason}

@fdmanana
fdmanana / user_default.erl
Created August 24, 2011 17:56 — forked from dustin/user_default.erl
Helpful stuff for figuring out what's going on in there...
-module(user_default).
-export([proc_count/1, proc_count/0,
proc_mem/2, proc_mem/1, proc_mem/0,
matching/2, matching/1]).
proc_info(X, Info) ->
case proplists:get_value(X, Info) of
{proc_lib, init_p, _} ->
@fdmanana
fdmanana / gist:1092157
Created July 19, 2011 12:37
Erlang skew data structure (priority queue for functional languages)
-module(skew).
-export([new/0, size/1, in/3, out/2, min/1]).
-define(null, []).
new() ->
?null.
size(?null) ->