-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IGNITE-20620 Add index availability command to catalog #2680
Changes from all commits
e90648c
d8440e8
f4eb671
1a65e10
1902d40
7840586
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.ignite.internal.catalog; | ||
|
||
import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor; | ||
|
||
/** | ||
* This exception is thrown when an attempt is made to make an index available a second time | ||
* ({@link CatalogIndexDescriptor#writeOnly() read-write} state). | ||
*/ | ||
public class IndexAlreadyAvailableValidationException extends CatalogValidationException { | ||
private static final long serialVersionUID = 5482919822886169473L; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param message Error message. | ||
*/ | ||
public IndexAlreadyAvailableValidationException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,10 @@ | |
import java.util.Set; | ||
import org.apache.ignite.internal.catalog.Catalog; | ||
import org.apache.ignite.internal.catalog.CatalogValidationException; | ||
import org.apache.ignite.internal.catalog.IndexNotFoundValidationException; | ||
import org.apache.ignite.internal.catalog.TableNotFoundValidationException; | ||
import org.apache.ignite.internal.catalog.descriptors.CatalogDataStorageDescriptor; | ||
import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor; | ||
import org.apache.ignite.internal.catalog.descriptors.CatalogSchemaDescriptor; | ||
import org.apache.ignite.internal.catalog.descriptors.CatalogTableColumnDescriptor; | ||
import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor; | ||
|
@@ -363,4 +365,22 @@ static CatalogZoneDescriptor zoneOrThrow(Catalog catalog, String name) throws Ca | |
public static String pkIndexName(String tableName) { | ||
return tableName + "_PK"; | ||
} | ||
|
||
/** | ||
* Returns index with given name. | ||
* | ||
* @param schema Schema to look up index in. | ||
* @param name Name of the index of interest. | ||
* @return Table with given name. | ||
* @throws IndexNotFoundValidationException If index with given name is not exists. | ||
*/ | ||
static CatalogIndexDescriptor indexOrThrow(CatalogSchemaDescriptor schema, String name) throws IndexNotFoundValidationException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about moving this method to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t think it’s worth it, this method is only used by teams, but |
||
CatalogIndexDescriptor index = schema.index(name); | ||
|
||
if (index == null) { | ||
throw new IndexNotFoundValidationException(format("Index with name '{}.{}' not found", schema.name(), name)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this method can be used not only in the context where we validate something, but it throws a validation exception. Can the exception type be generalized? Or the method renamed (or at least documented) that it's just for validation phase? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this class there were methods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth fixing this outside of the current task. |
||
} | ||
|
||
return index; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* 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.ignite.internal.catalog.commands; | ||
|
||
import static org.apache.ignite.internal.catalog.commands.CatalogUtils.indexOrThrow; | ||
import static org.apache.ignite.internal.catalog.commands.CatalogUtils.schemaOrThrow; | ||
import static org.apache.ignite.internal.lang.IgniteStringFormatter.format; | ||
|
||
import java.util.List; | ||
import org.apache.ignite.internal.catalog.Catalog; | ||
import org.apache.ignite.internal.catalog.CatalogCommand; | ||
import org.apache.ignite.internal.catalog.CatalogValidationException; | ||
import org.apache.ignite.internal.catalog.IndexAlreadyAvailableValidationException; | ||
import org.apache.ignite.internal.catalog.IndexNotFoundValidationException; | ||
import org.apache.ignite.internal.catalog.descriptors.CatalogHashIndexDescriptor; | ||
import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor; | ||
import org.apache.ignite.internal.catalog.descriptors.CatalogSchemaDescriptor; | ||
import org.apache.ignite.internal.catalog.descriptors.CatalogSortedIndexDescriptor; | ||
import org.apache.ignite.internal.catalog.storage.MakeIndexAvailableEntry; | ||
import org.apache.ignite.internal.catalog.storage.UpdateEntry; | ||
|
||
/** | ||
* Makes the index available for read-write, switches from the write-only to the read-write state in the catalog. | ||
* | ||
* @see CatalogIndexDescriptor#writeOnly() | ||
* @see IndexNotFoundValidationException | ||
* @see IndexAlreadyAvailableValidationException | ||
*/ | ||
public class MakeIndexAvailableCommand extends AbstractIndexCommand { | ||
/** Returns builder to make an index available for read-write. */ | ||
public static MakeIndexAvailableCommandBuilder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param schemaName Schema name. | ||
* @param indexName Index name. | ||
* @throws CatalogValidationException If any of the parameters fails validation. | ||
*/ | ||
private MakeIndexAvailableCommand(String schemaName, String indexName) throws CatalogValidationException { | ||
super(schemaName, indexName); | ||
} | ||
|
||
@Override | ||
public List<UpdateEntry> get(Catalog catalog) { | ||
CatalogSchemaDescriptor schema = schemaOrThrow(catalog, schemaName); | ||
|
||
CatalogIndexDescriptor index = indexOrThrow(schema, indexName); | ||
|
||
if (!index.writeOnly()) { | ||
throw new IndexAlreadyAvailableValidationException(format("Index is already available '{}.{}'", schemaName, indexName)); | ||
} | ||
|
||
CatalogIndexDescriptor updatedIndex; | ||
|
||
if (index instanceof CatalogHashIndexDescriptor) { | ||
updatedIndex = createReadWriteIndex((CatalogHashIndexDescriptor) index); | ||
} else if (index instanceof CatalogSortedIndexDescriptor) { | ||
updatedIndex = createReadWriteIndex((CatalogSortedIndexDescriptor) index); | ||
} else { | ||
throw new CatalogValidationException(format("Unsupported index type '{}.{}' {}", schemaName, indexName, index)); | ||
} | ||
|
||
return List.of(new MakeIndexAvailableEntry(schemaName, updatedIndex)); | ||
} | ||
|
||
private static CatalogIndexDescriptor createReadWriteIndex(CatalogHashIndexDescriptor index) { | ||
return new CatalogHashIndexDescriptor( | ||
index.id(), | ||
index.name(), | ||
index.tableId(), | ||
index.unique(), | ||
index.columns(), | ||
false | ||
); | ||
} | ||
|
||
private static CatalogIndexDescriptor createReadWriteIndex(CatalogSortedIndexDescriptor index) { | ||
return new CatalogSortedIndexDescriptor( | ||
index.id(), | ||
index.name(), | ||
index.tableId(), | ||
index.unique(), | ||
index.columns(), | ||
false | ||
); | ||
} | ||
|
||
private static class Builder implements MakeIndexAvailableCommandBuilder { | ||
private String schemaName; | ||
|
||
private String indexName; | ||
|
||
@Override | ||
public Builder schemaName(String schemaName) { | ||
this.schemaName = schemaName; | ||
|
||
return this; | ||
} | ||
|
||
@Override | ||
public Builder indexName(String indexName) { | ||
this.indexName = indexName; | ||
|
||
return this; | ||
} | ||
|
||
@Override | ||
public CatalogCommand build() { | ||
return new MakeIndexAvailableCommand(schemaName, indexName); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.ignite.internal.catalog.commands; | ||
|
||
/** Builder for {@link MakeIndexAvailableCommand}. */ | ||
public interface MakeIndexAvailableCommandBuilder extends AbstractIndexCommandBuilder<MakeIndexAvailableCommandBuilder> { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need that trailing
</p>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the code that I recall we never use it. But this is not too important