diff options
author | Niharika Sharma <niharika.sharma@amdocs.com> | 2021-03-25 17:07:04 -0400 |
---|---|---|
committer | Niharika Sharma <niharika.sharma@amdocs.com> | 2021-03-25 21:32:01 +0000 |
commit | d010436eadddc878ddfc50c8f8908817f5231804 (patch) | |
tree | 7db98819fab15826b514cb819a84b599f56f405e /src/main/java | |
parent | eab4c7ce3ebe4d202f94b22836c9e1b9af023d84 (diff) |
Fixed Concurrent Updates overriding the AAI object such as Pserver
Issue-ID: AAI-3308
Signed-off-by: Niharika Sharma <niharika.sharma@amdocs.com>
Change-Id: I5f5b89d6304f382c186ae03f3f70ba60097ff6e3
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/onap/aai/dbgen/schemamod/SchemaMod.java | 13 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/dbgen/schemamod/SchemaModInternalBatch.java | 21 |
2 files changed, 25 insertions, 9 deletions
diff --git a/src/main/java/org/onap/aai/dbgen/schemamod/SchemaMod.java b/src/main/java/org/onap/aai/dbgen/schemamod/SchemaMod.java index 6e48d4b..7fbc449 100644 --- a/src/main/java/org/onap/aai/dbgen/schemamod/SchemaMod.java +++ b/src/main/java/org/onap/aai/dbgen/schemamod/SchemaMod.java @@ -68,23 +68,26 @@ public class SchemaMod { String targetDataType = ""; String targetIndexInfo = ""; String preserveDataFlag = ""; + String consistencyLockFlag = ""; String commitBlockSizeStr = ""; long commitBlockSize = 120000; - String usageString = "Usage: SchemaMod propertyName targetDataType targetIndexInfo preserveDataFlag [blockSize] \n"; + String usageString = "Usage: SchemaMod propertyName targetDataType targetIndexInfo preserveDataFlag consistencyLockFlag [blockSize] \n"; - if (args.length == 4) { + if (args.length == 5) { propName = args[0]; targetDataType = args[1]; targetIndexInfo = args[2]; preserveDataFlag = args[3]; + consistencyLockFlag = args[4]; } - else if (args.length == 5) { + else if (args.length == 6) { propName = args[0]; targetDataType = args[1]; targetIndexInfo = args[2]; preserveDataFlag = args[3]; - commitBlockSizeStr = args[4]; + consistencyLockFlag = args[4]; + commitBlockSizeStr = args[5]; } else { String emsg = "Incorrect number of Parameters passed. \n" + usageString; @@ -148,7 +151,7 @@ public class SchemaMod { TransactionalGraphEngine engine = null; try { engine = new JanusGraphDBEngine(queryStyle, loader); - SchemaModInternalBatch internal = new SchemaModInternalBatch(engine, logger, propName, targetDataType, targetIndexInfo, Boolean.parseBoolean(preserveDataFlag), commitBlockSize); + SchemaModInternalBatch internal = new SchemaModInternalBatch(engine, logger, propName, targetDataType, targetIndexInfo, Boolean.parseBoolean(preserveDataFlag), Boolean.parseBoolean(consistencyLockFlag), commitBlockSize); internal.execute(); engine.startTransaction(); engine.tx().close(); diff --git a/src/main/java/org/onap/aai/dbgen/schemamod/SchemaModInternalBatch.java b/src/main/java/org/onap/aai/dbgen/schemamod/SchemaModInternalBatch.java index e88e2bf..e88c261 100644 --- a/src/main/java/org/onap/aai/dbgen/schemamod/SchemaModInternalBatch.java +++ b/src/main/java/org/onap/aai/dbgen/schemamod/SchemaModInternalBatch.java @@ -32,6 +32,8 @@ import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.VertexProperty; +import org.janusgraph.core.schema.ConsistencyModifier; +import org.janusgraph.core.schema.JanusGraphIndex; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.util.FormatDate; @@ -48,17 +50,19 @@ public class SchemaModInternalBatch { private final Class<?> type; private final String indexType; private final boolean preserveData; + private final boolean consistencyLock; private final Cardinality cardinality; private final long commitBlockSize; private final Logger logger; public SchemaModInternalBatch(TransactionalGraphEngine engine, Logger logger, String propName, - String type, String indexType, boolean preserveData, long commitBlockSize) { + String type, String indexType, boolean preserveData, boolean consistencyLock, long commitBlockSize) { this.engine = engine; this.propName = propName; this.type = determineClass(type); this.indexType = indexType; this.preserveData = preserveData; + this.consistencyLock = consistencyLock; this.cardinality = determineCardinality(type); this.commitBlockSize = commitBlockSize; this.logger = logger; @@ -226,14 +230,23 @@ public class SchemaModInternalBatch { // targetDataType PropertyKey freshPropKey = graphMgt.makePropertyKey(propName).dataType(type) .cardinality(cardinality).make(); - + if (consistencyLock) { + logAndPrint(logger, " -- Consistency Lock is being set on the property "); + graphMgt.setConsistency(freshPropKey, ConsistencyModifier.LOCK); + } // Create the appropriate index (if any) + JanusGraphIndex indexG = null; if (indexType.equals("uniqueIndex")) { String freshIndexName = propName + dteStr; - graphMgt.buildIndex(freshIndexName, Vertex.class).addKey(freshPropKey).unique().buildCompositeIndex(); + indexG = graphMgt.buildIndex(freshIndexName, Vertex.class).addKey(freshPropKey).unique().buildCompositeIndex(); } else if (indexType.equals("index")) { String freshIndexName = propName + dteStr; - graphMgt.buildIndex(freshIndexName, Vertex.class).addKey(freshPropKey).buildCompositeIndex(); + indexG = graphMgt.buildIndex(freshIndexName, Vertex.class).addKey(freshPropKey).buildCompositeIndex(); + } + + if(indexG != null && consistencyLock) { + logAndPrint(logger, " -- Consistency Lock is being set on the index "); + graphMgt.setConsistency(indexG, ConsistencyModifier.LOCK); } logAndPrint(logger, "Committing schema changes with graphMgt.commit()"); |