|
4 | 4 | from typing import Dict, Any
|
5 | 5 |
|
6 | 6 | from core.file_io_manager import FileIOManager
|
| 7 | +from core.ssTable_manager import SSTableManager |
| 8 | +from schemas.sorted_set_table import SortedSetTable |
7 | 9 |
|
8 | 10 |
|
9 | 11 | class memTableManager:
|
10 | 12 | def __init__(self):
|
11 | 13 | self.wal_file = "D:\\HLD-Assignments\\NoSQL-Database-Simulation-Implementation\\persistent-storage\\wal_file.txt"
|
12 | 14 | self.file_io_manager = FileIOManager()
|
| 15 | + self.ssTableManager = SSTableManager() |
13 | 16 |
|
14 | 17 | 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 |
15 | 28 | self.wal_file = self.file_io_manager.openWAL(self.wal_file)
|
16 | 29 | reconstructed_mem_table = {}
|
| 30 | + i = 0 |
17 | 31 | for record in self.wal_file:
|
18 | 32 | if record != "":
|
19 | 33 | if record == "\n":
|
20 | 34 | continue
|
21 | 35 | 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 |
26 | 43 | else:
|
27 | 44 | return {}
|
28 |
| - |
29 | 45 | return reconstructed_mem_table
|
0 commit comments