diff --git a/evita_engine/src/main/java/io/evitadb/core/Catalog.java b/evita_engine/src/main/java/io/evitadb/core/Catalog.java index 9465d0760..5cbd8bdf5 100644 --- a/evita_engine/src/main/java/io/evitadb/core/Catalog.java +++ b/evita_engine/src/main/java/io/evitadb/core/Catalog.java @@ -228,6 +228,7 @@ public final class Catalog implements CatalogContract, CatalogVersionBeyondTheHo /** * Contains reference to the archived catalog index that allows fast lookups for entities across all types. */ + @Nullable private CatalogIndex archiveCatalogIndex; /** * Isolated sequence service for this catalog. @@ -409,6 +410,7 @@ public Catalog( .orElseGet(() -> new CatalogIndex(Scope.LIVE)); this.catalogIndex.attachToCatalog(null, this); this.archiveCatalogIndex = this.persistenceService.readCatalogIndex(this, Scope.ARCHIVED) + .filter(it -> !it.isEmpty()) .orElse(null); if (this.archiveCatalogIndex != null) { this.archiveCatalogIndex.attachToCatalog(null, this); @@ -490,7 +492,7 @@ public Catalog( long catalogVersion, @Nonnull CatalogState catalogState, @Nonnull CatalogIndex catalogIndex, - @Nonnull CatalogIndex archiveCatalogIndex, + @Nullable CatalogIndex archiveCatalogIndex, @Nonnull Collection entityCollections, @Nonnull Catalog previousCatalogVersion ) { @@ -1380,13 +1382,6 @@ void flush() { changeOccurred = changeOccurred || entityCollection.getVersion() != lastSeenVersion; } - if (this.archiveCatalogIndex != null && this.archiveCatalogIndex.isEmpty()) { - this.dataStoreBuffer.removeIndex( - this.archiveCatalogIndex.getIndexKey(), - catalogIndexKey -> this.archiveCatalogIndex = null - ); - } - if (changeOccurred) { this.persistenceService.flushTrappedUpdates( 0L, diff --git a/evita_engine/src/main/java/io/evitadb/store/spi/model/storageParts/index/CatalogIndexStoragePart.java b/evita_engine/src/main/java/io/evitadb/store/spi/model/storageParts/index/CatalogIndexStoragePart.java index b0d94b27b..20bec0e72 100644 --- a/evita_engine/src/main/java/io/evitadb/store/spi/model/storageParts/index/CatalogIndexStoragePart.java +++ b/evita_engine/src/main/java/io/evitadb/store/spi/model/storageParts/index/CatalogIndexStoragePart.java @@ -80,12 +80,12 @@ public static long getStoragePartPKForScope(@Nonnull Scope scope) { @Nullable @Override public Long getStoragePartPK() { - return getStoragePartPKForScope(catalogIndexKey.scope()); + return getStoragePartPKForScope(this.catalogIndexKey.scope()); } @Override public long computeUniquePartIdAndSet(@Nonnull KeyCompressor keyCompressor) { - return 1L; + return getStoragePartPKForScope(this.catalogIndexKey.scope()); } } diff --git a/evita_functional_tests/src/test/java/io/evitadb/api/EvitaArchivingTest.java b/evita_functional_tests/src/test/java/io/evitadb/api/EvitaArchivingTest.java index f485a1f82..49ad435c5 100644 --- a/evita_functional_tests/src/test/java/io/evitadb/api/EvitaArchivingTest.java +++ b/evita_functional_tests/src/test/java/io/evitadb/api/EvitaArchivingTest.java @@ -398,7 +398,7 @@ void shouldArchiveEntityAndMoveToArchivedIndexes() { assertNotNull(getReferencedEntityIndex(productCollection3, Scope.LIVE, Entities.BRAND, 1)); assertNull(getReferencedEntityIndex(productCollection3, Scope.LIVE, Entities.BRAND, 2)); - assertNull(catalog3.getCatalogIndexIfExits(Scope.ARCHIVED).orElse(null)); + assertNull(catalog3.getCatalogIndexIfExits(Scope.ARCHIVED).filter(it -> !it.isEmpty()).orElse(null)); assertNull(getGlobalIndex(productCollection3, Scope.ARCHIVED)); assertNull(getReferencedEntityIndex(productCollection3, Scope.ARCHIVED, Entities.CATEGORY, 1)); assertNull(getReferencedEntityIndex(productCollection3, Scope.ARCHIVED, Entities.CATEGORY, 2));