this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Garbage-collect deleted memtables

garrison ba0dab8d bacf461e

+32 -12
+12 -2
lib/xks/manifest.ex
··· 71 71 {partition, level, first_key, epoch_min} 72 72 end 73 73 74 + defp deleted_key_for(%MemtableInfo{epoch_max: epoch_max} = info), do: {:deleted_table, epoch_max, key_for(info)} 75 + defp deleted_key_for(%TableInfo{epoch_max: epoch_max} = info), do: {:deleted_table, epoch_max, key_for(info)} 76 + 74 77 @spec new :: t 75 78 def new do 76 79 table = :ets.new(__MODULE__, [:ordered_set, :protected]) ··· 88 91 def insert_memtable(manifest, %MemtableInfo{} = info, at_version) do 89 92 # TODO: maybe add `smallest_version` to MemtableInfo instead of passing `at_version` 90 93 assert is_integer(info.partition) 94 + assert info.epoch_max == :infinity 95 + 91 96 :ets.insert(manifest, {key_for(info), info}) 92 97 93 98 partition = info.partition ··· 146 151 case :ets.lookup(manifest, key) do 147 152 [{_key, %MemtableInfo{} = info}] -> 148 153 assert info.epoch_max == :infinity 154 + 155 + # Mark memtable as deleted by updating `epoch_max` 149 156 info = %{info | epoch_max: at_epoch} 150 157 :ets.insert(manifest, {key, info}) 151 158 159 + # Add memtable to index of deleted tables 160 + :ets.insert(manifest, {deleted_key_for(info), nil}) 161 + 152 162 [] -> 153 163 raise "Memtable #{inspect(delete_info)} not found" 154 164 end ··· 192 202 end 193 203 194 204 defp count_key_for(%TableInfo{partition: partition, level: level}), do: {:level_table_count, partition, level} 195 - defp deleted_key_for(%TableInfo{epoch_max: epoch_max} = info), do: {:deleted_table, epoch_max, key_for(info)} 196 205 197 206 @spec get_table_count_for_level(t, integer, non_neg_integer) :: non_neg_integer 198 207 def get_table_count_for_level(manifest, partition, level) do ··· 236 245 defp do_pop_deleted(manifest, up_to_epoch_max, prev_key, acc) do 237 246 case :ets.next(manifest, prev_key) do 238 247 {:deleted_table, ep_max, table_key} = key when ep_max <= up_to_epoch_max -> 239 - [{_key, %TableInfo{} = info}] = :ets.lookup(manifest, table_key) 248 + [{_key, info}] = :ets.lookup(manifest, table_key) 249 + assert is_struct(info, MemtableInfo) or is_struct(info, TableInfo) 240 250 241 251 :ets.delete(manifest, key) 242 252 :ets.delete(manifest, table_key)
+6
lib/xks/memtable.ex
··· 8 8 :ets.new(__MODULE__, [:ordered_set, :protected]) 9 9 end 10 10 11 + @spec destroy(t) :: :ok 12 + def destroy(memtable) do 13 + :ets.delete(memtable) 14 + :ok 15 + end 16 + 11 17 @spec apply_mutations(XKS.t, t, integer, non_neg_integer, list) :: non_neg_integer 12 18 def apply_mutations(%XKS{} = xks, memtable, partition, version, mutations) when is_integer(version) and is_list(mutations) do 13 19 do_apply(mutations, xks, memtable, partition, version, 0)
+14 -10
lib/xks/xks.ex
··· 1 1 defmodule Hobbes.XKS do 2 2 alias Hobbes.XKS 3 3 alias Hobbes.XKS.{MemoryStore, FileStore, Superblock, FreeList, Manifest, ManifestLog, WAL, WorkQueue, Memtable, Merge, Compaction, Table} 4 - alias Hobbes.XKS.Manifest.MemtableInfo 4 + alias Hobbes.XKS.Manifest.{MemtableInfo, TableInfo} 5 5 6 6 alias Trinity.{Sim, SimProcess} 7 7 ··· 428 428 epoch = :atomics.get(epoch_atomic, 1) 429 429 430 430 removed_tables = Manifest.pop_deleted_tables(manifest, epoch) 431 - Enum.each(removed_tables, fn table_info -> 432 - case table_info.last_block_address do 433 - # TODO: remove this hack, needed because ManifestLogFuzz tables have fake blocks 434 - {0, _} -> :noop 435 - _ -> Table.release_table(block_store, free_list, table_info) 436 - end 437 - ManifestLog.delete_table(manifest_log, table_info) 431 + Enum.each(removed_tables, fn 432 + %MemtableInfo{} = info -> 433 + :ok = Memtable.destroy(info.memtable) 434 + 435 + %TableInfo{} = table_info -> 436 + case table_info.last_block_address do 437 + # TODO: remove this hack, needed because ManifestLogFuzz tables have fake blocks 438 + {0, _} -> :noop 439 + _ -> :ok = Table.release_table(block_store, free_list, table_info) 440 + end 441 + :ok = ManifestLog.delete_table(manifest_log, table_info) 438 442 end) 439 443 :ok 440 444 end ··· 779 783 %Manifest.MemtableInfo{} = memtable -> 780 784 Manifest.delete_memtable(manifest, memtable, new_epoch) 781 785 782 - %Manifest.TableInfo{} = table -> 786 + %TableInfo{} = table -> 783 787 deleted_info = Manifest.delete_table(manifest, table, new_epoch) 784 788 ManifestLog.update_table(manifest_log, deleted_info) 785 789 end) ··· 794 798 Enum.each(left_over_block_indexes, &FreeList.release_block(free_list, &1)) 795 799 796 800 # Insert table 797 - table_info = %Manifest.TableInfo{ 801 + table_info = %TableInfo{ 798 802 partition: partition, 799 803 level: output_level, 800 804 epoch: new_epoch,