caetanosauer / zero

Fork of the Shore-MT storage manager used by the research project Instant Recovery

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Concurrency Problem in Archive Index

llersch opened this issue · comments

ArchiveIndex has a member: std::vector runs
The last element of this vector is the run being generated.

T1: Archiver Thread
T2: Writer Thread

// Run 1
T1: assemb.start() //get block
T1: assemb.add(lr)... assemb.add(lr)... assemb.add(lr)...
T1: assemb.finish() ----> newBlock()

// Run 2
T1: assemb.start() //get block
T1: assemb.add(lr)... assemb.add(lr)... assemb.add(lr)...
T2: closeCurrentRun() ----> finishRun() //inserts empty run element to the back of runs (for the new run)

newBlock() inserts an empty block in the run runs.back().

A new run is only inserted in the runs vector after the Writer Thread finished writing the current run to disk. Therefore, the Archiver Thread may start processing log records pertaining to a new run and inserting then to the element runs.back() which refers to the old run (because it was not written to disk yet).