writeImpl
大致流程:
- 一般都要先做一些参数check
- 写wal
- 写memtable
- 更新seq
- 收尾
- 流程结束并返回
重要知识点:
- joinBatchGroup相关的status操作
- 写wal的注意事项
- 写memtable的内部流程(跳表)
- sequence相关操作
细节流程
- step 1:
- 参数的判断
- step 2:
- 写限流的判断
- step3:
- 如果设置不写memtable,直接走writewalonly 然后返回
- step4
- step5
-
enable_pipelined_write=true 执行PipelinedWriteImpl
-
- step6
-
构造writer WriteThread::Writer w(write_options, my_batch, callback, log_ref, disable_memtable, batch_cnt, pre_release_callback);
-
- step7
-
StopWatch write_sw statistics_统计
-
- step8
- 传说中的write_thread_.JoinBatchGroup(&w);
- step9
-
STATE_PARALLEL_MEMTABLE_WRITER
-
- step10
-
STATE_COMPLETED
-
- step11
- 初始化write_context
-
uint64_t last_sequence = kMaxSequenceNumber;
=============mutex_.Lock();============
- step12
-
PreprocessWrite
-
- step13
- log::Writer* log_writer = logs_.back().writer;
============mutex_.Unlock();============
- step 14:
-
EnterAsBatchGroupLeader
-
- step15
- 计算stats
- step16
- 更新stats
- step17
-
判断write_done_by_other 更新stats WRITE_DONE_BY_OTHER
-
- step18
- a
-
// A flag indicating whether the current rocksdb database has any // data that is not yet persisted into either WAL or SST file. // Used when disableWAL is true.标识当前rocksdb数据库是否有任何尚未持久化到WAL或SST文件中的数据。
-
- a
- step19
-
WriteToWAL或者ConcurrentWriteToWAL
- FetchAddLastAllocatedSequence!!!
-
- step20
-
inc seq number for memtable writes
-
pre_release_callback (事务场景用到)
-
- step21
-
WriteBatchInternal::InsertInto 写memtable
-
- step22
- FlushWal or SyncWal
- step23
-
in_parallel_group=true的话,执行CompleteParallelMemTableWriter
-
- step24
- 更新versions_->SetLastSequence(last_sequence);
-
MemTableInsertStatusCheck
- step25
- 获取w.FinalStatus()
- 返回status;
结束