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 @@ -63,6 +63,10 @@ public ResultSet executeDDL(final CommandContext context) {
final DatabaseInternal database = context.getDatabase();
database.checkPermissionsOnDatabase(SecurityDatabaseUser.DATABASE_ACCESS.UPDATE_SCHEMA);

// Resolved outside the try below, as REBUILD INDEX does (issue #15034): a name the schema does not have is the caller's
// mistake, refused with the SchemaException the lookup raises, not wrapped in an IndexException that reads as a server fault
final Index namedIndex = all ? null : database.getSchema().getIndexByName(name.getValue());

final ResultInternal result = new ResultInternal(database);
result.setProperty("operation", "compact index");

Expand All @@ -81,7 +85,7 @@ public ResultSet executeDDL(final CommandContext context) {
if (idx.isAutomatic() && !(idx instanceof TypeIndex))
targetIndexes.add(idx);
} else
targetIndexes.add(database.getSchema().getIndexByName(name.getValue()));
targetIndexes.add(namedIndex);

int stepIndex = 0;
for (final Index idx : targetIndexes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.arcadedb.GlobalConfiguration;
import com.arcadedb.TestHelper;
import com.arcadedb.database.MutableDocument;
import com.arcadedb.exception.SchemaException;
import com.arcadedb.index.sparsevector.LSMSparseVectorIndex;
import com.arcadedb.query.sql.executor.Result;
import com.arcadedb.query.sql.executor.ResultSet;
Expand All @@ -34,6 +35,7 @@
import java.util.Random;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
* Regression test for issue #5144: index compaction must be reachable from SQL (and therefore HTTP)
Expand Down Expand Up @@ -152,6 +154,17 @@ void compactLsmTreeIndexActuallyMergesViaSql() {
}
}

/**
* Issue #15034: a name the schema does not have is the caller's mistake, refused with the lookup's SchemaException as
* REBUILD INDEX and DROP INDEX refuse it, not wrapped in an IndexException (HTTP 500).
*/
@Test
void compactingAnIndexThatDoesNotExistIsRefusedAsASchemaError() {
assertThatThrownBy(() -> database.command("sql", "COMPACT INDEX Issue15034Nope"))
.isInstanceOf(SchemaException.class)
.hasMessageContaining("Issue15034Nope");
}

private void insertDocs(final int n, final int seedOffset) {
database.transaction(() -> {
final Random rnd = new Random(0xCAFEL + seedOffset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ void rebuildingAnIndexThatDoesNotExistIs400() throws Exception {
assertAnswer("REBUILD INDEX Issue11803Nope", 400, SchemaException.class, "Issue11803Nope");
}

@Test
void compactingAnIndexThatDoesNotExistIs400() throws Exception {
// issue #15034: it answered 500 with the SchemaException wrapped in an IndexException
assertAnswer("COMPACT INDEX Issue15034Nope", 400, SchemaException.class, "Issue15034Nope");
}

@Test
void importingASourceThatDoesNotExistIs400() throws Exception {
final File missing = new File(System.getProperty("java.io.tmpdir"), "issue11803-" + System.nanoTime() + ".jsonl");
Expand Down
Loading