liuis / leveldb

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

Size() would be handy to get number of records. #186

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
1.5

Please provide any additional information below.

Original issue reported on code.google.com by miroslav...@gmail.com on 10 Jul 2013 at 3:12

GoogleCodeExporter commented 9 years ago
Unfortunately Size() would be very expensive to implement.

In more detail, suppose leveldb starts maintaining an internal count of number 
of records. Consider a "Put(k, v)" value call.  If the database already 
contains "k", the counter must be left unchanged. Otherwise the counter must be 
increased by one.  And currently Put() implementation just logs: it does not 
need to read anything. To keep the counter up to date, we would have to do a 
read to detect whether or not "k" already exists.  So keeping the counter up to 
date would double the cost of a synchronous write (changing one seek to two 
seeks) and increase the cost of a non-synchronous write by an even larger ratio 
(changing 0 seeks to 1 seek).

So we won't be adding a Size() method.

Original comment by san...@google.com on 10 Jul 2013 at 9:56