1

For example, one class has a private db, and a public method-put . We got several threads to run the put, is this ok ? (ps: we don't consider the order of the k/v )

void put(List<byte[] keys, List<byte[]> values) {
      WriteOptions writeOpt = new WriteOptions();
      WriteBatch batch = new WriteBatch();
      for (int i = 0; i < keys.size(); ++i) {
        batch.put(keys.get(i), values.get(i));
      }
      this.db.write(writeOpt, batch);
}

The doc here says that

However other objects (like Iterator and WriteBatch) may require external synchronization. 
If two threads share such an object, they must protect access to it using their own locking protocol. 

But for the example above, the threads don't share the same WriteBatch, they own its own WriteBatch, and write to the db. So I wonder if this is ok?

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
jcyan
  • 51
  • 7

1 Answers1

0

As far as I known, this is ok. RocksDB uses a WriterThread to handle the multithread write. And all the writers will go into a JoinBatchGroup, if the writer of current thread gets the so called group_leader, it gonna write. The whole process has no competition.

I'm a freshman to this, and I don't be sure about the above statements. Can anyone fix me if I'm wrong ?

jcyan
  • 51
  • 7