Packages
cubdb
0.13.0
2.0.2
2.0.1
2.0.0
2.0.0-rc.1
1.1.0
1.0.0
1.0.0-rc.10
1.0.0-rc.9
1.0.0-rc.8
1.0.0-rc.7
1.0.0-rc.6
1.0.0-rc.5
1.0.0-rc.4
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
0.17.0
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.0
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.0
0.9.0
0.8.0
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
A pure-Elixir embedded key-value database
Current section
Files
Jump to
Current section
Files
lib/cubdb/compactor.ex
defmodule CubDB.Compactor do
@moduledoc false
# The `CubDB.Compactor` module takes care of the compaction operation, to
# reclaim disk space. It does so by loading all entries in a new store (using
# the fast algorithm provided by `Btree.load/2`). This will cause the new
# store to only contain the entries reachable from the current root.
#
# Compaction runs in the background and does not block read/write operations.
# This module only takes care of loading the compacted entries in the new
# store, and then reports back to the caller. Subsequent steps in the
# compaction process (catching up with updates performed during compaction,
# swapping the store, cleaning up old files) are performed by other modules
# and coordinated by the main db process.
use Task
alias CubDB.Btree
alias CubDB.Store
@spec start_link(pid, Btree.t(), Store.File.t()) :: {:ok, pid}
def start_link(caller, btree, store) do
Task.start_link(__MODULE__, :run, [caller, btree, store])
end
@spec run(pid, Btree.t(), Store.File.t()) :: :ok
def run(caller, btree, store) do
compacted_btree = Btree.load(btree, store)
Btree.sync(compacted_btree)
send(caller, {:compaction_completed, btree, compacted_btree})
end
end