Skip to content

Bytes count does not accurately represent size of RB Tree in memtable #31

Description

@anarmanafov1

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:

  1. Open the KVS file and set MT_MAX_SIZE to something small like 20.
  2. Create an instance of KVS.
  3. Try inserting varying key value pairs until a disk segment is created. Inspect the disk segment.
  4. Try inserting identical key value pairs until a disk segment is created. Inspect the disk segment.
  5. 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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions