Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions engine/src/main/java/com/arcadedb/engine/NodeLocalFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
*/
package com.arcadedb.engine;

import com.arcadedb.index.vector.LSMVectorIndexGraphFile;
import com.arcadedb.index.vector.LSMVectorIndexGraphManifest;
import com.arcadedb.index.vector.LSMVectorIndexOrdinalMapFile;
import com.arcadedb.index.vector.LSMVectorIndexPQFile;
import com.arcadedb.schema.LocalSchema;

/**
Expand All @@ -36,6 +40,19 @@
* Analytical View's persisted CSR and contraction-hierarchy orders. A cache of data the database already holds, written
* at close and - in a replicated database - only on the leader, so a cluster has one on the current leader, a stale one
* wherever leadership used to be and none elsewhere.</li>
* <li>An LSM vector index's proximity graph and everything derived from it (issue #9751): the {@code .vecgraph}
* component, its {@code .vecgraphfp} manifest and {@code .vecordmap} ordinal map, and the {@code .vecpq} product
* quantization. Every node builds its own graph, on the inner database instance and without the WAL (issues #8292,
* #8905), from the vectors the index pages DO replicate, so the graph pages carry different bytes on every node - the
* JVector build is parallel and not deterministic - and the PQ codebooks are trained from the same node-local pass.
* The three plain side files are not shipped by a snapshot at all; the {@code .vecgraph} component is (it is a
* registered page file), without the manifest beside it (issue #9758). A divergence in any of them is a cache that
* differs, never data that does: the vectors themselves live in the index's own pages, which ARE compared.</li>
* <li>{@link TransactionManager#LAST_TX_ID_FILE_NAME}: the recency marker, holding the highest transaction id this
* node had assigned the last time it rotated its WAL or closed (issue #5277). A snapshot ships a synthesized copy, but
* on a live node the file is rewritten at moments that are this node's own, so two healthy peers at the same commit
* routinely hold different values - or one holds none (issue #9751). Node-local here means "not comparable", not
* "never shipped".</li>
* </ul>
* A new engine side file that is not replicated content belongs here. {@code Issue9638NodeLocalFilesChecksumTest} in
* {@code ha-raft} drives a real database through its writers and fails on a file that is neither shipped by a snapshot
Expand All @@ -53,16 +70,40 @@ private NodeLocalFiles() {
/**
* True when {@code fileName} (a name, never a path) is one of the node-local files above. Matched by exact name or by
* the full prefix-plus-extension shape, never by a substring, so a component file of a type named {@code gav-x} or
* {@code statistics} is still data: a component file's name always ends with its own extension, which is neither of
* the two below. The shapes describe the files the engine itself creates; a user file dropped into the directory that
* happens to take one of them (say {@code gav-notes.csr}) is left out too, which is harmless because nothing in the
* database reads or ships it.
* {@code statistics} is still data: a component file's name always ends with its own extension, and the only component
* extension matched below is the vector graph's own {@code .vecgraph}. The shapes describe the files the engine
* itself creates; a user file dropped into the directory that happens to take one of them (say {@code gav-notes.csr})
* is left out too, which is harmless because nothing in the database reads or ships it.
* <p>
* <b>"Node-local" answers "may two healthy copies differ here?", not "is it shipped?".</b> The {@code .vecgraph}
* component and {@code last-tx-id.bin} are both node-local and both carried by an HA snapshot, so a caller deciding
* what to SHIP or BACK UP must not use this method to skip files.
*/
public static boolean isNodeLocalFileName(final String fileName) {
return fileName.equals(LocalSchema.STATISTICS_FILE_NAME)
|| fileName.equals(LocalSchema.CACHED_COUNT_FILE_NAME_LEGACY)
|| fileName.equals(DATABASE_LOCK_FILE_NAME)
|| fileName.equals(TransactionManager.LAST_TX_ID_FILE_NAME)
|| isVectorGraphFileName(fileName)
|| (fileName.startsWith(GAV_CSR_FILE_PREFIX)
&& (fileName.endsWith(GAV_CSR_FILE_EXTENSION) || fileName.endsWith(CCH_ORDER_FILE_EXTENSION)));
}

