this repo has no description
2
fork

Configure Feed

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

Remove dead code

garrison a11a02eb 61042f5d

-83
-79
lib/xks/manifest.ex
··· 187 187 } 188 188 end 189 189 190 - @spec list_overlapping_tables(t, non_neg_integer, non_neg_integer, {binary, non_neg_integer}, {binary, non_neg_integer}) :: [tuple] 191 - def list_overlapping_tables(manifest, epoch, level, start_key, end_key) do 192 - {sk_key, sk_ver} = start_key 193 - # Scan backwards to find the first table visible at `epoch` which is outside of the range (below) 194 - prev_key = 195 - case find_prev_table_key(manifest, epoch, level, start_key, {level, sk_key, sk_ver, epoch + 1}, false) do 196 - {:ok, key} -> key 197 - # If we hit the start of the level, we use a sentinel at epoch -1 198 - :error -> {level, "", 0, -1} 199 - end 200 - 201 - # Start the scan at the `prev_key` found above, which guarantees 202 - # that any overlapping tables will be found by `next()` 203 - scan_tables(manifest, epoch, level, end_key, prev_key, []) 204 - |> Enum.reverse() 205 - end 206 - 207 - # Scan backwards to find the key of the first table *below* (disjoint from) `start_key` that is visible at `epoch` 208 - # This key can then be used to start a forward scan and accumulate 209 - # 210 - # TODO: there is absolutely no way this is correct right now 211 - defp find_prev_table_key(manifest, epoch, level, start_key, prev_key, prev_tombstone?) do 212 - case :ets.prev_lookup(manifest, prev_key) do 213 - {key, _obj} when prev_tombstone? -> 214 - # The previous key we saw (i.e. the next key in the keyspace) was a tombstone, 215 - # so this entry has been deleted 216 - find_prev_table_key(manifest, epoch, level, start_key, key, false) 217 - 218 - {{^level, _k, _ver, ep} = key, _obj} when ep > epoch -> 219 - # This entry is not visible at `epoch` 220 - find_prev_table_key(manifest, epoch, level, start_key, key, false) 221 - 222 - {{^level, _k, _ver, _ep} = key, [{_key, :tombstone}]} -> 223 - # This entry is a tombstone, so we will ignore the next entry we see (which is previous in the keyspace) 224 - find_prev_table_key(manifest, epoch, level, start_key, key, true) 225 - 226 - {{^level, _k, _ver, _ep} = key, [{_key, {ek_key, ek_ver, _i, _ck, _id}}]} when {ek_key, ek_ver} > start_key -> 227 - # This table actually *contains* `start_key`: 228 - # - table_sk < start_key due to prev() 229 - # - table_ek > start_key due to guard 230 - # Therefore: sk < start_key < ek 231 - find_prev_table_key(manifest, epoch, level, start_key, key, false) 232 - 233 - {{^level, _k, _ver, _ep} = key, _obj} -> 234 - # This is the first table found which has an ek <= `start_key`, 235 - # which means it is the first table with a range *below* (disjoint) start_key 236 - {:ok, key} 237 - 238 - _ -> 239 - :error 240 - end 241 - end 242 - 243 - defp scan_tables(manifest, epoch, level, end_key, prev_key, acc) do 244 - case :ets.next_lookup(manifest, prev_key) do 245 - {{^level, _k, _ver, ep} = key, [{_key, _value}]} when ep > epoch -> 246 - # This entry is not visible at epoch 247 - scan_tables(manifest, epoch, level, end_key, key, acc) 248 - 249 - {{^level, _k, _ver, _ep} = key, [{_key, :tombstone}]} -> 250 - # This entry is a tombstone and cancels out the previous entry 251 - # TODO: assert that it was the same key? 252 - [_deleted | acc] = acc 253 - scan_tables(manifest, epoch, level, end_key, key, acc) 254 - 255 - {{^level, sk_key, sk_ver, _ep} = key, [{_key, value}]} when {sk_key, sk_ver} < end_key -> 256 - # This entry is visible and overlaps, accumulate 257 - {ek_key, ek_ver, block_index, block_checksum, _id} = value 258 - table = {:table, block_index, block_checksum, {sk_key, sk_ver}, {ek_key, ek_ver}} 259 - 260 - acc = [table | acc] 261 - scan_tables(manifest, epoch, level, end_key, key, acc) 262 - 263 - _ -> 264 - # Reached the end of either the ets table, the level, or the range (end_key) 265 - acc 266 - end 267 - end 268 - 269 190 @doc false 270 191 def dump(manifest) do 271 192 :ets.tab2list(manifest)
-4
lib/xks/xks.ex
··· 86 86 %XKS{manifest: manifest, block_store: block_store} = xks 87 87 epoch = :atomics.get(xks.epoch_atomic, 1) 88 88 89 - # start_key has version=0 because we have no way of knowing its latest version in the DB 90 - # end_key has version=0 because the end key is exclusive so we won't actually read it 91 - _tables = Manifest.list_overlapping_tables(manifest, epoch, 1, {start_key, 0}, {end_key, 0}) 92 - 93 89 memtable_iterators = 94 90 Manifest.list_memtables(xks.manifest, epoch) 95 91 |> Enum.map(fn {_id, memtable} ->