Programming

Notes on the google spanner paper

The traits of Google Spanner

  1. horizontal scalability, keys partitioned into shards(named “Directory” in the paper)
  2. Transaction and extern consistency
  3. RW transactions require 2 phase commit and 2 phase locking with locks stored on a lock table on each Span Master
  4. R only transactions requires no lock and no 2 phase commit. Read is fast since the client query it’s the nearest replica and reads the latest data, likely without blocking (Even no Paxos sync latency).

MIT 6.824 Lab 4: Sharded KeyValue Service的个人实现

终于把lab4写到过test稳如狗了. 回顾这段时间, 看日志看得头疼. 写这个lab可比打只狼硬核多了. 能写完完全靠坚持. 当跑通test的时候, 我感觉我要high到天上去了.

MIT 6.824 lab 3 一种client request 去重方式

终于吧lab3调通到1k次运行稳如狗了. 写这个lab我感觉还是得靠坚持. 看到极低概率的失败还是心里会咯噔一下的. 不像是lab2, 照着论文算法按部就班老老实实写出来, Lab3给我感觉提供了更大的发挥空间, 很多种实现方式, 得自己来设计一些关键的步骤.

Class Interface design and thread-safe in concurrent programming

I wrote a logging manager for logging. The logging manager maintains a thread-safe queue and creates a new thread for asynchronous logging, let’s call it logging thread. The queue is used to deliver logging records to the logging thread which is doing an infinite loop of retrieving records from that queue until a stop token received.

The interface of the logging manager is below:

 class GlobalLoggerManager {
  private:
	threadsafe_queue queue;
    std::thread logging_deamon;
  public:
    GlobalLoggerManager(int level);
    GlobalLoggerManager(int level, const char *file_path);
    void new_records(const record &r);
    void loop_body();
    void stop();
};

think thread safe when using global/static variable

const char *get_file_name(const char *path) {
    // get the file name for __FILE__ macro
    //  should be thread safe
    static thread_local unordered_map dict;
    if (dict.count(path) == 0) {
        const char *pos = strrchr(path, '/') ? strrchr(path, '/') + 1 : path;
        dict[path] = pos;
    }
    return dict[path];
}

the cost of think-async

We need to guarantee that the callback functions and everything bound to them should be available when the asio executor running them. I just forgot that…

Back to Top ↑