noblog 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/cmds/generate.d.ts +2 -0
- package/dist/cmds/generate.d.ts.map +1 -0
- package/dist/cmds/generate.js +46 -0
- package/dist/cmds/generate.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/cvtmd.d.ts +38 -0
- package/dist/lib/cvtmd.d.ts.map +1 -0
- package/dist/lib/cvtmd.js +111 -0
- package/dist/lib/cvtmd.js.map +1 -0
- package/dist/lib/nomd/cvter.d.ts +38 -0
- package/dist/lib/nomd/cvter.d.ts.map +1 -0
- package/dist/lib/nomd/cvter.js +111 -0
- package/dist/lib/nomd/cvter.js.map +1 -0
- package/dist/lib/nomd/nomd.d.ts +20 -0
- package/dist/lib/nomd/nomd.d.ts.map +1 -0
- package/dist/lib/nomd/nomd.js +73 -0
- package/dist/lib/nomd/nomd.js.map +1 -0
- package/dist/lib/nomd.d.ts +8 -0
- package/dist/lib/nomd.d.ts.map +1 -0
- package/dist/lib/nomd.js +50 -0
- package/dist/lib/nomd.js.map +1 -0
- package/dist/lib/nosm/default.d.ts +2 -0
- package/dist/lib/nosm/default.d.ts.map +1 -0
- package/dist/lib/nosm/default.js +3 -0
- package/dist/lib/nosm/default.js.map +1 -0
- package/dist/lib/nosm/nosm.d.ts +2 -0
- package/dist/lib/nosm/nosm.d.ts.map +1 -0
- package/dist/lib/nosm/nosm.js +2 -0
- package/dist/lib/nosm/nosm.js.map +1 -0
- package/dist/lib/notion/client.d.ts +6 -0
- package/dist/lib/notion/client.d.ts.map +1 -0
- package/dist/lib/notion/client.js +48 -0
- package/dist/lib/notion/client.js.map +1 -0
- package/dist/lib/notion/object.d.ts +148 -0
- package/dist/lib/notion/object.d.ts.map +1 -0
- package/dist/lib/notion/object.js +2 -0
- package/dist/lib/notion/object.js.map +1 -0
- package/dist/lib/notion/request.d.ts +36 -0
- package/dist/lib/notion/request.d.ts.map +1 -0
- package/dist/lib/notion/request.js +2 -0
- package/dist/lib/notion/request.js.map +1 -0
- package/output/00097769-2aac-4b6f-8f37-d9b658d46b2e +435 -0
- package/output/1707063b-7c0a-4572-9526-f7db2f7bbc49 +162 -0
- package/output/1ed588e1-2604-4e33-9685-722b03f66374 +89 -0
- package/output/2b1c0d09-40f7-4151-a053-11391f775ece +33 -0
- package/output/336b6a5a-f383-4d6c-8fe5-54c9a918c4c0 +264 -0
- package/output/37b77a0a-e233-405a-93f5-a60a808eee35 +72 -0
- package/output/3ac660cb-9503-4e88-8939-5aee30c98351 +24 -0
- package/output/5bc1b19a-8350-48b3-aa19-8073561ad45b +109 -0
- package/output/765976b5-7790-497b-8634-4be1d4770e16 +111 -0
- package/output/90f2cb44-90ab-40b7-a736-02bfb83a314c +1167 -0
- package/output/99a7b0c5-f9de-403c-95ec-eba3d700a195 +49 -0
- package/output/c844b66d-0bf3-4f89-bbe1-5974f2de454b +193 -0
- package/output/cd6299f7-54bb-4160-8735-16e629422a57 +193 -0
- package/output/d462cfca-0a39-4b65-8430-4eae35edbb76 +27 -0
- package/output/daafaad2-2570-43da-8e9e-f95a1b29ca17 +12 -0
- package/output/e45ef6bf-6c30-4fb2-9efc-a1984e5dc530 +84 -0
- package/output/sub/05009ca9-cb39-4356-8f24-c0db39cb4661 +64 -0
- package/output/sub/0b903359-2337-4ad9-adef-e77b69142581 +328 -0
- package/output/sub/18f0fae1-b7ca-40ea-b725-4e69404429dc +109 -0
- package/output/sub/232ae8ce-5ec3-4737-a18e-077774b84b1e +940 -0
- package/output/sub/34f4d4af-812e-4e56-a6dd-deb96e7f605c +3 -0
- package/output/sub/44331753-a264-40a4-b86f-eafd676b3da0 +509 -0
- package/output/sub/4bac355b-24f0-49e7-a317-e4f1cad63c79 +65 -0
- package/output/sub/4d6663a2-e93a-402e-89f8-a47cccc0c8cf +76 -0
- package/output/sub/5771c956-25bf-4714-bc2e-65959c9156d9 +52 -0
- package/output/sub/6ff91a18-494e-4ffc-a33b-b9fd2c36f43f +42 -0
- package/output/sub/81e4a2b0-05e2-4013-bd41-14b144979d91 +0 -0
- package/output/sub/99ef1497-0b94-490f-b9a0-f54b0e64194d +6 -0
- package/output/sub/9a33b8cc-101a-4f6a-9852-115595cd166b +172 -0
- package/output/sub/9c060d29-39a2-432b-b06b-b0bd91989a52 +1159 -0
- package/output/sub/a45b383c-d894-4480-8322-9c5d028722e3 +9 -0
- package/output/sub/b875bfe4-3c1e-4a8f-a56c-27a48ab874ca +438 -0
- package/output/sub/b8cbb8f9-f702-4a43-943c-02a6e39683d5 +222 -0
- package/output/sub/e339a686-bbb1-41d9-b6b5-18111e72a68c +1392 -0
- package/output/sub/e7931a8e-45ca-444a-8d6f-e6fed9415c26 +110 -0
- package/output/sub/e859552b-c597-49ed-9ede-fab320fafd87 +150 -0
- package/output/sub/f4237e72-fdce-44a4-b62c-659dce24b1ee +107 -0
- package/output/sub/ff7ea97c-55ac-471c-902f-b7a7bd101ee6 +0 -0
- package/package.json +31 -0
- package/src/cmds/generate.ts +54 -0
- package/src/index.ts +22 -0
- package/src/lib/nomd/cvter.ts +143 -0
- package/src/lib/nomd/nomd.ts +88 -0
- package/src/lib/nosm/default.ts +0 -0
- package/src/lib/nosm/nosm.ts +3 -0
- package/src/lib/notion/client.ts +59 -0
- package/src/lib/notion/object.ts +176 -0
- package/src/lib/notion/request.ts +42 -0
- package/tsconfig.json +35 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
# Intro
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
This blog is written in eng cus ref and concept related to it could be super confusing when translation happens.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# All that matters
|
|
9
|
+
|
|
10
|
+
- `[T; n]` is an array of length `n`, represented as `n` adjacent `T` instances.
|
|
11
|
+
- `&[T; n]` is purely a reference to that array, represented as a thin pointer to the data.
|
|
12
|
+
- `[T]` is a slice, an unsized type; it can only be used through some form of indirection.
|
|
13
|
+
- `&[T]`, called a slice, is a sized type. It's a _fat pointer_, represented as a pointer to the first item and the length of the slice.
|
|
14
|
+
|
|
15
|
+
# Array and Slice
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
ok, first lets learn how to create a array.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Lets picture a scenario, you are a python boy. You want to learn rust to show off to your miserable friends. you create a array based on the spirit of python. And the compiler complained that you should use `let i32slice: [i32; 2] = [0, 10];` instead of `let i32slice: [i32] = [0, 10];`.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## TL; DR.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
This part is for those python boy. If you are familiar with c++, you should spit on my blog and go get some comic to read till I finish this stupid lesson.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
```c++
|
|
31
|
+
// in C++
|
|
32
|
+
std::array<int, 2> myArray = {1, 10};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
`[T]` is a contiguous sequence of `T`s, while `&[T]` is a dynamically-sized view into this contiguous sequence. The former has no statically known size while the latter does. while the lvalue always has an statically known size. If you dont know what lvalue is, go ask Dr.Google, on this I cant help.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Diff between `&[T; n]` and `&[T]`
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
[https://stackoverflow.com/questions/30794235/what-is-the-difference-between-a-slice-and-an-array](https://stackoverflow.com/questions/30794235/what-is-the-difference-between-a-slice-and-an-array)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## About `[T]`
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
`[T]` is just a concept, you can never create a dynamically sized variable in rust, all you can do is let `&[T; n]` coerce to `&[T]` and thus exploit the returned fat pointer.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
# 什么是反射
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
> 在计算机科学中,反射是指计算机程序在运行时(Run time)可以访问、检测和修改它本身状态或行为的一种能力。用比喻来说,反射就是程序在运行的时候能够“观察”并且修改自己的行为。
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
难道不用反射就不能在运行时访问、检测和修改它本身的状态和行为吗?
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
问题的回答,其实要首先理解什么叫访问、检测和修改它本身状态或行为,它的本质是什么?
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
实际上,它的本质是程序在运行期探知对象的类型信息和内存结构。不用反射能行吗?可以的!使用汇编语言,直接和内层打交道,可以获取任何信息?但是,当编程迁移到高级语言上来之后,就不行了!只能通过`反射`来达到此项技能。
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
不同语言的反射模型不尽相同,有些语言还不支持反射。《Go 语言圣经》中是这样定义反射的:
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
> Go 语言提供了一种机制在运行时更新变量和检查它们的值、调用它们的方法,但是在编译时并不知道这些变量的具体类型,这称为反射机制。
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
再挂一段摘自stackoverflow的解释
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
> The first good example I can think of off the top of my head is for when you need to execute a set of methods on a given object without knowing at compile-time what methods will exist in it.
|
|
27
|
+
>
|
|
28
|
+
> Take unit testing frameworks for example. The test runner class that is responsible for running all your unit tests doesn't know ahead of time what you are going to name your methods. All it knows is that they will be prefixed with "test" (or in Java 5's case, annotated with `@Test`). So when given a test class, it reflects on that class in order to get a list of all the methods in it. Then, it iterates through those method names as strings and calls those methods on the object if they start with "test". That wouldn't be possible without reflection. And that's just one example.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# 什么时候需要反射
|
|
32
|
+
|
|
33
|
+
1. 不能明确接口调用哪个函数,需要根据传入的参数在运行时决定。
|
|
34
|
+
2. 不能明确传入函数的参数类型,需要在运行时处理任意对象。
|
|
35
|
+
3. 彻底解耦调用者和执行者,执行者只负责执行,方法可以在运行时动态获取
|
|
36
|
+
|
|
37
|
+
# 为什么不推荐反射
|
|
38
|
+
|
|
39
|
+
1. 与反射相关的代码,经常是难以阅读的。在软件工程中,代码可读性也是一个非常重要的指标。
|
|
40
|
+
2. Go 语言作为一门静态语言,编码过程中,编译器能提前发现一些类型错误,但是对于反射代码是无能为力的。所以包含反射相关的代码,很可能会运行很久,才会出错,这时候经常是直接 panic,可能会造成严重的后果。
|
|
41
|
+
3. 反射对性能影响还是比较大的,比正常代码运行速度慢一到两个数量级。所以,对于一个项目中处于运行效率关键位置的代码,尽量避免使用反射特性。
|
|
42
|
+
4. 反射会让封装的变量、方法不再安全。
|
|
File without changes
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
|
|
2
|
+
## 1. Why Raft?
|
|
3
|
+
|
|
4
|
+
- **Consensus algorithms** allow a collection of machines to work as a coherent group that can survive the failures of some of its members.
|
|
5
|
+
- **Paxos** (one of the Consensus Algorithm)has dominated the discussion of consensus algorithms over the last decade. But it is hard to understand.
|
|
6
|
+
- **Raft** define a consensus algorithm for practical systems and describe it in a way that is significantly easier to learn than Paxos.
|
|
7
|
+
|
|
8
|
+
## 2. Main features in Raft
|
|
9
|
+
|
|
10
|
+
- **Strong leader:** Raft uses a stronger form of leadership than other consensus algorithms. For example, log entries only flow from the leader to other servers. This simplifies the management of the replicated log and makes Raft easier to understand.
|
|
11
|
+
- **Leader election:** Raft uses randomized timers to elect leaders. This adds only a small amount of mechanism to the heartbeats already required for any consensus algorithm, while resolving conflicts simply and rapidly.
|
|
12
|
+
- **Membership changes:** Raft’s mechanism for changing the set of servers in the cluster uses a new joint consensus approach where the majorities of two different configurations overlap during transitions. This allows the cluster to continue operating normally during configuration changes.
|
|
13
|
+
|
|
14
|
+
## 3. Replicated state machines
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
> Replicated state machines are used to solve a variety of fault tolerance problems in distributed systems.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
> 💡 Replicated state machines are typically implemented using a replicated log
|
|
21
|
+
> 
|
|
22
|
+
>
|
|
23
|
+
> - Each server stores a log containing a series of commands, which its state machine executes in order
|
|
24
|
+
>
|
|
25
|
+
> - Each log contains the same commands in the same order, so each state machine processes the same sequence of commands
|
|
26
|
+
>
|
|
27
|
+
> - State machines are deterministic, each computes the same state and the same sequence of outputs
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
- Each server stores a log containing a series of commands, which its state machine executes in order
|
|
33
|
+
- Each log contains the same commands in the same order, so each state machine processes the same sequence of commands
|
|
34
|
+
- State machines are deterministic, each computes the same state and the same sequence of outputs
|
|
35
|
+
|
|
36
|
+
**Keeping the replicated log consistent is the job of the consensus algorithm.**
|
|
37
|
+
|
|
38
|
+
- The consensus module on a server receives commands from clients and adds them to its log.
|
|
39
|
+
- It communicates with the consensus modules on other servers to ensure that every log eventually contains the same requests in the same order, even if some servers fail.
|
|
40
|
+
- Once commands are properly replicated, each server’s state machine processes them in log order, and the outputs are returned to clients.
|
|
41
|
+
|
|
42
|
+
**Consensus algorithms for practical systems typically have the following properties:**
|
|
43
|
+
|
|
44
|
+
- They ensure safety (never returning an incorrect result) under all non-Byzantine conditions, including network delays, partitions, and packet loss, duplication, and reordering.
|
|
45
|
+
- They are fully functional (available) as long as any majority of the servers are operational and can communicate with each other and with clients. Thus, a typical cluster of five servers can tolerate the failure of any two servers. Servers are assumed to fail by stopping; they may later recover from state on stable storage and rejoin the cluster.
|
|
46
|
+
- They do not depend on timing to ensure the consistency of the logs: faulty clocks and extreme message delays can, at worst, cause availability problems.
|
|
47
|
+
- In the common case, a command can complete as soon as a majority of the cluster has responded to a single round of remote procedure calls; a minority of slow servers need not impact overall system performance.
|
|
48
|
+
|
|
49
|
+
## 4. Weakness of Paxos
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
> Over the last ten years, Leslie Lamport’s Paxos protocol has become almost synonymous with consensus: it is the protocol most commonly taught in courses, and most implementations of consensus use it as a starting point.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
> 💡 Paxos first defines a protocol capable of reaching agreement on a single decision, such as a single replicated log entry. We refer to this subset as single-decree Paxos. Paxos then combines multiple instances of this protocol to facilitate a series of decisions such as a log (multi-Paxos)
|
|
56
|
+
|
|
57
|
+
- Too difficult to understand.
|
|
58
|
+
- does not provide a good foundation for building practical implementations.
|
|
59
|
+
|
|
60
|
+
Each implementation begins with Paxos, discovers the difficulties in implementing it, and then develops a significantly different architecture. This is timeconsuming and error-prone, and the difficulties of understanding Paxos exacerbate the problem.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## 5. Idea within Raft
|
|
64
|
+
|
|
65
|
+
- Problem decomposition: wherever possible, we divided problems into separate pieces that could be solved, explained, and understood relatively independently.
|
|
66
|
+
- Simplify the state space by reducing the number of states to consider, making the system more coherent and eliminating nondeterminism where possible
|
|
67
|
+
- There are some situations where nondeterminism actually improves understandability. In particular, randomized approaches introduce nondeterminism, but they tend to reduce the state space by handling all possible choices in a similar fashion (“choose any; it doesn’t matter”). We used randomization to simplify the Raft leader election algorithm.
|
|
68
|
+
|
|
69
|
+
## 6. The Raft consensus algorithm
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
**First electing a distinguished leader**
|
|
73
|
+
|
|
74
|
+
- leader has complete responsibility for managing the replicated log.
|
|
75
|
+
- leader accepts log entries from clients, replicates them on other servers, and tells servers when it is safe to apply log entries to
|
|
76
|
+
their state machines.
|
|
77
|
+
- leader can fail or become disconnected from the other servers, in which case a new leader is elected
|
|
78
|
+
|
|
79
|
+
**Given the leader approch, Raft decomposes the consensus problem into three relatively independent subproblems, which are discussed in the subsections that follow:**
|
|
80
|
+
|
|
81
|
+
- Leader election: a new leader must be chosen when an existing leader failss
|
|
82
|
+
- Log replication: the leader must accept log entries from clients and replicate them across the cluster.
|
|
83
|
+
- Safety: the key safety property for Raft is the State Machine Safety Property. if any server has applied a particular log entry to its state machine, then no other server may apply a different command
|
|
84
|
+
for the same log index.
|
|
85
|
+
|
|
86
|
+
**term**
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
Each server stores a current term number, which increases monotonically over time.
|
|
90
|
+
|
|
91
|
+
- Current terms are exchanged whenever servers communicate.
|
|
92
|
+
- If one server’s current term is smaller than the other’s, then it updates its current term to the larger value.
|
|
93
|
+
- If a candidate or leader discovers that its term is out of date, it immediately reverts to follower state.
|
|
94
|
+
- If a server receives a request with a stale term number, it rejects the request.
|
|
95
|
+
|
|
96
|
+
**RPCs**
|
|
97
|
+
|
|
98
|
+
- RequestVote RPCs are initiated by candidates during elections.
|
|
99
|
+
- AppendEntries RPCs are initiated by leaders to replicate log entries and to provide a form of heartbeat.
|
|
100
|
+
- A third RPC for transferring snapshots between servers
|
|
101
|
+
- Servers retry RPCs if they do not receive a response in a timely manner, and they issue RPCs in parallel for best performance.
|
|
102
|
+
|
|
103
|
+
## 7. Leader election
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
> Raft uses a heartbeat mechanism to trigger leader election. When servers start up, they begin as followers. A server remains in follower state as long as it receives valid RPCs from a leader or candidate. Leaders send periodic heartbeats (AppendEntries RPCs that carry no log entries) to all followers in order to maintain their authority. If a
|
|
107
|
+
> follower receives no communication over a period of time called the _election timeout_, then it assumes there is no viable leader and begins an election to choose a new leader.
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
**Begin an election**
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
follower increments its current term and transitions to candidate state. It then votes for itself and issues RequestVote RPCs in parallel to each of the other servers in the cluster.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
**A candidate continues in this state until one of three things happens:**
|
|
117
|
+
|
|
118
|
+
<details>
|
|
119
|
+
<summary>**a.** it wins the election</summary>
|
|
120
|
+
|
|
121
|
+
A candidate wins an election if it receives votes from a majority.
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
</details>
|
|
125
|
+
|
|
126
|
+
<details>
|
|
127
|
+
<summary>**b.** another server establishes itself as leader</summary>
|
|
128
|
+
|
|
129
|
+
Each server will vote for at most one candidate in a given term, on a first-come-first-served basis
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
a candidate may receive AppendEntries RPC from another server claiming to be leader. If the leader’s term is at least as large as the candidate’s current term, then the candidate recognizes the leader as legitimate and returns to follower state. If the term in the RPC is smaller than the candidate’s current term, then the candidate rejects the RPC and continues in candidate state.
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
</details>
|
|
136
|
+
|
|
137
|
+
<details>
|
|
138
|
+
<summary>**c.** a period of time goes by with no winner</summary>
|
|
139
|
+
|
|
140
|
+
candidate neither wins nor loses the election: if many followers become candidates at the same time, votes could be split so that no candidate obtains a majority. When this happens, each candidate will time out and start a new election by incrementing its term and initiating another round of RequestVote RPCs. However, without extra measures split votes could repeat indefinitely.
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
</details>
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
Raft uses randomized election timeouts to ensure that split votes are rare and that they are resolved quickly
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
**Why not use ranking?**
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
a lower-ranked server might need to time out and become a candidate
|
|
153
|
+
again if a higher-ranked server fails, but if it does so too soon, it can reset progress towards electing a leader.
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|