Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
Expand Down Expand Up @@ -234,6 +235,36 @@ public static Collection<String> filterReplacedIndexes(Collection<String> indexP
return result;
}

/**
* Remove indexes if there is a newer, active version.
* This suppresses indexes when a newer version of a different type exists
* (e.g. lucene vs. elasticsearch).
*
* @param candidatePaths paths of one specific index type being evaluated
* @param allCompetingPaths paths of all competing index types (e.g. both lucene and elasticsearch)
* @return candidates that are not superseded by a higher-versioned entry in allCompetingPaths
*/
public static Collection<String> filterGloballySuperseded(
Collection<String> candidatePaths, Collection<String> allCompetingPaths) {
Map<String, IndexName> maxByBase = new HashMap<>();
for (String p : allCompetingPaths) {
IndexName n = IndexName.parse(PathUtils.getName(p));
IndexName stored = maxByBase.get(n.baseName);
if (stored == null || stored.compareTo(n) < 0) {
maxByBase.put(n.baseName, n);
}
}
List<String> result = new ArrayList<>();
for (String p : candidatePaths) {
IndexName n = IndexName.parse(PathUtils.getName(p));
IndexName globalMax = maxByBase.get(n.baseName);
if (globalMax == null || globalMax.compareTo(n) == 0) {
result.add(p);
}
}
return result;
}

public static Collection<String> filterNewestIndexes(Collection<String> indexPaths) {
HashMap<String, IndexName> latestVersions = new HashMap<>();
for (String p : indexPaths) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.jackrabbit.oak.plugins.index;

import org.junit.Test;

import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class IndexNameAdditionalTest {

// ---- filterGloballySuperseded ----

@Test
public void filterGloballySuperseded_noCompetitors() {
// no competing paths: all candidates pass through
Collection<String> result = IndexName.filterGloballySuperseded(
List.of("/oak:index/lucene-2"),
List.of());
assertEquals(List.of("/oak:index/lucene-2"), List.copyOf(result));
}

@Test
public void filterGloballySuperseded_olderCompetitorKept() {
// lucene-2 is newer than /oak:index/lucene-1-custom-1, so it passes
Collection<String> result = IndexName.filterGloballySuperseded(
List.of("/oak:index/lucene-2"),
List.of("/oak:index/lucene-2", "/oak:index/lucene-1-custom-1"));
assertEquals(List.of("/oak:index/lucene-2"), List.copyOf(result));
}

@Test
public void filterGloballySuperseded_newerCompetitorFilters() {
// lucene-1 vs. lucene-2 (same base): lucene-1 is superseded
Collection<String> result = IndexName.filterGloballySuperseded(
List.of("/oak:index/lucene-1"),
List.of("/oak:index/lucene-1", "/oak:index/lucene-2"));
assertTrue(result.isEmpty());
}

@Test
public void filterGloballySuperseded_differentBaseNotAffected() {
// lucene-1 for "fooIndex" is not affected by a newer version of "barIndex"
Collection<String> result = IndexName.filterGloballySuperseded(
List.of("/oak:index/fooIndex-1"),
List.of("/oak:index/fooIndex-1", "/oak:index/barIndex-2"));
assertEquals(List.of("/oak:index/fooIndex-1"), List.copyOf(result));
}

@Test
public void filterGloballySuperseded_unversionedSupersededByVersioned() {
// unversioned lucene (version 0) is superseded by lucene-1
Collection<String> result = IndexName.filterGloballySuperseded(
List.of("/oak:index/lucene"),
List.of("/oak:index/lucene", "/oak:index/lucene-1"));
assertTrue(result.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.jackrabbit.oak.plugins.index.search.spi.query;
package org.apache.jackrabbit.oak.plugins.index;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;

import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
import org.apache.jackrabbit.oak.plugins.index.IndexName;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.junit.Test;
Expand Down Expand Up @@ -71,10 +70,10 @@
IndexName p1c1 = IndexName.parse("/lucene-1-custom-1");
IndexName p1c2 = IndexName.parse("/lucene-1-custom-2");

assertTrue(p0.compareTo(p0a) == 0);

Check warning on line 73 in oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexNameTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use assertEquals instead.

See more on https://sonarcloud.io/project/issues?id=org.apache.jackrabbit%3Ajackrabbit-oak&issues=AZ0ltYpZ3TOoRD_-O1QI&open=AZ0ltYpZ3TOoRD_-O1QI&pullRequest=2813
assertTrue(p0.compareTo(p0b) == 0);

Check warning on line 74 in oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexNameTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use assertEquals instead.

See more on https://sonarcloud.io/project/issues?id=org.apache.jackrabbit%3Ajackrabbit-oak&issues=AZ0ltYpZ3TOoRD_-O1QJ&open=AZ0ltYpZ3TOoRD_-O1QJ&pullRequest=2813
assertTrue(p0a.compareTo(p0b) == 0);

Check warning on line 75 in oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexNameTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use assertEquals instead.

See more on https://sonarcloud.io/project/issues?id=org.apache.jackrabbit%3Ajackrabbit-oak&issues=AZ0ltYpZ3TOoRD_-O1QK&open=AZ0ltYpZ3TOoRD_-O1QK&pullRequest=2813
assertTrue(p0c1.compareTo(p0c1a) == 0);

Check warning on line 76 in oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexNameTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use assertEquals instead.

See more on https://sonarcloud.io/project/issues?id=org.apache.jackrabbit%3Ajackrabbit-oak&issues=AZ0ltYpZ3TOoRD_-O1QL&open=AZ0ltYpZ3TOoRD_-O1QL&pullRequest=2813

assertTrue(p0.compareTo(p0c1) < 0);
assertTrue(p0c1.compareTo(p1) < 0);
Expand Down
13 changes: 13 additions & 0 deletions oak-it-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-search-elastic</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>elasticsearch</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-store-composite</artifactId>
Expand Down
Loading
Loading