You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2026/09/22 12:11:29 UTC
[S] Change in asterixdb[totoro]: [ASTERIXDB-3879][STO] Cache the latest index checkpoint
From Michael Blow <mb...@apache.org>:
Michael Blow has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21861?usp=email )
Change subject: [ASTERIXDB-3879][STO] Cache the latest index checkpoint
......................................................................
[ASTERIXDB-3879][STO] Cache the latest index checkpoint
- user model changes: no
- storage format changes: no
- interface changes: no
Details: Every read of an index's latest checkpoint lists the index
directory, reads and parses each checkpoint file found, and sorts them.
That runs on each flush, once per index, and again on each low watermark
query.
Keep the latest checkpoint in memory instead, as last read or written.
An IndexCheckpointManager is the only writer of its index's checkpoint
files -- one instance is cached per index path, and replication reaches
them through delete() and init() on that same instance -- so a write
whose read-back verification succeeded is authoritative and need not be
re-read. The cache is dropped before a write and only restored once that
verification passes, so a failed write falls back to reading the disk.
Ext-ref: MB-74008
Co-Authored-By: Claude Opus 5 <no...@anthropic.com>
Change-Id: Ib5a4a9e63aaf3d3926dbfe92e5cc3cfb3ad0a139
---
M asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/IndexCheckpointManager.java
1 file changed, 14 insertions(+), 1 deletion(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/61/21861/1
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/IndexCheckpointManager.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/IndexCheckpointManager.java
index 34f0cb1..7f39cf9 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/IndexCheckpointManager.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/IndexCheckpointManager.java
@@ -35,6 +35,7 @@
import org.apache.asterix.common.utils.StorageConstants;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.storage.am.lsm.common.impls.AbstractLSMIndexFileManager;
+import org.apache.hyracks.util.annotations.AiProvenance;
import org.apache.hyracks.util.annotations.ThreadSafe;
import org.apache.hyracks.util.file.FileUtil;
import org.apache.logging.log4j.LogManager;
@@ -50,6 +51,11 @@
(file, name) -> name.startsWith(StorageConstants.INDEX_CHECKPOINT_FILE_PREFIX);
private static final long BULKLOAD_LSN = 0;
private final Path indexPath;
+ // the latest checkpoint, as last read or written by this manager; null until read, and whenever a write left the
+ // on-disk state in doubt. this manager is the only writer of an index's checkpoint files- replication goes through
+ // delete()/init() on this same instance- so a successful write is authoritative and need not be re-read
+ @AiProvenance(agent = AiProvenance.Agent.CLAUDE_OPUS_5, tool = AiProvenance.Tool.CLAUDE_CODE_CLI, contributionKind = AiProvenance.ContributionKind.GENERATED, notes = "In-memory cache of the latest checkpoint, maintained by getLatest(), persist() and delete()")
+ private IndexCheckpoint latest;
public IndexCheckpointManager(Path indexPath) {
this.indexPath = indexPath;
@@ -124,6 +130,7 @@
@Override
public synchronized void delete() {
+ latest = null;
deleteHistory(Long.MAX_VALUE, 0);
}
@@ -151,6 +158,9 @@
@Override
public synchronized IndexCheckpoint getLatest() throws HyracksDataException {
+ if (latest != null) {
+ return latest;
+ }
List<IndexCheckpoint> checkpoints;
try {
checkpoints = getCheckpoints();
@@ -163,7 +173,8 @@
throw new IllegalStateException("Couldn't find any checkpoints for resource: " + indexPath);
}
checkpoints.sort(Comparator.comparingLong(IndexCheckpoint::getId).reversed());
- return checkpoints.get(0);
+ latest = checkpoints.get(0);
+ return latest;
}
@Override
@@ -204,6 +215,7 @@
private void persist(IndexCheckpoint checkpoint) throws HyracksDataException {
final Path checkpointPath = getCheckpointPath(checkpoint);
+ latest = null;
for (int i = 1; i <= MAX_CHECKPOINT_WRITE_ATTEMPTS; i++) {
try {
// clean up from previous write failure
@@ -213,6 +225,7 @@
FileUtil.writeAndForce(checkpointPath, checkpoint.asJson().getBytes());
// ensure it was written correctly by reading it
read(checkpointPath);
+ latest = checkpoint;
return;
} catch (ClosedByInterruptException e) {
LOGGER.info("interrupted while writing checkpoint at {}", checkpointPath);
--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21861?usp=email
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: totoro
Gerrit-Change-Id: Ib5a4a9e63aaf3d3926dbfe92e5cc3cfb3ad0a139
Gerrit-Change-Number: 21861
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Blow <mb...@apache.org>