liuis / leveldb

Automatically exported from code.google.com/p/leveldb
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

add support for PutNew/3 and WriteNew/2 update operations #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be handy to have 2 new update operations that fail if the key(s) 
already exist in the database.  

For WriteNew operations, the last key/value of the batch is stored and not 
considered as already exists when a duplicate key(s) are given in the batch.

  // Set the database entry for "key" to "value" only if "key" does not exist.  Returns OK on success,
  // and a non-OK status on error.
  // Note: consider setting options.sync = true.
  virtual Status PutNew(const WriteOptions& options,
                     const Slice& key,
                     const Slice& value) = 0;

  // Apply the specified updates to the database only if all keys do not exist (prior to this operation).
  // Returns OK on success, non-OK on failure.
  // Note: consider setting options.sync = true.
  virtual Status WriteNew(const WriteOptions& options, WriteBatch* updates) = 0;

Original issue reported on code.google.com by josephwn...@gmail.com on 27 Sep 2011 at 2:32

GoogleCodeExporter commented 9 years ago
I am not sure I understand this one. leveldb is a LSM based database. It writes 
new kvs to a new location and garbage collects overwritten ones. If you want an 
api that implements read-modify-writes can you implement it in your own 
application?

are you concerned about the atomicity of the read-modify-write operation?

Original comment by dhr...@gmail.com on 26 May 2012 at 5:12

GoogleCodeExporter commented 9 years ago
This feature request is to add 2 new functions PutNew/3 and WriteNew/2 that 
would work exactly like Put/3 and Write/2 respectively, with the exception that 
instead of overwriting values with the same key or adding more values with keys 
already existing in the database, these 2 functions simply return a non-OK 
status.  Nothing would be inserted if not all key or keys are absent from the 
database.  The entire operation would be guaranteed to be atomic and isolated.

Original comment by josephwn...@gmail.com on 27 May 2012 at 1:50

GoogleCodeExporter commented 9 years ago
Sorry, but it is currently out of scope of this library.  Equivalent 
functionality can be implemented just as efficiently outside the library.

Original comment by san...@google.com on 8 Oct 2012 at 9:25