Commit 8dc4041c by Sarath Subramanian

ATLAS-3104: Fix stale transaction alerts in atlas logs

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