Within the set method of memtable, the self.bytes += len(k) + len(v) is performed without checking if the values already exist in the RB Tree. If the values already exist in the RB Tree, the RB tree will not grow, however self.bytes will be increased.
The bug that this creates can be seen during flushing of a memtable to a disk segment.
To reproduce:
- Open the KVS file and set
MT_MAX_SIZE to something small like 20.
- Create an instance of KVS.
- Try inserting varying key value pairs until a disk segment is created. Inspect the disk segment.
- Try inserting identical key value pairs until a disk segment is created. Inspect the disk segment.
- The first disk segment will be near the
MT_MAX_SIZE because it will contain all of the unique key value pairs. The second disk segment will hold 1 key value pair and therefore be significantly smaller.
The solution should prevent the self.bytes from growing when the memtable does not grow. Memtables should be flushed when the MT_MAX_SIZE is reached.
Within the
setmethod of memtable, theself.bytes += len(k) + len(v)is performed without checking if the values already exist in the RB Tree. If the values already exist in the RB Tree, the RB tree will not grow, however self.bytes will be increased.The bug that this creates can be seen during flushing of a memtable to a disk segment.
To reproduce:
MT_MAX_SIZEto something small like 20.MT_MAX_SIZEbecause it will contain all of the unique key value pairs. The second disk segment will hold 1 key value pair and therefore be significantly smaller.The solution should prevent the self.bytes from growing when the memtable does not grow. Memtables should be flushed when the
MT_MAX_SIZEis reached.