/**
* True when {@code fileName} is an LSM vector index's node-locally built graph or one of the files derived from it:
* the {@code .vecgraph} component, the {@code .vecgraphfp} manifest, the {@code .vecordmap} ordinal map and the
* {@code .vecpq} product quantization (issue #9751). Matched by the final extension, which is how every one of their
* writers names them ({@code <base>.<ext>}); a write in flight ends in {@code .tmp} instead and is not matched here.
*/
public static boolean isVectorGraphFileName(final String fileName) {
return endsWithExtension(fileName, LSMVectorIndexGraphFile.FILE_EXT)
|| endsWithExtension(fileName, LSMVectorIndexGraphManifest.FILE_EXT)
|| endsWithExtension(fileName, LSMVectorIndexOrdinalMapFile.FILE_EXT)
|| endsWithExtension(fileName, LSMVectorIndexPQFile.FILE_EXT);
}

private static boolean endsWithExtension(final String fileName, final String extension) {
final int dot = fileName.length() - extension.length() - 1;
return dot > 0 && fileName.charAt(dot) == '.' && fileName.endsWith(extension);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.arcadedb.GlobalConfiguration;
import com.arcadedb.database.DatabaseInternal;
import com.arcadedb.engine.NodeLocalFiles;
import com.arcadedb.engine.PageSnapshot;
import com.arcadedb.engine.PaginatedComponent;
import com.arcadedb.engine.timeseries.ListedSealedStore;
Expand Down Expand Up @@ -661,7 +662,7 @@ private boolean computeLocalChecksums(final DatabaseInternal db, final JSONObjec
try {
// #7955: AN INDEX COMPACTION IN FLIGHT HAS A REGISTERED temp_* COMPONENT FILE, SO THE WINDOW CARRIES
// IT - AND ONLY THE NODE THAT HAPPENS TO BE COMPACTING HAS ONE. SEE isTemporaryFileName
if (PaginatedComponent.isTemporaryFileName(file.fileName()))
if (isNotCompared(file.fileName()))
continue;
collectFileInfo(snapshotChecksums, snapshotFiles, file.fileName(), snapshot.calculateChecksum(file.fileId()),
file.size());
Expand Down Expand Up @@ -700,7 +701,7 @@ private boolean computeLocalChecksums(final DatabaseInternal db, final JSONObjec
db.getPageManager().suspendFlushAndExecute(db, () -> {
runChecksummingHook(null);
for (final var file : db.getFileManager().getFiles())
if (file != null && !PaginatedComponent.isTemporaryFileName(file.getFileName())) {
if (file != null && !isNotCompared(file.getFileName())) {
try {
collectFileInfo(localChecksums, localFiles, file.getFileName(), file.calculateChecksum(), file.getSize());
} catch (final Exception e) {
Expand All @@ -720,6 +721,17 @@ private boolean computeLocalChecksums(final DatabaseInternal db, final JSONObjec
return sealedStoresCovered[0];
}

/**
* Whether a registered page file is left out of the comparison because only this node has it, or only this node's
* copy of it: an index-compaction temporary (#7955), or a component the engine declares node-local - in practice an
* LSM vector index's {@code .vecgraph}, which every node builds for itself without the WAL, so its pages differ on a
* healthy cluster (#9751). The vectors it is built from live in the index's own pages, which ARE compared. The same
* declaration {@code SnapshotManager.computeFileChecksums} applies, so the two collectors cannot disagree on it.
*/
static boolean isNotCompared(final String fileName) {
return PaginatedComponent.isTemporaryFileName(fileName) || NodeLocalFiles.isNodeLocalFileName(fileName);
}

/**
* The image one verify reads on the window path: the point-in-time page window, and the TimeSeries sealed stores as
* they were listed in the same read-locked frame as its t0. {@code sealedFiles} is {@code null} when the compaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ public static Map<String, Long> computeFileChecksums(final File directory, final
* {@code database.lck}, empty today and so matching by accident. They are declared by
* {@link NodeLocalFiles#isNodeLocalFileName(String)} in the engine, beside the constants their writers build the names
* from, rather than listed here, so a new engine side file is classified where it is written.
* <p>
* #9751 adds two more families there: an LSM vector index's node-locally built graph with its manifest, ordinal map
* and product quantization, and the {@code last-tx-id.bin} recency marker, which a snapshot does ship but which a live
* node rewrites at moments of its own.
*/
private static boolean isNodeLocalFileName(final String name) {
return name.endsWith(".wal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.arcadedb.graph.olap.ContractionHierarchy;
import com.arcadedb.graph.olap.GraphAnalyticalView;
import com.arcadedb.schema.LocalSchema;
import com.arcadedb.schema.LocalTimeSeriesType;
import com.arcadedb.schema.Type;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -157,6 +158,20 @@ void everyFileARealDatabaseWritesIsEitherShippedOrLeftOutOfTheChecksums(@TempDir
assertThat(cch).isNotNull();
assertThat(cch.awaitReady(false, 60, TimeUnit.SECONDS)).isTrue();

// #9751: LSM VECTOR INDEXES, THEIR GRAPHS BUILT, WRITE THE GRAPH COMPONENT AND THREE PLAIN SIDE FILES BESIDE IT -
// ONE WITHOUT AND ONE WITH PRODUCT QUANTIZATION, SINCE ONLY THE FORMER WRITES AN ORDINAL MAP AND ONLY THE LATTER A PQ
Issue9751VectorSideFilesChecksumTest.createVectorIndex(database, "Doc", "NONE");
Issue9751VectorSideFilesChecksumTest.createVectorIndex(database, "PqDoc", "PRODUCT");

// #9751: AND A TIMESERIES TYPE WITH A SEALED STORE, THE OTHER WRITER OF RAW FILES INTO THE DIRECTORY
database.command("sql", "CREATE TIMESERIES TYPE Reading TIMESTAMP ts TAGS (id STRING) FIELDS (value DOUBLE) SHARDS 1");
database.transaction(() -> {
for (int i = 0; i < 100; i++)
database.command("sql", "INSERT INTO Reading SET ts = ?, id = 's1', value = ?", 1_700_000_000_000L + i * 1000L,
(double) i);
});
((LocalTimeSeriesType) database.getSchema().getType("Reading")).getEngine().compactAll();

for (final File file : listFiles(path))
seenWhileOpen.add(file.getName());
assertThat(seenWhileOpen).as("the open database holds its lock file, so the guard reaches it").contains("database.lck");
Expand All @@ -173,6 +188,12 @@ void everyFileARealDatabaseWritesIsEitherShippedOrLeftOutOfTheChecksums(@TempDir
assertThat(afterClose).as("the clean close writes the statistics file").contains(LocalSchema.STATISTICS_FILE_NAME);
assertThat(afterClose).as("the clean close persists the view's CSR").contains("gav-Routes.csr");
assertThat(afterClose).as("and the contraction hierarchy's order").anyMatch(n -> n.startsWith("gav-Routes.csr.") && n.endsWith(".cchorder"));
assertThat(afterClose).as("the vector index persisted its graph").anyMatch(n -> n.endsWith(".vecgraph"));
assertThat(afterClose).as("and its manifest").anyMatch(n -> n.endsWith(".vecgraphfp"));
assertThat(afterClose).as("and its ordinal map").anyMatch(n -> n.endsWith(".vecordmap"));
assertThat(afterClose).as("and its product quantization").anyMatch(n -> n.endsWith(".vecpq"));
assertThat(afterClose).as("the TimeSeries compaction sealed a store").anyMatch(n -> n.endsWith(TimeSeriesSealedStore.FILE_EXTENSION));
assertThat(afterClose).as("the clean close wrote the recency marker").contains(TransactionManager.LAST_TX_ID_FILE_NAME);

assertUnshippedFilesAreLeftOut(path);
}
Expand Down Expand Up @@ -201,7 +222,8 @@ private static boolean isShippedBySnapshot(final String name) {
|| name.endsWith(TimeSeriesSealedStore.FILE_EXTENSION)
|| name.equals(LocalDatabase.CONFIGURATION_FILE_NAME)
|| name.equals(LocalSchema.SCHEMA_FILE_NAME)
// TODO #9751: shipped, but rewritten per node on WAL rotation and close, so it may still differ between peers
// SYNTHESIZED INTO THE ARCHIVE, BUT LEFT OUT OF THE CHECKSUMS ALL THE SAME: A LIVE NODE REWRITES IT ON ITS OWN WAL
// ROTATIONS AND CLOSES, SO TWO HEALTHY PEERS HOLD DIFFERENT VALUES (#9751)
|| name.equals(TransactionManager.LAST_TX_ID_FILE_NAME);
}

Expand Down
Loading