You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sa...@apache.org on 2019/03/28 21:12:47 UTC

[atlas] branch master updated: ATLAS-3104: Fix stale transaction alerts in atlas logs

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

sarath pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new 8dc4041  ATLAS-3104: Fix stale transaction alerts in atlas logs
8dc4041 is described below

commit 8dc4041c69083292d7d5f9996b10f42e33874077
Author: Sarath Subramanian <ss...@hortonworks.com>
AuthorDate: Thu Mar 28 14:00:12 2019 -0700

    ATLAS-3104: Fix stale transaction alerts in atlas logs
---
 .../java/org/apache/atlas/repository/graphdb/AtlasGraph.java     | 5 +++++
 .../apache/atlas/repository/graphdb/janus/AtlasJanusGraph.java   | 9 +++++++++
 .../apache/atlas/repository/patches/AtlasJavaPatchHandler.java   | 8 ++++----
 .../atlas/repository/patches/UniqueAttributePatchHandler.java    | 8 ++------
 .../atlas/repository/store/graph/v2/AtlasGraphUtilsV2.java       | 8 ++++++++
 5 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraph.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraph.java
index 09eab28..d282c99 100644
--- a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraph.java
+++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraph.java
@@ -208,6 +208,11 @@ public interface AtlasGraph<V, E> {
     void clear();
 
     /**
+     * Gets all open transactions.
+     */
+    Set getOpenTransactions();
+
+    /**
      * Converts the graph to gson and writes it to the specified stream.
      *
      * @param os
diff --git a/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraph.java b/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraph.java
index 9328414..8eea96b 100644
--- a/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraph.java
+++ b/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraph.java
@@ -60,6 +60,7 @@ import org.janusgraph.core.SchemaViolationException;
 import org.janusgraph.core.schema.JanusGraphIndex;
 import org.janusgraph.core.schema.JanusGraphManagement;
 import org.janusgraph.diskstorage.BackendException;
+import org.janusgraph.graphdb.database.StandardJanusGraph;
 
 import javax.script.Bindings;
 import javax.script.ScriptEngine;
@@ -87,6 +88,7 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
 
     private final ConvertGremlinValueFunction GREMLIN_VALUE_CONVERSION_FUNCTION = new ConvertGremlinValueFunction();
     private final Set<String>                 multiProperties                   = new HashSet<>();
+    private final StandardJanusGraph          janusGraph;
 
     public AtlasJanusGraph() {
         //determine multi-properties once at startup
@@ -107,6 +109,8 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
                 mgmt.rollback();
             }
         }
+
+        janusGraph = (StandardJanusGraph) AtlasJanusGraphDatabase.getGraphInstance();
     }
 
     @Override
@@ -217,6 +221,11 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
     }
 
     @Override
+    public Set getOpenTransactions() {
+        return janusGraph.getOpenTransactions();
+    }
+
+    @Override
     public void shutdown() {
         getGraph().close();
     }
diff --git a/repository/src/main/java/org/apache/atlas/repository/patches/AtlasJavaPatchHandler.java b/repository/src/main/java/org/apache/atlas/repository/patches/AtlasJavaPatchHandler.java
index 470ff10..9153d49 100644
--- a/repository/src/main/java/org/apache/atlas/repository/patches/AtlasJavaPatchHandler.java
+++ b/repository/src/main/java/org/apache/atlas/repository/patches/AtlasJavaPatchHandler.java
@@ -84,10 +84,10 @@ public abstract class AtlasJavaPatchHandler {
             setEncodedProperty(patchVertex, CREATED_BY_KEY, getCurrentUser());
             setEncodedProperty(patchVertex, MODIFIED_BY_KEY, getCurrentUser());
 
-            graph.commit();
-
             addToPatchesRegistry(patchId, getPatchStatus());
         }
+
+        graph.commit();
     }
 
     private PatchStatus getPatchStatus(Map<String, PatchStatus> patchesRegistry) {
@@ -108,10 +108,10 @@ public abstract class AtlasJavaPatchHandler {
             setEncodedProperty(patchVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
             setEncodedProperty(patchVertex, MODIFIED_BY_KEY, getCurrentUser());
 
-            graph.commit();
-
             addToPatchesRegistry(getPatchId(), getPatchStatus());
         }
+
+        graph.commit();
     }
 
     public PatchStatus getPatchStatus() {
diff --git a/repository/src/main/java/org/apache/atlas/repository/patches/UniqueAttributePatchHandler.java b/repository/src/main/java/org/apache/atlas/repository/patches/UniqueAttributePatchHandler.java
index 0c65ef1..0e707a5 100644
--- a/repository/src/main/java/org/apache/atlas/repository/patches/UniqueAttributePatchHandler.java
+++ b/repository/src/main/java/org/apache/atlas/repository/patches/UniqueAttributePatchHandler.java
@@ -136,7 +136,6 @@ public class UniqueAttributePatchHandler extends AtlasJavaPatchHandler {
 
     private void registerUniqueAttrPropertyKeys(Collection<AtlasAttribute> attributes) throws IndexException {
         AtlasGraphManagement management = graph.getManagementSystem();
-        boolean              idxCreated = false;
 
         for (AtlasAttribute attribute : attributes) {
             String  uniquePropertyName       = attribute.getVertexUniquePropertyName();
@@ -150,14 +149,11 @@ public class UniqueAttributePatchHandler extends AtlasJavaPatchHandler {
                 AtlasCardinality  cardinality    = indexer.toAtlasCardinality(attributeDef.getCardinality());
 
                 indexer.createVertexIndex(management, uniquePropertyName, UniqueKind.NONE, propertyClass, cardinality, isIndexable, true);
-
-                idxCreated = true;
             }
         }
 
         //Commit indexes
-        if (idxCreated) {
-            indexer.commit(management);
-        }
+        indexer.commit(management);
+        graph.commit();
     }
 }
\ No newline at end of file
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasGraphUtilsV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasGraphUtilsV2.java
index eac2a03..e8d61d1 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasGraphUtilsV2.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasGraphUtilsV2.java
@@ -512,9 +512,17 @@ public class AtlasGraphUtilsV2 {
             LOG.warn("getPatches() returned empty result!");
         }
 
+        getGraphInstance().commit();
+
         return new AtlasPatches(ret);
     }
 
+    public int getOpenTransactions() {
+        Set openTransactions = getGraphInstance().getOpenTransactions();
+
+        return (openTransactions != null) ? openTransactions.size() : 0;
+    }
+
     private static AtlasPatch toAtlasPatch(AtlasVertex vertex) {
         AtlasPatch ret = new AtlasPatch();