Skip to content

Commit 5a1983e

Browse files
编写序列化文档
1 parent ca5ff82 commit 5a1983e

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

demo/batch_test/write_batch_demo.h

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/*
1515
* 对write_bach 进行重新实现,一般理解里面的实现原理
16-
*
1716
* */
1817
namespace WRITE_BATCH_DEMO {
1918

@@ -33,36 +32,24 @@ namespace WRITE_BATCH_DEMO {
3332

3433
WriteBatch();
3534

36-
// Intentionally copyable.
35+
// 支持copy构造函数
3736
WriteBatch(const WriteBatch &) = default;
38-
37+
// 支持赋值操作
3938
WriteBatch &operator=(const WriteBatch &) = default;
4039

4140
~WriteBatch();
4241

43-
// Store the mapping "key->value" in the database.
42+
// Put 将Key-value形式的值存储在数据库中
4443
void Put(const leveldb::Slice &key, const leveldb::Slice &value);
45-
46-
// If the database contains a mapping for "key", erase it. Else do nothing.
44+
// 当某个值不想要时,按照key值将对应的键值对删除
4745
void Delete(const leveldb::Slice &key);
48-
49-
// Clear all updates buffered in this batch.
46+
// 将 batch中所有的缓存清理,并预留出长度和序列号字段足够的长度
5047
void Clear();
51-
52-
// The size of the database changes caused by this batch.
53-
//
54-
// This number is tied to implementation details, and may change across
55-
// releases. It is intended for LevelDB usage metrics.
48+
// 获取batch内部指标数据长度,也就是获取rep_的大小
5649
size_t ApproximateSize() const;
57-
58-
// Copies the operations in "source" to this batch.
59-
//
60-
// This runs in O(source size) time. However, the constant factor is better
61-
// than calling Iterate() over the source batch with a Handler that replicates
62-
// the operations into this batch.
50+
// 当有多个batch想合并时,可以使用append将batch添加到另外衣蛾batch后面
6351
void Append(const WriteBatch &source);
64-
65-
// Support for iterating over the contents of a batch.
52+
// 对batch进行迭代,这样能够按照类型取出所有batch里面的值
6653
leveldb::Status Iterate(Handler *handler) const;
6754

6855
private:

doc/instruction/write_batch_impl.adoc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,39 @@ endif::rootpath[]
2222

2323
== write batch
2424

25+
write batch作为levelDB对外提供的事务操作类,只要你使用levelDB肯定避免不了要应对write batch。我见很多帖子上都说write batch实现的很巧妙,只使用一个string就把一个事务模型给实现了,我也一直好奇到底巧妙到哪?以及如何在日后的编码中能够让其为我所用,带着这样的疑问和目的让我们对write batch来一探究竟。
26+
27+
作为C++类,无非就是成员函数和成员变量,以及部分辅助类(友元函数等)。
28+
29+
=== 成员函数
30+
31+
32+
=== 成员变量
33+
34+
35+
36+
=== 巧妙的结合
37+
38+
39+
40+
对rep的设计
41+
42+
43+
44+
45+
46+
47+
=== 总结
48+
49+
50+
可以用到哪里
51+
52+
- 因为是序列化的数据 可以直接用来网络之中传输数据
53+
54+
55+
56+
57+
58+
59+
2560

0 commit comments

Comments
 (0)