mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-07-05 05:20:38 +00:00
59 lines
11 KiB
HTML
59 lines
11 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Region hook extension point for observing SST writes and manifest mutations."><title>mito2::engine::region_hook - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-17e0aaed.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="mito2" data-themes="" data-resource-suffix="" data-rustdoc-version="1.96.0-nightly (ac7f9ec7d 2026-03-20)" data-channel="nightly" data-search-js="search-63369b7b.js" data-stringdex-js="stringdex-2da4960a.js" data-settings-js="settings-170eb4bf.js" ><script src="../../../static.files/storage-41dd4d93.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-5013f961.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-f7c3ffd8.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><a class="skip-main-content" href="#main-content">Skip to main content</a><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Module region_hook</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../mito2/index.html">mito2</a><span class="version">1.2.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module region_<wbr>hook</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#design" title="Design">Design</a></li><li><a href="#coverage" title="Coverage">Coverage</a></li><li><a href="#invocation-points" title="Invocation points">Invocation points</a></li><li><a href="#future-work" title="Future work">Future work</a></li></ul><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In mito2::<wbr>engine</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content" tabindex="-1"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../index.html">mito2</a>::<wbr><a href="../index.html">engine</a></div><h1>Module <span>region_<wbr>hook</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/mito2/engine/region_hook.rs.html#15-221">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Region hook extension point for observing SST writes and manifest mutations.</p>
|
||
<h3 id="design"><a class="doc-anchor" href="#design">§</a>Design</h3>
|
||
<p>The <a href="trait.RegionHook.html" title="trait mito2::engine::region_hook::RegionHook"><code>RegionHook</code></a> trait provides two methods with clear separation of concerns:</p>
|
||
<ul>
|
||
<li>
|
||
<p><a href="trait.RegionHook.html#method.on_sst_files_written" title="method mito2::engine::region_hook::RegionHook::on_sst_files_written"><code>on_sst_files_written</code></a>: Fires when mito2 physically writes SST <strong>data files</strong>.
|
||
Provides per-file <a href="../../sst/parquet/struct.SstInfo.html" title="struct mito2::sst::parquet::SstInfo"><code>SstInfo</code></a> + <a href="../../sst/file/struct.FileMeta.html" title="struct mito2::sst::file::FileMeta"><code>FileMeta</code></a> — the richest available metadata
|
||
(row counts, index metadata, Parquet metadata, etc.).</p>
|
||
</li>
|
||
<li>
|
||
<p><a href="trait.RegionHook.html#method.on_manifest_updated" title="method mito2::engine::region_hook::RegionHook::on_manifest_updated"><code>on_manifest_updated</code></a>: Fires after <strong>any</strong> manifest write is successfully committed.
|
||
Receives the full <a href="../../manifest/action/struct.RegionMetaActionList.html" title="struct mito2::manifest::action::RegionMetaActionList"><code>RegionMetaActionList</code></a> so consumers can inspect what changed
|
||
(file additions/removals, schema changes, truncation, partition expression changes, etc.).</p>
|
||
</li>
|
||
</ul>
|
||
<p>Hook implementations are registered via the <a href="common_base::Plugins"><code>Plugins</code></a> system:</p>
|
||
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code>plugins.insert(Arc::new(MyHook) <span class="kw">as </span>RegionHookRef);</code></pre></div><h3 id="coverage"><a class="doc-anchor" href="#coverage">§</a>Coverage</h3><div><table><thead><tr><th>Scenario</th><th style="text-align: center"><code>on_sst_files_written</code></th><th style="text-align: center"><code>on_manifest_updated</code></th></tr></thead><tbody>
|
||
<tr><td>Flush (memtable → SST)</td><td style="text-align: center">✅ Yes</td><td style="text-align: center">✅ Yes</td></tr>
|
||
<tr><td>Local compaction</td><td style="text-align: center">✅ Yes</td><td style="text-align: center">✅ Yes</td></tr>
|
||
<tr><td>Remote compaction</td><td style="text-align: center">✅ (compactor node) ¹</td><td style="text-align: center">✅ (compactor node) ¹</td></tr>
|
||
<tr><td>RegionEdit / bulk ingestion</td><td style="text-align: center">❌ (files pre-written)</td><td style="text-align: center">✅ Yes</td></tr>
|
||
<tr><td>Copy region</td><td style="text-align: center">❌ (object-store copy)</td><td style="text-align: center">✅ Yes</td></tr>
|
||
<tr><td>Apply staging</td><td style="text-align: center">❌ (delegates to edit)</td><td style="text-align: center">✅ Yes ²</td></tr>
|
||
<tr><td>Alter (schema change)</td><td style="text-align: center">❌ (no SST files)</td><td style="text-align: center">✅ Yes</td></tr>
|
||
<tr><td>Truncate</td><td style="text-align: center">❌ (removes files)</td><td style="text-align: center">✅ Yes</td></tr>
|
||
<tr><td>Enter staging</td><td style="text-align: center">❌ (no SST files)</td><td style="text-align: center">✅ Yes</td></tr>
|
||
<tr><td>Async index build</td><td style="text-align: center">❌ (index files only)</td><td style="text-align: center">✅ Yes</td></tr>
|
||
</tbody></table>
|
||
</div>
|
||
<p>¹ Remote compaction runs on a dedicated compactor node via <code>open_compaction_region()</code>.
|
||
The caller must pass plugins via <code>OpenCompactionRegionRequest</code> to enable hooks on the
|
||
compactor node.
|
||
² Apply staging fires <code>on_manifest_updated</code> twice: once when the staging SST files are
|
||
committed via <code>RegionEdit</code>, and once when <code>exit_staging_on_success</code> merges all staged
|
||
manifest actions into the live manifest.</p>
|
||
<p>The following paths do <strong>not</strong> trigger any hook:</p>
|
||
<ul>
|
||
<li>Follower region sync / catchup (manifest read-only; followers don’t author changes)</li>
|
||
<li>GC / checkpoint / drop / remap (internal bookkeeping, not logical state changes)</li>
|
||
</ul>
|
||
<h3 id="invocation-points"><a class="doc-anchor" href="#invocation-points">§</a>Invocation points</h3>
|
||
<p><code>on_sst_files_written</code> is invoked at the SST write site (flush task or compaction task),
|
||
immediately after SST files are written but <strong>before</strong> the manifest is committed.</p>
|
||
<p><code>on_manifest_updated</code> is funneled through <a href="../../region/struct.ManifestContext.html#method.update_locked" title="method mito2::region::ManifestContext::update_locked"><code>ManifestContext::update_locked</code></a>,
|
||
the sole caller of the low-level <a href="../../manifest/manager/struct.RegionManifestManager.html#method.update" title="method mito2::manifest::manager::RegionManifestManager::update"><code>RegionManifestManager::update</code></a>, which
|
||
packages each successful write into a <a href="struct.PendingManifestHook.html" title="struct mito2::engine::region_hook::PendingManifestHook"><code>PendingManifestHook</code></a>. The caller
|
||
owns the write lock, drops it, and <em>then</em> fires the receipt — the hook must
|
||
never run under the lock. <a href="../../region/struct.ManifestContext.html#method.update_manifest" title="method mito2::region::ManifestContext::update_manifest"><code>ManifestContext::update_manifest</code></a> is the common
|
||
case: it acquires the lock, delegates to <code>update_locked</code>, and fires the
|
||
receipt in one go. Multi-step sequences (staging-exit, role-state backfill)
|
||
call <code>update_locked</code> directly under their own held guard.</p>
|
||
<p>Non-logical writes (GC, staging bookkeeping) call the manager’s own methods
|
||
directly and intentionally do not fire the hook.</p>
|
||
<h3 id="future-work"><a class="doc-anchor" href="#future-work">§</a>Future work</h3>
|
||
<p>A future <code>on_files_removed</code> hook may be added to observe file lifecycle end
|
||
(GC, drop, truncate, compaction removal). This is not yet implemented.</p>
|
||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.PendingManifestHook.html" title="struct mito2::engine::region_hook::PendingManifestHook">Pending<wbr>Manifest<wbr>Hook</a><span title="Restricted Visibility"> 🔒</span> </dt><dd>A deferred <a href="trait.RegionHook.html#method.on_manifest_updated" title="method mito2::engine::region_hook::RegionHook::on_manifest_updated"><code>RegionHook::on_manifest_updated</code></a> notification produced by a
|
||
logical manifest write via <a href="../../region/struct.ManifestContext.html#method.update_locked" title="method mito2::region::ManifestContext::update_locked"><code>ManifestContext::update_locked</code></a>.</dd><dt><a class="struct" href="struct.SstFileInfo.html" title="struct mito2::engine::region_hook::SstFileInfo">SstFile<wbr>Info</a></dt><dd>Information about a single SST data file written during flush or compaction.</dd></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.RegionHook.html" title="trait mito2::engine::region_hook::RegionHook">Region<wbr>Hook</a></dt><dd>Hook for observing region mutations in mito2.</dd></dl><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><dl class="item-table"><dt><a class="type" href="type.RegionHookRef.html" title="type mito2::engine::region_hook::RegionHookRef">Region<wbr>Hook<wbr>Ref</a></dt></dl></section></div></main></body></html> |