blob: 75c163dbb62b2fce0e63fab3ba54478c619a3f27 [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (17) -->
<title>VersionedKeyValueStore (kafka 3.5.2 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="declaration: package: org.apache.kafka.streams.state, interface: VersionedKeyValueStore">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../script-dir/jquery-ui.min.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../jquery-ui.overrides.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
<script type="text/javascript" src="../../../../../script-dir/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="../../../../../script-dir/jquery-ui.min.js"></script>
</head>
<body class="class-declaration-page">
<script type="text/javascript">var evenRowColor = "even-row-color";
var oddRowColor = "odd-row-color";
var tableTab = "table-tab";
var activeTableTab = "active-table-tab";
var pathtoroot = "../../../../../";
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<div class="flex-box">
<header role="banner" class="flex-header">
<nav role="navigation">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="top-nav" id="navbar-top">
<div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div>
<ul id="navbar-top-firstrow" class="nav-list" title="Navigation">
<li><a href="../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="nav-bar-cell1-rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html#class">Help</a></li>
</ul>
</div>
<div class="sub-nav">
<div>
<ul class="sub-nav-list">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li><a href="#field-summary">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method-summary">Method</a></li>
</ul>
<ul class="sub-nav-list">
<li>Detail:&nbsp;</li>
<li><a href="#field-detail">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method-detail">Method</a></li>
</ul>
</div>
<div class="nav-list-search"><label for="search-input">SEARCH:</label>
<input type="text" id="search-input" value="search" disabled="disabled">
<input type="reset" id="reset-button" value="reset" disabled="disabled">
</div>
</div>
<!-- ========= END OF TOP NAVBAR ========= -->
<span class="skip-nav" id="skip-navbar-top"></span></nav>
</header>
<div class="flex-content">
<main role="main">
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="sub-title"><span class="package-label-in-type">Package</span>&nbsp;<a href="package-summary.html">org.apache.kafka.streams.state</a></div>
<h1 title="Interface VersionedKeyValueStore" class="title">Interface VersionedKeyValueStore&lt;K,<wbr>V&gt;</h1>
</div>
<section class="class-description" id="class-description">
<dl class="notes">
<dt>Type Parameters:</dt>
<dd><code>K</code> - The key type</dd>
<dd><code>V</code> - The value type</dd>
</dl>
<dl class="notes">
<dt>All Superinterfaces:</dt>
<dd><code><a href="../processor/StateStore.html" title="interface in org.apache.kafka.streams.processor">StateStore</a></code></dd>
</dl>
<hr>
<div class="type-signature"><span class="modifiers">public interface </span><span class="element-name type-name-label">VersionedKeyValueStore&lt;K,<wbr>V&gt;</span><span class="extends-implements">
extends <a href="../processor/StateStore.html" title="interface in org.apache.kafka.streams.processor">StateStore</a></span></div>
<div class="block">A key-value store that stores multiple record versions per key, and supports timestamp-based
retrieval operations to return the latest record (per key) as of a specified timestamp.
Only one record is stored per key and timestamp, i.e., a second call to
<a href="#put(K,V,long)"><code>put(Object, Object, long)</code></a> with the same key and timestamp will replace the first.
<p>
Each store instance has an associated, fixed-duration "history retention" which specifies
how long old record versions should be kept for. In particular, a versioned store guarantees
to return accurate results for calls to <a href="#get(K,long)"><code>get(Object, long)</code></a> where the provided timestamp
bound is within history retention of the current observed stream time. (Queries with timestamp
bound older than the specified history retention are considered invalid.)
<p>
The store's "history retention" also doubles as its "grace period," which determines how far
back in time writes to the store will be accepted. A versioned store will not accept writes
(inserts, updates, or deletions) if the timestamp associated with the write is older than the
current observed stream time by more than the grace period.</div>
</section>
<section class="summary">
<ul class="summary-list">
<!-- =========== FIELD SUMMARY =========== -->
<li>
<section class="field-summary" id="field-summary">
<h2>Field Summary</h2>
<div class="caption"><span>Fields</span></div>
<div class="summary-table three-column-summary">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Field</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color"><code>static final long</code></div>
<div class="col-second even-row-color"><code><a href="#PUT_RETURN_CODE_NOT_PUT" class="member-name-link">PUT_RETURN_CODE_NOT_PUT</a></code></div>
<div class="col-last even-row-color">&nbsp;</div>
<div class="col-first odd-row-color"><code>static final long</code></div>
<div class="col-second odd-row-color"><code><a href="#PUT_RETURN_CODE_VALID_TO_UNDEFINED" class="member-name-link">PUT_RETURN_CODE_VALID_TO_UNDEFINED</a></code></div>
<div class="col-last odd-row-color">&nbsp;</div>
</div>
</section>
</li>
<!-- ========== METHOD SUMMARY =========== -->
<li>
<section class="method-summary" id="method-summary">
<h2>Method Summary</h2>
<div id="method-summary-table">
<div class="table-tabs" role="tablist" aria-orientation="horizontal"><button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-controls="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table', 3)" class="active-table-tab">All Methods</button><button id="method-summary-table-tab2" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab2', 3)" class="table-tab">Instance Methods</button><button id="method-summary-table-tab3" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab3', 3)" class="table-tab">Abstract Methods</button></div>
<div id="method-summary-table.tabpanel" role="tabpanel">
<div class="summary-table three-column-summary" aria-labelledby="method-summary-table-tab0">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Method</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="VersionedRecord.html" title="class in org.apache.kafka.streams.state">VersionedRecord</a>&lt;<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">V</a>&gt;</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#delete(K,long)" class="member-name-link">delete</a><wbr>(<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">K</a>&nbsp;key,
long&nbsp;timestamp)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Delete the value associated with this key from the store, at the specified timestamp
(if there is such a value), and return the deleted value.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="VersionedRecord.html" title="class in org.apache.kafka.streams.state">VersionedRecord</a>&lt;<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">V</a>&gt;</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#get(K)" class="member-name-link">get</a><wbr>(<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">K</a>&nbsp;key)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Get the current (i.e., latest by timestamp) record associated with this key.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="VersionedRecord.html" title="class in org.apache.kafka.streams.state">VersionedRecord</a>&lt;<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">V</a>&gt;</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#get(K,long)" class="member-name-link">get</a><wbr>(<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">K</a>&nbsp;key,
long&nbsp;asOfTimestamp)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Get the record associated with this key as of the specified timestamp (i.e.,
the existing record with the largest timestamp not exceeding the provided
timestamp bound).</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code>long</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3"><code><a href="#put(K,V,long)" class="member-name-link">put</a><wbr>(<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">K</a>&nbsp;key,
<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">V</a>&nbsp;value,
long&nbsp;timestamp)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab3">
<div class="block">Add a new record version associated with the specified key and timestamp.</div>
</div>
</div>
</div>
</div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-org.apache.kafka.streams.processor.StateStore">Methods inherited from interface&nbsp;org.apache.kafka.streams.processor.<a href="../processor/StateStore.html" title="interface in org.apache.kafka.streams.processor">StateStore</a></h3>
<code><a href="../processor/StateStore.html#close()">close</a>, <a href="../processor/StateStore.html#flush()">flush</a>, <a href="../processor/StateStore.html#getPosition()">getPosition</a>, <a href="../processor/StateStore.html#init(org.apache.kafka.streams.processor.ProcessorContext,org.apache.kafka.streams.processor.StateStore)">init</a>, <a href="../processor/StateStore.html#init(org.apache.kafka.streams.processor.StateStoreContext,org.apache.kafka.streams.processor.StateStore)">init</a>, <a href="../processor/StateStore.html#isOpen()">isOpen</a>, <a href="../processor/StateStore.html#name()">name</a>, <a href="../processor/StateStore.html#persistent()">persistent</a>, <a href="../processor/StateStore.html#query(org.apache.kafka.streams.query.Query,org.apache.kafka.streams.query.PositionBound,org.apache.kafka.streams.query.QueryConfig)">query</a></code></div>
</section>
</li>
</ul>
</section>
<section class="details">
<ul class="details-list">
<!-- ============ FIELD DETAIL =========== -->
<li>
<section class="field-details" id="field-detail">
<h2>Field Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="PUT_RETURN_CODE_VALID_TO_UNDEFINED">
<h3>PUT_RETURN_CODE_VALID_TO_UNDEFINED</h3>
<div class="member-signature"><span class="modifiers">static final</span>&nbsp;<span class="return-type">long</span>&nbsp;<span class="element-name">PUT_RETURN_CODE_VALID_TO_UNDEFINED</span></div>
<dl class="notes">
<dt>See Also:</dt>
<dd>
<ul class="see-list">
<li><a href="../../../../../constant-values.html#org.apache.kafka.streams.state.VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED">Constant Field Values</a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="PUT_RETURN_CODE_NOT_PUT">
<h3>PUT_RETURN_CODE_NOT_PUT</h3>
<div class="member-signature"><span class="modifiers">static final</span>&nbsp;<span class="return-type">long</span>&nbsp;<span class="element-name">PUT_RETURN_CODE_NOT_PUT</span></div>
<dl class="notes">
<dt>See Also:</dt>
<dd>
<ul class="see-list">
<li><a href="../../../../../constant-values.html#org.apache.kafka.streams.state.VersionedKeyValueStore.PUT_RETURN_CODE_NOT_PUT">Constant Field Values</a></li>
</ul>
</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
<!-- ============ METHOD DETAIL ========== -->
<li>
<section class="method-details" id="method-detail">
<h2>Method Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="put(K,V,long)">
<h3 id="put(java.lang.Object,java.lang.Object,long)">put</h3>
<div class="member-signature"><span class="return-type">long</span>&nbsp;<span class="element-name">put</span><wbr><span class="parameters">(<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">K</a>&nbsp;key,
<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">V</a>&nbsp;value,
long&nbsp;timestamp)</span></div>
<div class="block">Add a new record version associated with the specified key and timestamp.
<p>
If the timestamp associated with the new record version is older than the store's
grace period (i.e., history retention) relative to the current observed stream time,
then the record will not be added.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>key</code> - The key</dd>
<dd><code>value</code> - The value, it can be <code>null</code>. <code>null</code> is interpreted as a delete.</dd>
<dd><code>timestamp</code> - The timestamp for this record version</dd>
<dt>Returns:</dt>
<dd>The validTo timestamp of the newly put record. Two special values, <code>-1</code> and
<code>Long.MIN_VALUE</code> carry specific meanings. <code>-1</code> indicates that the
record that was put is the latest record version for its key, and therefore the
validTo timestamp is undefined. <code>Long.MIN_VALUE</code> indicates that the record
was not put, due to grace period having been exceeded.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/NullPointerException.html" title="class or interface in java.lang" class="external-link">NullPointerException</a></code> - If <code>null</code> is used for key.</dd>
<dd><code><a href="../errors/InvalidStateStoreException.html" title="class in org.apache.kafka.streams.errors">InvalidStateStoreException</a></code> - if the store is not initialized</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="delete(K,long)">
<h3 id="delete(java.lang.Object,long)">delete</h3>
<div class="member-signature"><span class="return-type"><a href="VersionedRecord.html" title="class in org.apache.kafka.streams.state">VersionedRecord</a>&lt;<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">V</a>&gt;</span>&nbsp;<span class="element-name">delete</span><wbr><span class="parameters">(<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">K</a>&nbsp;key,
long&nbsp;timestamp)</span></div>
<div class="block">Delete the value associated with this key from the store, at the specified timestamp
(if there is such a value), and return the deleted value.
<p>
If the timestamp associated with this deletion is older than the store's grace period
(i.e., history retention) relative to the current observed stream time, then the deletion
will not be performed and <code>null</code> will be returned.
<p>
As a consequence of the above, the way to delete a record version is <it>not</it>
to first call <a href="#get(K)"><code>#get(key)</code></a> or <a href="#get(K,long)"><code>#get(key, timestamp)</code></a>
and use the returned <a href="VersionedRecord.html#timestamp()"><code>VersionedRecord.timestamp()</code></a> in a call to this
<code>delete(key, timestamp)</code> method, as the returned timestamp may be older than
the store's grace period (i.e., history retention) and will therefore not take place.
Instead, you should pass a business logic inferred timestamp that specifies when
the delete actually happens. For example, it could be the timestamp of the currently
processed input record or the current stream time.
<p>
This operation is semantically equivalent to <a href="#get(K,long)"><code>#get(key, timestamp)</code></a>
followed by <a href="#put(K,V,long)"><code>#put(key, null, timestamp)</code></a>, with
a caveat that if the deletion timestamp is older than the store's grace period
(i.e., history retention) then the return value is always <code>null</code>, regardless
of what <a href="#get(K,long)"><code>#get(key, timestamp)</code></a> would return.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>key</code> - The key</dd>
<dd><code>timestamp</code> - The timestamp for this delete</dd>
<dt>Returns:</dt>
<dd>The value and timestamp of the record associated with this key as of
the deletion timestamp (inclusive), or <code>null</code> if no such record exists
(including if the deletion timestamp is older than this store's history
retention time, i.e., the store no longer contains data for the provided
timestamp). Note that the record timestamp <code>r.timestamp()</code> of the
returned <a href="VersionedRecord.html" title="class in org.apache.kafka.streams.state"><code>VersionedRecord</code></a> may be smaller than the provided deletion
timestamp.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/NullPointerException.html" title="class or interface in java.lang" class="external-link">NullPointerException</a></code> - If <code>null</code> is used for key.</dd>
<dd><code><a href="../errors/InvalidStateStoreException.html" title="class in org.apache.kafka.streams.errors">InvalidStateStoreException</a></code> - if the store is not initialized</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="get(K)">
<h3 id="get(java.lang.Object)">get</h3>
<div class="member-signature"><span class="return-type"><a href="VersionedRecord.html" title="class in org.apache.kafka.streams.state">VersionedRecord</a>&lt;<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">V</a>&gt;</span>&nbsp;<span class="element-name">get</span><wbr><span class="parameters">(<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">K</a>&nbsp;key)</span></div>
<div class="block">Get the current (i.e., latest by timestamp) record associated with this key.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>key</code> - The key to fetch</dd>
<dt>Returns:</dt>
<dd>The value and timestamp of the current record associated with this key, or
<code>null</code> if there is no current record for this key.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/NullPointerException.html" title="class or interface in java.lang" class="external-link">NullPointerException</a></code> - If null is used for key.</dd>
<dd><code><a href="../errors/InvalidStateStoreException.html" title="class in org.apache.kafka.streams.errors">InvalidStateStoreException</a></code> - if the store is not initialized</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="get(K,long)">
<h3 id="get(java.lang.Object,long)">get</h3>
<div class="member-signature"><span class="return-type"><a href="VersionedRecord.html" title="class in org.apache.kafka.streams.state">VersionedRecord</a>&lt;<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">V</a>&gt;</span>&nbsp;<span class="element-name">get</span><wbr><span class="parameters">(<a href="VersionedKeyValueStore.html" title="type parameter in VersionedKeyValueStore">K</a>&nbsp;key,
long&nbsp;asOfTimestamp)</span></div>
<div class="block">Get the record associated with this key as of the specified timestamp (i.e.,
the existing record with the largest timestamp not exceeding the provided
timestamp bound).</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>key</code> - The key to fetch</dd>
<dd><code>asOfTimestamp</code> - The timestamp bound. This bound is inclusive; if a record
(for the specified key) exists with this timestamp, then
this is the record that will be returned.</dd>
<dt>Returns:</dt>
<dd>The value and timestamp of the record associated with this key
as of the provided timestamp, or <code>null</code> if no such record exists
(including if the provided timestamp bound is older than this store's history
retention time, i.e., the store no longer contains data for the provided
timestamp). Note that the record timestamp <code>r.timestamp()</code> of the
returned <a href="VersionedRecord.html" title="class in org.apache.kafka.streams.state"><code>VersionedRecord</code></a> may be smaller than the provided timestamp
bound. Additionally, if the latest record version for the key is eligible
for the provided timestamp bound, then that record will be returned even if
the timestamp bound is older than the store's history retention.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/NullPointerException.html" title="class or interface in java.lang" class="external-link">NullPointerException</a></code> - If null is used for key.</dd>
<dd><code><a href="../errors/InvalidStateStoreException.html" title="class in org.apache.kafka.streams.errors">InvalidStateStoreException</a></code> - if the store is not initialized</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
</ul>
</section>
<!-- ========= END OF CLASS DATA ========= -->
</main>
</div>
</div>
</body>
</html>