git-hulk commented on issue #487:
URL: 
https://github.com/apache/incubator-kvrocks/issues/487#issuecomment-1445391916

   Hi, @Eshcar @ShooterIT I have an idea to workaround this bug. We can add a 
new function to create a shared WriteBatch for the Multi-Exec command like the 
below:
   
   ```C++
   Status Storge::Begin() {
       is_txn_mode = true;
       txn_write_batch = make_shared<*rocksdb::WriteBatch>();
   }
   
   rocksdb::WriteBatch *Storge::GetWriteBatch() {
      if (is_txn_mode) {
         return txn_write_batch.get();
      }
      return make_shared<*rocksdb::WriteBatch>();
   }
   
   Status Storge::Commit() {
       is_txn_mode = false;
       // write txn WriteBatch to RocksDB
       txn_write_batch.reset();
   }
   ```
   
   For the Command Exec, we need to explicitly call the `Begin()` and  
`Commit()` to enter and leave the transaction mode. So that Kvrocks will create 
a new WriteBatch for each writes operation if it's NOT in transaction mode, and 
use the shared WriteBatch to collect all write operations if it's in the 
transaction mode.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to