diff --git a/platform/indexing-impl/src/com/intellij/find/ngrams/TrigramIndex.java b/platform/indexing-impl/src/com/intellij/find/ngrams/TrigramIndex.java index 6a37c2e3f474..1dc89421d4e5 100644 --- a/platform/indexing-impl/src/com/intellij/find/ngrams/TrigramIndex.java +++ b/platform/indexing-impl/src/com/intellij/find/ngrams/TrigramIndex.java @@ -91,9 +91,15 @@ public final class TrigramIndex extends ScalarIndexExtension implements return true; } + @Override + @Internal + public int shardlessVersion() { + return 4; + } + @Override public int getVersion() { - return 4 + (SHARDS - 1); + return shardlessVersion() + (SHARDS - 1); } @Override diff --git a/platform/indexing-impl/src/com/intellij/util/indexing/storage/sharding/ShardableIndexExtension.java b/platform/indexing-impl/src/com/intellij/util/indexing/storage/sharding/ShardableIndexExtension.java index b4e48249a633..4ca2ce9135a1 100644 --- a/platform/indexing-impl/src/com/intellij/util/indexing/storage/sharding/ShardableIndexExtension.java +++ b/platform/indexing-impl/src/com/intellij/util/indexing/storage/sharding/ShardableIndexExtension.java @@ -1,6 +1,7 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.util.indexing.storage.sharding; +import com.intellij.util.indexing.IndexExtension; import org.jetbrains.annotations.ApiStatus; /** @@ -48,4 +49,14 @@ public interface ShardableIndexExtension { return 3; } } + + /** + * Implementation version, without taking shards# into account. + * Motivation: generally, shards count should be a part of {@link IndexExtension#getVersion()} -- e.g. change in shardsCount _must_ + * trigger re-indexing -- but in some cases shards count is not important. It all comes down to the exact interpretation of + * {@link IndexExtension#getVersion()}: is it a version of current index layout, or it is a version of index layout that could be + * _open-and-read_ by current code? This method returns "version that could be open-and-read", while {@link IndexExtension#getVersion()} + * returns a current layout version. + */ + int shardlessVersion(); } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/id/IdIndexImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/id/IdIndexImpl.java index ef0d02b23491..52e43935d692 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/id/IdIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/cache/impl/id/IdIndexImpl.java @@ -43,8 +43,13 @@ public final class IdIndexImpl extends IdIndex implements CustomInputsIndexFileB return SHARDS; } + @Override + public int shardlessVersion() { + return super.getVersion(); + } + @Override public int getVersion() { - return super.getVersion() + (SHARDS - 1); + return shardlessVersion() + (SHARDS - 1); } } diff --git a/platform/platform-tests/benchmarks/src/com/intellij/openapi/vfs/newvfs/persistent/indexes/IndexStorageLayoutBenchmark.java b/platform/platform-tests/benchmarks/src/com/intellij/openapi/vfs/newvfs/persistent/indexes/IndexStorageLayoutBenchmark.java index 5564777fa8fd..fef16f978adf 100644 --- a/platform/platform-tests/benchmarks/src/com/intellij/openapi/vfs/newvfs/persistent/indexes/IndexStorageLayoutBenchmark.java +++ b/platform/platform-tests/benchmarks/src/com/intellij/openapi/vfs/newvfs/persistent/indexes/IndexStorageLayoutBenchmark.java @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.vfs.newvfs.persistent.indexes; import com.intellij.openapi.module.Module; @@ -157,6 +157,11 @@ public class IndexStorageLayoutBenchmark { public int shardsCount() { return 2; } + + @Override + public int shardlessVersion() { + return super.getVersion(); + } } } diff --git a/platform/util/src/com/intellij/util/indexing/IndexExtension.java b/platform/util/src/com/intellij/util/indexing/IndexExtension.java index 5b6d509898b7..15a9e31f804a 100644 --- a/platform/util/src/com/intellij/util/indexing/IndexExtension.java +++ b/platform/util/src/com/intellij/util/indexing/IndexExtension.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.util.indexing; @@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull; /** * Represents index data format specification, namely serialization format for keys & values, and a mapping from input to * indexing data. - * + *

* To create index corresponding to any extension one could use {@link com.intellij.util.indexing.impl.MapReduceIndex}. */ public abstract class IndexExtension { @@ -25,6 +25,15 @@ public abstract class IndexExtension { public abstract @NotNull DataExternalizer getValueExternalizer(); - /** Version of index format/algo. Generally, if the version is changed -- index must be rebuilt. */ + /** + * Version of index format/algo. + * Generally, if the version is changed -- index must be rebuilt. + *

+ * Discussion: "index version" is quite ill-defined concept, because really it should be not a single version, but a few separate + * versions for "binary layout to be written version", "binary layout compatible to read version", "indexer algo version", etc. + * Currently, all those 'versions' are merged into a single version -- which simplifies things a bit, but causes issues from time to time. + * + * @see ShardableIndexExtension#shardlessVersion + */ public abstract int getVersion(); } diff --git a/platform/util/testSrc/com/intellij/util/indexing/IndexStorageLayoutProviderTestBase.java b/platform/util/testSrc/com/intellij/util/indexing/IndexStorageLayoutProviderTestBase.java index f0596194d7fb..e4a1d84d91ba 100644 --- a/platform/util/testSrc/com/intellij/util/indexing/IndexStorageLayoutProviderTestBase.java +++ b/platform/util/testSrc/com/intellij/util/indexing/IndexStorageLayoutProviderTestBase.java @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.util.indexing; import com.intellij.openapi.util.io.ByteArraySequence; @@ -538,6 +538,11 @@ public abstract class IndexStorageLayoutProviderTestBase { return VERSION; } + @Override + public int shardlessVersion() { + return VERSION + (shardsCount() - 1) * 10; + } + @Override public int shardsCount() { return 3;