def __init__(self, sstable: SSTable) -> None: self.sstable = sstable self._pairs = kv_iter(sstable.path) try: self.current_pair: Tuple[str, Value] = next(self._pairs) except StopIteration: self.has_next = False else: self.has_next = True
def resume(cls, log_path): memtable = Memtable() # recover the memtable if necessary if path.exists(log_path): for key, value in kv_iter(log_path): if value == TOMBSTONE: memtable.unset(key) else: memtable.set(key, value) writer = KVWriter(log_path, append=True) else: writer = KVWriter(log_path) return cls(writer), memtable
def log() -> List[Tuple[str, str]]: """Get the commit log file contents. For debugging purposes.""" return list(kv_iter(LOG_PATH))
def test_merge_correctly_merges_files(files_pre_compaction): expected = list(kv_iter(f"{FIXTURES}/segment-0-compacted-expected.dat")) merged_file = SSTable.merge(files_pre_compaction) result = list(kv_iter(merged_file.path)) assert result == expected