Commit 05eba3fd by Ashutosh Mestry

ATLAS-3907: Java Patch Handler: Set index consistency.

parent 500ea95c
......@@ -167,4 +167,9 @@ public interface AtlasGraphManagement {
* @return the encoded name for the index
*/
String getIndexFieldName(String indexName, AtlasPropertyKey propertyKey, boolean isStringField);
/**
* Set consistency to ConsistencyModifier.LOCK for all vertex and edge indexes.
*/
void updateUniqueIndexesForConsistencyLock();
}
......@@ -20,6 +20,7 @@ package org.apache.atlas.repository.graphdb.janus;
import com.google.common.base.Preconditions;
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.janusgraph.core.Cardinality;
import org.janusgraph.core.EdgeLabel;
import org.janusgraph.core.PropertyKey;
......@@ -274,4 +275,38 @@ public class AtlasJanusGraphManagement implements AtlasGraphManagement {
indexBuilder.buildCompositeIndex();
}
@Override
public void updateUniqueIndexesForConsistencyLock() {
try {
setConsistency(this.management, Vertex.class);
setConsistency(this.management, Edge.class);
} finally {
commit();
}
}
private static void setConsistency(JanusGraphManagement mgmt, Class<? extends Element> elementType) {
LOG.info("setConsistency: {}: Starting...", elementType.getSimpleName());
int count = 0;
try {
Iterable<JanusGraphIndex> iterable = mgmt.getGraphIndexes(elementType);
for (JanusGraphIndex index : iterable) {
if (!index.isCompositeIndex() || !index.isUnique() || mgmt.getConsistency(index) == ConsistencyModifier.LOCK) {
continue;
}
for (PropertyKey propertyKey : index.getFieldKeys()) {
LOG.info("setConsistency: {}: {}", count, propertyKey.name());
}
mgmt.setConsistency(index, ConsistencyModifier.LOCK);
count++;
}
}
finally {
LOG.info("setConsistency: {}: {}: Done!", elementType.getSimpleName(), count);
}
}
}
\ No newline at end of file
......@@ -53,7 +53,8 @@ public class AtlasPatchManager {
new UniqueAttributePatch(context),
new ClassificationTextPatch(context),
new FreeTextRequestHandlerPatch(context),
new SuggestionsRequestHandlerPatch(context)
new SuggestionsRequestHandlerPatch(context),
new IndexConsistencyPatch(context)
};
try {
......
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.atlas.repository.patches;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.atlas.model.patches.AtlasPatch.PatchStatus.APPLIED;
public class IndexConsistencyPatch extends AtlasPatchHandler {
private static final Logger LOG = LoggerFactory.getLogger(IndexConsistencyPatch.class);
private static final String PATCH_ID = "JAVA_PATCH_0000_005";
private static final String PATCH_DESCRIPTION = "Sets index consistency for vertices and edges.";
private final PatchContext context;
public IndexConsistencyPatch(PatchContext context) {
super(context.getPatchRegistry(), PATCH_ID, PATCH_DESCRIPTION);
this.context = context;
}
@Override
public void apply() throws AtlasBaseException {
AtlasGraph graph = context.getGraph();
try {
LOG.info("IndexConsistencyPatch: Starting...");
graph.getManagementSystem().updateUniqueIndexesForConsistencyLock();
} finally {
LOG.info("IndexConsistencyPatch: Done!");
}
setStatus(APPLIED);
LOG.info("IndexConsistencyPatch.apply(): patchId={}, status={}", getPatchId(), getStatus());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment