Recently I was wondering how Ceph (i.e. Rados in particular) maps object to Placement Groups (PGs).
It basically works like the following:
pg = hash(object)
osd = crush(pg)
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
# I used this in order to insert the preimages into a local ceph cluster, | |
# started in my ceph dev directory via src/vstart.sh. Adapt paths if needed. | |
import sys, os | |
srcdir = '/home/daniel/cn-work/ceph-dev/src' | |
pool = 'collisions' |
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
import sys, json | |
from collections import defaultdict | |
from scipy.stats import chisquare | |
# usage: ceph pg dump_json | ./check_distribution.py | |
if __name__ == '__main__': |
#include <thread> | |
#include <utility> | |
#include <stdexcept> | |
// takes ownership of the thread | |
class scoped_thread { | |
public: | |
explicit scoped_thread(std::thread t_) : t(std::move(t_)) { | |
if(!t.joinable()) throw std::logic_error{"no thread"}; |
#include <atomic> | |
class spinlock_mutex { | |
public: | |
spinlock_mutex() : flag(ATOMIC_FLAG_INIT) {} | |
void lock() { while(flag.test_and_set(std::memory_order_acquire)); } | |
void unlock() { flag.clear(std::memory_order_release); } | |
private: |
// Suppose we have a templated framework and we want to adapt its interface -> use the adapter pattern. | |
// Our templated framework with awkward get_t and set_t member functions: | |
template <typename T> | |
class Framework { | |
public: | |
Framework(T t = {}) : t_{std::move(t)} { } | |
T get_t() const { return t_; } |
#!/usr/bin/env hy | |
(import [operator [eq]] | |
[itertools [chain count]] | |
[functools [partial reduce]]) | |
(defn map-indexed [f coll] | |
(map f (count) coll)) |
// See: EMC++, Item 4 | |
template<typename> | |
class CompileTimeType; | |
int main() { | |
int x; | |
CompileTimeType<decltype(x)> x_Type; |
#include <iostream> | |
#include <string> | |
#include <tuple> | |
// See: EMC++, Item 10 | |
namespace { | |
using Person = std::tuple<std::string, std::string, int>; | |
enum { FirstName, LastName, Age }; | |
} |