MVCC

To solve non-repeatable read: 1. lock 2. mvcc As long as there is an update, then generate a new record with current tx_id. undo log points to previous one. When read, it should have: ReadView { m_ids_list, min_trx_id, max_trx_id, creator_trx_id } When read or doing a transaction, it should have current tx_id and its ReadView.… Read More »

hungarian algorithm template

  public int findMaxMatch(boolean[][] graph) { int match = 0; int[] match = new int[graph[0].length]; for (int i = 0; i < graph.length; i++) { boolean[] visited = new int[graph.length]; if (find(i, graph, match, visited)) { match++; } } return match; } // match[j], for each record j in B set, it matches to a… Read More »

payment system keywowrd

double payment sync payment async payment 3rd party interaction different state sensitive data, accuracy, relational database. websocket, long polling, stateful

consistency model

Strictly Serializable support transaction, Spanner Linearizable Doesn’t support transaction. There is global timer. Things in different machine happens with the global timer. Sequential consistency Above example satisfies sequential consistency. P3, P4, P5 all observe that W(x)1 happens before W(x)3. They are globally making sense. So it is sequential consistent. But considering the time when W(x)3… Read More »

ddia chapter 5, replication

1. partition by key range 2. partition by hash HBase, key is sorted partition内部再sort. read intensive, 1. replication, 2. cache? read intensive leaderless, 加名人list,加cache leader-replica, 加replica vertical scale, 加CPU, memory, disk vertical split table. 将不同的column放在不同的node中 normalize, 归一化, no redundancy denormalize, large table global secondary index, local secondary index. consistency hashing rebalancing, 并不能彻底解决hotspot fixed number of… Read More »

Background run, nohup, &

nohup, means “no hangup”. Means even logout, let it run. &, run in background. For instance: nohup java -jar abc.jar &

PreSum template

HashMap targetSum currSum for (int n : nums) { 1. see if currSum satisfy 2. count number of targetSum 3. put currSum into map. } In this case, it can handle [0, 0, 0], targetSum = 0, which returns 5. practice https://leetcode.com/problems/path-sum-iii/

DDIA, leaderless

Dynamo database, leaderless, quorum read/write, vector clock. database, ACID cache coherent, consistency linearizable, 用户写的action发生了,那么read的时候就要读出write的内容 leaderless, quoram write, quoram read read repair or a background process to detect the stale data in replica 如果是read repair,某些data一直没有被read repair过,有些机器down了。good data node不在了。所以一定要有background process anti-entrophy the higher entropy, the greater the disorder 3 nodes. r+w>n. when w=1, r=3. user1 only write… Read More »