Skip to content

Commit 4998f7d

Browse files
committed
Merge branch 'v1.0.0-Basic-Implementation'
2 parents ed6b8b9 + fd1f0fa commit 4998f7d

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

core/memTable_manager.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,42 @@
44
from typing import Dict, Any
55

66
from core.file_io_manager import FileIOManager
7+
from core.ssTable_manager import SSTableManager
8+
from schemas.sorted_set_table import SortedSetTable
79

810

911
class memTableManager:
1012
def __init__(self):
1113
self.wal_file = "D:\\HLD-Assignments\\NoSQL-Database-Simulation-Implementation\\persistent-storage\\wal_file.txt"
1214
self.file_io_manager = FileIOManager()
15+
self.ssTableManager = SSTableManager()
1316

1417
def reconstructMemTable(self):
18+
19+
last_ssTable_id = self.ssTableManager.retrieve_last_id_from_id_file()
20+
final_ssTable = SortedSetTable
21+
if last_ssTable_id is not None:
22+
ssTableList = self.ssTableManager.read_sstables(last_ssTable_id)
23+
for ssTable in ssTableList:
24+
if ssTable.SSTableId == last_ssTable_id:
25+
final_ssTable = ssTable
26+
27+
lastSSTable_timeStamp = final_ssTable.timestamp
1528
self.wal_file = self.file_io_manager.openWAL(self.wal_file)
1629
reconstructed_mem_table = {}
30+
i = 0
1731
for record in self.wal_file:
1832
if record != "":
1933
if record == "\n":
2034
continue
2135
list_of_strings = record.split(" ")
22-
operation = list_of_strings[2]
23-
key = list_of_strings[3]
24-
value = list_of_strings[4]
25-
reconstructed_mem_table[operation] = {"key": key, "value": value}
36+
timeStamp = list_of_strings[0] + " " + list_of_strings[1]
37+
if timeStamp > lastSSTable_timeStamp:
38+
operation = list_of_strings[2]
39+
key = list_of_strings[3]
40+
value = list_of_strings[4].rstrip("\n")
41+
reconstructed_mem_table[operation + str(i)] = {"key": key, "value": value}
42+
i+=1
2643
else:
2744
return {}
28-
2945
return reconstructed_mem_table

core/ssTable_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def read_sstables(self, ss_table_id):
4444
for line in data:
4545
if line != "":
4646
current_sst_table = self.parse_ss_table(line)
47-
if current_sst_table != None:
47+
if current_sst_table is not None:
4848
ss_tables.append(current_sst_table)
4949
return ss_tables
5050

0 commit comments

Comments
 (0)