// 1. Create a new memtable// 2. Put the current memtable into flush queue// 3. A worker apply update block op (? Maybe apply update block in main thread is better)snapshot:=CacheHolder.GetSnapshot()
ctx:=NewOperationContext(snapshot)
updateblkop:=NewUpdateBlockOperation(&ctx)
seg, err:=updateblkop.CommitNewSegment()
iferr!=nil {
returnerr
}
newsegop.Push()
err=newblkop.WaitDone()
iferr!=nil {
returnerr
}
Flush
// 1. The flush worker take a memtable | segment from flush queue// 2. Get the latest snapshot and check whether to flush or not. (maybe dropped already)// 3. Serialize the data// 4. Serialize the metadata into a tmp file// 5. Create a flush operation and pass the tmp file in op context// 6. The metadata execute worker check the consistency. If it is ok, rename the tmp file to correct name// 7. Refresh the latest cachesnapshot:=CacheHolder.GetSnapshot()
ctx:=NewOperationContext(snapshot)
ctx.Block=memTable.Block// Here take flush memtable as exampleflushop:=NewFlushOperation(&ctx)
flushop.Push()
err=flushop.WaitDone()
iferr!=nil {
returnerr
}