Skip to content

Instantly share code, notes, and snippets.

@coffeemug
coffeemug / gist:2658017
Created May 11, 2012 06:55
Ubuntu 12.04 ext4 ftruncate deadlock
/* This program demonstrates a bug in the Linux kernel version 3.2.0 using the
`ext4` filesystem.
Steps to compile:
$ gcc -o demo demo.c -laio
Steps to reproduce:
1. Run `./demo FILE`, where `FILE` is the path where the program will put the
@coffeemug
coffeemug / gist:4227320
Created December 6, 2012 19:11
RethinkDB oneliner
r.table(Build.__tablename__).get(build_id).update({'result': r.table(Build.__tablename__).get(build_id)['result'].append(line)}).run()
@coffeemug
coffeemug / gist:4227353
Created December 6, 2012 19:14
RethinkDB oneliner take 2
r.table(Build.__tablename__).get(build_id).update({'result': r['result'].append(line)}).run()
@coffeemug
coffeemug / rethinkdb_president_motiff
Created May 5, 2013 04:30
RethinkDB memory utilization under President Beef's workload
--------------------------------------------------------------------------------
n time(i) total(B) useful-heap(B) extra-heap(B) stacks(B)
--------------------------------------------------------------------------------
78 57,030,430,673 1,440,292,888 1,227,094,500 213,198,388 0
85.20% (1,227,094,500B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->26.62% (383,410,176B) 0x207EA0D: malloc_aligned(unsigned long, unsigned long) (utils.cc:234)
| ->13.94% (200,802,304B) 0x186277E: artificial_stack_t::artificial_stack_t(void (*)(), unsigned long) (context_switching.cc:37)
| | ->13.94% (200,802,304B) 0x1862F4D: coro_t::coro_t() (coroutines.cc:127)
| | ->13.94% (200,802,304B) 0x1863DAA: coro_t::get_coro() (coroutines.cc:356)
| | ->06.41% (92,274,688B) 0x18BD37A: coro_t* coro_t::get_and_init_coro<boost::_bi::bind_t<void, boost::_mfi::mf2<void, mc_inner_buf_t, bool, file_account_t*>, boost::_bi::list3<boost::_bi::value<mc_inner_buf_t*>, boost::_bi::valu
@coffeemug
coffeemug / rethinkdb-import-export.md
Last active January 19, 2023 08:21
Description of import and export feature introduced in RethinkDB 1.7.

You can import data as follows:

# Import a JSON document into table `users` in database `my_db`
$ rethinkdb import -c HOST:PORT -f user_data.json --table my_db.users

# Import a CSV document
$ rethinkdb import -c HOST:PORT -f user_data.csv --format csv --table my_db.users
@coffeemug
coffeemug / rethinkdb-atomic-get-set.md
Last active February 2, 2018 15:17
Atomic get and set in RethinkDB 1.7

Suppose you have a number of nodes on a network that spin up cron jobs to perform various tasks. However, you need the nodes to cooperate to ensure that multiple nodes don't spin up the same task. You can easily implement this functionality on top of RethinkDB as follows:

// A single node atomically pushes jobs onto an array in the database
r.table('admin').get('jobs').update({ job_list: r.row('job_list').append(JOB_DESCRIPTION)) })
@coffeemug
coffeemug / rethinkdb-getField.md
Last active December 19, 2015 03:59
The `getField` command works on sequences in RethinkDB 1.7

The getField command now works on sequences

In the previous versions of RethinkDB you could get a subset of an object using the pluck command, and the value of a specific field using the getField command (accessible via () in Javascript and [] in Python and Ruby):

r.expr({a: 1, b: 1}).pluck('a')
// returns {a: 1}
@coffeemug
coffeemug / rethinkdb-getall.md
Last active March 2, 2022 07:29
Using the `getAll` command to query multiple keys in RethinkDB 1.7.

Querying by multiple keys

The previous releases of RethinkDB allowed querying indexes as follows:

// Three ways to get the user with primary key 5
r.table('users').get(5)
r.table('users').getAll(5)
r.table('users').getAll(5, {index: 'id'})
@coffeemug
coffeemug / rethinkdb-pluck.md
Last active December 19, 2015 03:59
Plucking nested objects in RethinkDB 1.7.

Syntax for plucking nested objects

In the previous versions of RethinkDB you could use the pluck command to extract only specific attributes from an object or a sequence of objects:

r.expr({a: 1, b: {c: 1, d: 1}}).pluck('b')
// returns `b: {c: 1, d: 1}`