You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2020/07/31 00:19:01 UTC

[atlas] 01/02: ATLAS-3907: Java Patch Handler: Set index consistency.

This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git

commit 7086a4ac3ebdda56c7f125edfd0014a3c2ad3f58
Author: Ashutosh Mestry <am...@cloudera.com>
AuthorDate: Thu Jul 30 15:50:21 2020 -0700

    ATLAS-3907: Java Patch Handler: Set index consistency.
    
    (cherry picked from commit 05eba3fdb9fedf3483cdb1cef938f7a2cbf7933e)
---
 .../repository/graphdb/AtlasGraphManagement.java   |  5 ++
 .../graphdb/janus/AtlasJanusGraphManagement.java   | 35 ++++++++++++++
 .../repository/patches/AtlasPatchManager.java      |  3 +-
 .../repository/patches/IndexConsistencyPatch.java  | 56 ++++++++++++++++++++++
 4 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphManagement.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphManagement.java
index fca7890..f7d2e27 100644
--- a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphManagement.java
+++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphManagement.java
@@ -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();
 }
diff --git a/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphManagement.java b/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphManagement.java
index 6ef9cb7..d0cda71 100644
--- a/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphManagement.java
+++ b/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphManagement.java
@@ -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
diff --git a/repository/src/main/java/org/apache/atlas/repository/patches/AtlasPatchManager.java b/repository/src/main/java/org/apache/atlas/repository/patches/AtlasPatchManager.java
index 093edf9..b142a2a 100644
--- a/repository/src/main/java/org/apache/atlas/repository/patches/AtlasPatchManager.java
+++ b/repository/src/main/java/org/apache/atlas/repository/patches/AtlasPatchManager.java
@@ -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 {
diff --git a/repository/src/main/java/org/apache/atlas/repository/patches/IndexConsistencyPatch.java b/repository/src/main/java/org/apache/atlas/repository/patches/IndexConsistencyPatch.java
new file mode 100644
index 0000000..2abe73c
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/repository/patches/IndexConsistencyPatch.java
@@ -0,0 +1,56 @@
+/**
+ * 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());
+    }
+}