DataManagementLab/p4db

Question about TPC-C implementation?

mihir-b-shah opened this issue · 2 comments

Hello,

Sorry to bother about this, I had a question about implementation of insert() commands in P4DB, I had the following scenario I wasn't sure how P4DB maintains serializability. My understanding of insert() in P4DB is we do not acquire a lock, but rather just to atomic increment of table position to get our slot to insert a row. Then we have the following scenario:

Thread 1 is running:
Read(Table1, k)
v = Switch_Txn();
Insert(Table2, {...,k});

Thread 2 is running:
Read(Table2, k)
v = SwitchTxn();

Then we have the following interleaving:
First thread 1's transaction runs up through Switch_Txn(). Then thread 2 starts running, and tries to read the key that thread 1 was going to insert- so it is not found. Thread 2 then runs the SwitchTxn, and sees the effects of thread 1's transaction. Wouldn't this break isolation? (Since we are seeing some effects of a transaction but not others)?

Thank you!

mjasny commented

You would need to lock the inserted row with Thread 1, then Thread 2 will need to block and cannot issue the SwitchTxn until Thread 1 finished. See 2PL.

Oh ok, thank you for the clarification!