Java Code Examples for com.thinkaurelius.titan.graphdb.database.StandardTitanGraph

The following are top voted examples for showing how to use com.thinkaurelius.titan.graphdb.database.StandardTitanGraph. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: mizo   File: MizoRDD.java   View source code 6 votes vote down vote up
/**
 * Given a path for Titan config file, connects and gets the internal Titan types,
 * converting them to MizoTitanRelationTypes mapped by type-ids
 * @param titanConfigPath Path to Titan's config path
 * @return Mapping between relation type-ids to InternalRelationType instances
 */
protected static HashMap<Long, MizoTitanRelationType> loadRelationTypes(String titanConfigPath) {
    TitanGraph g = TitanFactory.open(titanConfigPath);
    StandardTitanTx tx = (StandardTitanTx)g.buildTransaction().readOnly().start();

    HashMap<Long, MizoTitanRelationType> relations = Maps.newHashMap();

    tx.query()
            .has(BaseKey.SchemaCategory, Contain.IN, Lists.newArrayList(TitanSchemaCategory.values()))
            .vertices()
            .forEach(v -> {
                if (v instanceof InternalRelationType)
                    relations.put(v.longId(), new MizoTitanRelationType((InternalRelationType)v));
            });

    tx.close();

    try {
        ((StandardTitanGraph)g).getBackend().close();
    } catch (BackendException e) {
        e.printStackTrace();
    }

    return relations;
}
 
Example 2
Project: titan1withtp3.1   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByThreadBoundTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx();
    assertEquals("ALL",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("LOCAL_QUORUM",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
}
 
Example 3
Project: titan1withtp3.1   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.newTransaction();
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("THREE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 4
Project: titan1withtp3.1   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testCustomConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction()
            .customOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE")
            .customOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();

    assertEquals("ONE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 5
Project: titan1withtp3.1   File: EdgeSerializerTest.java   View source code 6 votes vote down vote up
@Test
public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanManagement mgmt = graph.openManagement();
    EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    for (int i=1;i<=5;i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make();
    mgmt.commit();

    TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    TitanEdge e1 = v1.addEdge("father",v2);
    for (int i=1;i<=5;i++) e1.property("key"+i,i);

    graph.tx().commit();

    e1.remove();
    graph.tx().commit();

}
 
Example 6
Project: titan0.5.4-hbase1.1.1-custom   File: TitanCleanup.java   View source code 6 votes vote down vote up
/**
 * Clears out the entire graph. This will delete ALL of the data stored in this graph and the data will NOT be
 * recoverable. This method is intended only for development and testing use.
 *
 * @param graph
 * @throws IllegalArgumentException if the graph has not been shut down
 * @throws com.thinkaurelius.titan.core.TitanException if clearing the storage is unsuccessful
 */
public static final void clear(TitanGraph graph) {
    Preconditions.checkNotNull(graph);
    Preconditions.checkArgument(graph instanceof StandardTitanGraph,"Invalid graph instance detected: %s",graph.getClass());
    StandardTitanGraph g = (StandardTitanGraph)graph;
    Preconditions.checkArgument(!g.isOpen(),"Graph needs to be shut down before it can be cleared.");
    final GraphDatabaseConfiguration config = g.getConfiguration();
    BackendOperation.execute(new Callable<Boolean>(){
        @Override
        public Boolean call() throws Exception {
            config.getBackend().clearStorage();
            return true;
        }
        @Override
        public String toString() { return "ClearBackend"; }
    },new StandardDuration(20, TimeUnit.SECONDS));
}
 
Example 7
Project: titan1withtp3.1   File: StandardTransactionBuilder.java   View source code 6 votes vote down vote up
public StandardTransactionBuilder(GraphDatabaseConfiguration graphConfig, StandardTitanGraph graph, Configuration customOptions) {
    Preconditions.checkNotNull(graphConfig);
    Preconditions.checkNotNull(graph);
    if (graphConfig.isReadOnly()) readOnly();
    if (graphConfig.isBatchLoading()) enableBatchLoading();
    this.graph = graph;
    this.defaultSchemaMaker = graphConfig.getDefaultSchemaMaker();
    this.assignIDsImmediately = graphConfig.hasFlushIDs();
    this.forceIndexUsage = graphConfig.hasForceIndexUsage();
    this.groupName = graphConfig.getMetricsPrefix();
    this.propertyPrefetching = graphConfig.hasPropertyPrefetching();
    this.writableCustomOptions = null;
    this.customOptions = customOptions;
    vertexCacheSize(graphConfig.getTxVertexCacheSize());
    dirtyVertexSize(graphConfig.getTxDirtyVertexSize());


    // KAFKA PRODUCER
    this.logIdentifier = null;
    boolean logAll = graphConfig.getLogAllTransactions();

    if (logAll) {
        this.logIdentifier = graphConfig.getAllLogTransactionName();

    }
}
 
Example 8
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 6 votes vote down vote up
public ManagementSystem(StandardTitanGraph graph, KCVSConfiguration config, Log sysLog,
                        ManagementLogger mgmtLogger, SchemaCache schemaCache) {
    Preconditions.checkArgument(config != null && graph != null && sysLog != null && mgmtLogger != null);
    this.graph = graph;
    this.baseConfig = config;
    this.sysLog = sysLog;
    this.mgmtLogger = mgmtLogger;
    this.schemaCache = schemaCache;
    this.transactionalConfig = new TransactionalConfiguration(baseConfig);
    this.modifyConfig = new ModifiableConfiguration(ROOT_NS,
            transactionalConfig, BasicConfiguration.Restriction.GLOBAL);
    this.userConfig = new UserModifiableConfiguration(modifyConfig, configVerifier);

    this.updatedTypes = new HashSet<TitanSchemaVertex>();
    this.updatedTypeTriggers = new HashSet<Callable<Boolean>>();
    this.graphShutdownRequired = false;

    this.transaction = (StandardTitanTx) graph.buildTransaction().disableBatchLoading().start();
    this.txStartTime = graph.getConfiguration().getTimestampProvider().getTime();
    this.isOpen = true;
}
 
Example 9
Project: titan1withtp3.1   File: TitanCleanup.java   View source code 6 votes vote down vote up
/**
 * Clears out the entire graph. This will delete ALL of the data stored in this graph and the data will NOT be
 * recoverable. This method is intended only for development and testing use.
 *
 * @param graph
 * @throws IllegalArgumentException if the graph has not been shut down
 * @throws com.thinkaurelius.titan.core.TitanException if clearing the storage is unsuccessful
 */
public static final void clear(TitanGraph graph) {
    Preconditions.checkNotNull(graph);
    Preconditions.checkArgument(graph instanceof StandardTitanGraph,"Invalid graph instance detected: %s",graph.getClass());
    StandardTitanGraph g = (StandardTitanGraph)graph;
    Preconditions.checkArgument(!g.isOpen(),"Graph needs to be shut down before it can be cleared.");
    final GraphDatabaseConfiguration config = g.getConfiguration();
    BackendOperation.execute(new Callable<Boolean>(){
        @Override
        public Boolean call() throws Exception {
            config.getBackend().clearStorage();
            return true;
        }
        @Override
        public String toString() { return "ClearBackend"; }
    }, Duration.ofSeconds(20));
}
 
Example 10
Project: titan1.0.1.kafka   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByThreadBoundTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx();
    assertEquals("ALL",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("LOCAL_QUORUM",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
}
 
Example 11
Project: titan1.0.1.kafka   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.newTransaction();
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("THREE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 12
Project: titan1.0.1.kafka   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testCustomConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction()
            .customOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE")
            .customOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();

    assertEquals("ONE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 13
Project: titan1.0.1.kafka   File: EdgeSerializerTest.java   View source code 6 votes vote down vote up
@Test
public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanManagement mgmt = graph.openManagement();
    EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    for (int i=1;i<=5;i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make();
    mgmt.commit();

    TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    TitanEdge e1 = v1.addEdge("father",v2);
    for (int i=1;i<=5;i++) e1.property("key"+i,i);

    graph.tx().commit();

    e1.remove();
    graph.tx().commit();

}
 
Example 14
Project: titan1.0.1.kafka   File: StandardTransactionBuilder.java   View source code 6 votes vote down vote up
/**
 * Constructs a new TitanTransaction configuration with default configuration parameters.
 */
public StandardTransactionBuilder(GraphDatabaseConfiguration graphConfig, StandardTitanGraph graph) {
    Preconditions.checkNotNull(graphConfig);
    Preconditions.checkNotNull(graph);
    if (graphConfig.isReadOnly()) readOnly();
    if (graphConfig.isBatchLoading()) enableBatchLoading();
    this.graph = graph;
    this.defaultSchemaMaker = graphConfig.getDefaultSchemaMaker();
    this.assignIDsImmediately = graphConfig.hasFlushIDs();
    this.forceIndexUsage = graphConfig.hasForceIndexUsage();
    this.groupName = graphConfig.getMetricsPrefix();

    // KAFKA PRODUCER
    boolean logAll = graphConfig.getLogAllTransactions();

    if (logAll)
        this.logIdentifier = graphConfig.getAllLogTransactionName();
    else
        this.logIdentifier = null;

    this.propertyPrefetching = graphConfig.hasPropertyPrefetching();
    this.writableCustomOptions = GraphDatabaseConfiguration.buildGraphConfiguration();
    this.customOptions = new MergedConfiguration(writableCustomOptions, graphConfig.getConfiguration());
    vertexCacheSize(graphConfig.getTxVertexCacheSize());
    dirtyVertexSize(graphConfig.getTxDirtyVertexSize());
}
 
Example 15
Project: titan1.0.1.kafka   File: StandardTransactionBuilder.java   View source code 6 votes vote down vote up
public StandardTransactionBuilder(GraphDatabaseConfiguration graphConfig, StandardTitanGraph graph, Configuration customOptions) {
    Preconditions.checkNotNull(graphConfig);
    Preconditions.checkNotNull(graph);
    if (graphConfig.isReadOnly()) readOnly();
    if (graphConfig.isBatchLoading()) enableBatchLoading();
    this.graph = graph;
    this.defaultSchemaMaker = graphConfig.getDefaultSchemaMaker();
    this.assignIDsImmediately = graphConfig.hasFlushIDs();
    this.forceIndexUsage = graphConfig.hasForceIndexUsage();
    this.groupName = graphConfig.getMetricsPrefix();
    this.logIdentifier = null;
    this.propertyPrefetching = graphConfig.hasPropertyPrefetching();
    this.writableCustomOptions = null;
    this.customOptions = customOptions;
    vertexCacheSize(graphConfig.getTxVertexCacheSize());
    dirtyVertexSize(graphConfig.getTxDirtyVertexSize());
}
 
Example 16
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 6 votes vote down vote up
public ManagementSystem(StandardTitanGraph graph, KCVSConfiguration config, Log sysLog,
                        ManagementLogger mgmtLogger, SchemaCache schemaCache) {
    Preconditions.checkArgument(config != null && graph != null && sysLog != null && mgmtLogger != null);
    this.graph = graph;
    this.baseConfig = config;
    this.sysLog = sysLog;
    this.mgmtLogger = mgmtLogger;
    this.schemaCache = schemaCache;
    this.transactionalConfig = new TransactionalConfiguration(baseConfig);
    this.modifyConfig = new ModifiableConfiguration(ROOT_NS,
            transactionalConfig, BasicConfiguration.Restriction.GLOBAL);
    this.userConfig = new UserModifiableConfiguration(modifyConfig, configVerifier);

    this.updatedTypes = new HashSet<TitanSchemaVertex>();
    this.updatedTypeTriggers = new HashSet<Callable<Boolean>>();
    this.graphShutdownRequired = false;

    this.transaction = (StandardTitanTx) graph.buildTransaction().disableBatchLoading().start();
    this.txStartTime = graph.getConfiguration().getTimestampProvider().getTime();
    this.isOpen = true;
}
 
Example 17
Project: titan1.0.1.kafka   File: TitanCleanup.java   View source code 6 votes vote down vote up
/**
 * Clears out the entire graph. This will delete ALL of the data stored in this graph and the data will NOT be
 * recoverable. This method is intended only for development and testing use.
 *
 * @param graph
 * @throws IllegalArgumentException if the graph has not been shut down
 * @throws com.thinkaurelius.titan.core.TitanException if clearing the storage is unsuccessful
 */
public static final void clear(TitanGraph graph) {
    Preconditions.checkNotNull(graph);
    Preconditions.checkArgument(graph instanceof StandardTitanGraph,"Invalid graph instance detected: %s",graph.getClass());
    StandardTitanGraph g = (StandardTitanGraph)graph;
    Preconditions.checkArgument(!g.isOpen(),"Graph needs to be shut down before it can be cleared.");
    final GraphDatabaseConfiguration config = g.getConfiguration();
    BackendOperation.execute(new Callable<Boolean>(){
        @Override
        public Boolean call() throws Exception {
            config.getBackend().clearStorage();
            return true;
        }
        @Override
        public String toString() { return "ClearBackend"; }
    }, Duration.ofSeconds(20));
}
 
Example 18
Project: titan0.5.4-hbase1.1.1-custom   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByThreadBoundTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx();
    assertEquals("ALL",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("LOCAL_QUORUM",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
}
 
Example 19
Project: titan0.5.4-hbase1.1.1-custom   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testCustomConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction()
            .setCustomOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE")
            .setCustomOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();

    assertEquals("ONE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 20
Project: titan0.5.4-hbase1.1.1-custom   File: EdgeSerializerTest.java   View source code 6 votes vote down vote up
@Test
public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanManagement mgmt = graph.getManagementSystem();
    EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    for (int i=1;i<=5;i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make();
    mgmt.commit();

    TitanVertex v1 = graph.addVertex(null), v2 = graph.addVertex(null);
    TitanEdge e1 = v1.addEdge("father",v2);
    for (int i=1;i<=5;i++) e1.setProperty("key"+i,i);

    graph.commit();

    e1.remove();
    graph.commit();

}
 
Example 21
Project: titan0.5.4-hbase1.1.1-custom   File: TitanIndexRepairMapper.java   View source code 6 votes vote down vote up
@Override
public void setup(
        final Mapper<NullWritable, FaunusVertex, NullWritable, NullWritable>.Context context) throws IOException {
    Configuration hadoopConf = DEFAULT_COMPAT.getContextConfiguration(context);
    ModifiableHadoopConfiguration faunusConf = ModifiableHadoopConfiguration.of(hadoopConf);
    BasicConfiguration titanConf = faunusConf.getOutputConf();
    indexName = faunusConf.get(TitanHadoopConfiguration.INDEX_NAME);
    indexType = faunusConf.get(TitanHadoopConfiguration.INDEX_TYPE);

    try {
        Preconditions.checkNotNull(indexName, "Need to provide at least an index name for re-index job");
        log.info("Read index information: name={} type={}", indexName, indexType);
        graph = (StandardTitanGraph)TitanFactory.open(titanConf);
        SchemaContainer schema = new SchemaContainer(graph);
        FaunusSchemaManager typeManager = FaunusSchemaManager.getTypeManager(titanConf);
        typeManager.setSchemaProvider(schema);
        log.info("Opened graph {}", graph);
        mgmt = (ManagementSystem) graph.getManagementSystem();
        validateIndexStatus();
    } catch (final Exception e) {
        if (null != mgmt && mgmt.isOpen())
            mgmt.rollback();
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.FAILED_TRANSACTIONS, 1L);
        throw new IOException(e.getMessage(), e);
    }
}
 
Example 22
Project: titan0.5.4-hbase1.1.1-custom   File: StandardTransactionBuilder.java   View source code 6 votes vote down vote up
/**
 * Constructs a new TitanTransaction configuration with default configuration parameters.
 */
public StandardTransactionBuilder(GraphDatabaseConfiguration graphConfig, StandardTitanGraph graph) {
    Preconditions.checkNotNull(graphConfig);
    Preconditions.checkNotNull(graph);
    if (graphConfig.isReadOnly()) readOnly();
    if (graphConfig.isBatchLoading()) enableBatchLoading();
    this.graph = graph;
    this.defaultSchemaMaker = graphConfig.getDefaultSchemaMaker();
    this.assignIDsImmediately = graphConfig.hasFlushIDs();
    this.forceIndexUsage = graphConfig.hasForceIndexUsage();
    this.groupName = graphConfig.getMetricsPrefix();
    this.logIdentifier = null;
    this.propertyPrefetching = graphConfig.hasPropertyPrefetching();
    this.writableCustomOptions = GraphDatabaseConfiguration.buildConfiguration();
    this.customOptions = new MergedConfiguration(writableCustomOptions, graphConfig.getConfiguration());
    setVertexCacheSize(graphConfig.getTxVertexCacheSize());
    setDirtyVertexSize(graphConfig.getTxDirtyVertexSize());
}
 
Example 23
Project: titan0.5.4-hbase1.1.1-custom   File: StandardTransactionBuilder.java   View source code 6 votes vote down vote up
public StandardTransactionBuilder(GraphDatabaseConfiguration graphConfig, StandardTitanGraph graph, Configuration customOptions) {
    Preconditions.checkNotNull(graphConfig);
    Preconditions.checkNotNull(graph);
    if (graphConfig.isReadOnly()) readOnly();
    if (graphConfig.isBatchLoading()) enableBatchLoading();
    this.graph = graph;
    this.defaultSchemaMaker = graphConfig.getDefaultSchemaMaker();
    this.assignIDsImmediately = graphConfig.hasFlushIDs();
    this.forceIndexUsage = graphConfig.hasForceIndexUsage();
    this.groupName = graphConfig.getMetricsPrefix();
    this.logIdentifier = null;
    this.propertyPrefetching = graphConfig.hasPropertyPrefetching();
    this.writableCustomOptions = null;
    this.customOptions = customOptions;
    setVertexCacheSize(graphConfig.getTxVertexCacheSize());
    setDirtyVertexSize(graphConfig.getTxDirtyVertexSize());
}
 
Example 24
Project: titan0.5.4-hbase1.1.1-custom   File: ManagementSystem.java   View source code 6 votes vote down vote up
public ManagementSystem(StandardTitanGraph graph, KCVSConfiguration config, Log sysLog,
                        ManagementLogger mgmtLogger, SchemaCache schemaCache) {
    Preconditions.checkArgument(config!=null && graph!=null && sysLog!=null && mgmtLogger!=null);
    this.graph = graph;
    this.baseConfig = config;
    this.sysLog = sysLog;
    this.mgmtLogger = mgmtLogger;
    this.schemaCache = schemaCache;
    this.transactionalConfig = new TransactionalConfiguration(baseConfig);
    this.modifyConfig = new ModifiableConfiguration(ROOT_NS,
            transactionalConfig, BasicConfiguration.Restriction.GLOBAL);
    this.userConfig = new UserModifiableConfiguration(modifyConfig,configVerifier);

    this.updatedTypes = new HashSet<TitanSchemaVertex>();
    this.updatedTypeTriggers = new HashSet<Callable<Boolean>>();
    this.graphShutdownRequired = false;

    this.transaction = (StandardTitanTx) graph.buildTransaction().disableBatchLoading().start();
    this.txStartTime = graph.getConfiguration().getTimestampProvider().getTime();
    this.isOpen = true;
}
 
Example 25
Project: titan1withtp3.1   File: SerializerGraphConfiguration.java   View source code 5 votes vote down vote up
@Before
public void initialize() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    config.set(GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS, TClass1.class.getName(), "attribute1");
    config.set(GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS, TClass1Serializer.class.getName(), "attribute1");
    config.set(GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS, TEnum.class.getName(), "attribute4");
    config.set(GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS, TEnumSerializer.class.getName(), "attribute4");
    graph = (StandardTitanGraph) TitanFactory.open(config);
}
 
Example 26
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
private UpdateStatusTrigger(StandardTitanGraph graph, TitanSchemaVertex vertex, SchemaStatus newStatus, Iterable<PropertyKeyVertex> keys) {
    this.graph = graph;
    this.schemaVertexId = vertex.longId();
    this.newStatus = newStatus;
    this.propertyKeys = Sets.newHashSet(Iterables.transform(keys, new Function<PropertyKey, Long>() {
        @Nullable
        @Override
        public Long apply(@Nullable PropertyKey propertyKey) {
            return propertyKey.longId();
        }
    }));
}
 
Example 27
Project: titan1withtp3.1   File: ManagementLogger.java   View source code 5 votes vote down vote up
public ManagementLogger(StandardTitanGraph graph, Log sysLog, SchemaCache schemaCache, TimestampProvider times) {
    this.graph = graph;
    this.schemaCache = schemaCache;
    this.sysLog = sysLog;
    this.times = times;
    Preconditions.checkNotNull(times);
}
 
Example 28
Project: titan1withtp3.1   File: StandardLogProcessorFramework.java   View source code 5 votes vote down vote up
public StandardLogProcessorFramework(StandardTitanGraph graph) {
    Preconditions.checkArgument(graph!=null && graph.isOpen());
    this.graph = graph;
    this.serializer = graph.getDataSerializer();
    this.times = graph.getConfiguration().getTimestampProvider();
    this.processorLogs = new HashMap<String, Log>();
}
 
Example 29
Project: titan1withtp3.1   File: VertexJobConverter.java   View source code 5 votes vote down vote up
public static StandardTitanTx startTransaction(StandardTitanGraph graph) {
    StandardTransactionBuilder txb = graph.buildTransaction().readOnly();
    txb.setPreloadedData(true);
    txb.checkInternalVertexExistence(false);
    txb.dirtyVertexSize(0);
    txb.vertexCacheSize(0);
    return (StandardTitanTx)txb.start();
}
 
Example 30
Project: titan1withtp3.1   File: IndexUpdateJob.java   View source code 5 votes vote down vote up
public void workerIterationStart(TitanGraph graph, Configuration config, ScanMetrics metrics) {
    this.graph = (StandardTitanGraph)graph;
    Preconditions.checkArgument(config.has(GraphDatabaseConfiguration.JOB_START_TIME),"Invalid configuration for this job. Start time is required.");
    this.jobStartTime = Instant.ofEpochMilli(config.get(GraphDatabaseConfiguration.JOB_START_TIME));
    if (indexName == null) {
        Preconditions.checkArgument(config.has(INDEX_NAME), "Need to configure the name of the index to be repaired");
        indexName = config.get(INDEX_NAME);
        indexRelationTypeName = config.get(INDEX_RELATION_TYPE);
        log.info("Read index information: name={} type={}", indexName, indexRelationTypeName);
    }

    try {
        this.mgmt = (ManagementSystem)graph.openManagement();

        if (isGlobalGraphIndex()) {
            index = mgmt.getGraphIndex(indexName);
        } else {
            indexRelationType = mgmt.getRelationType(indexRelationTypeName);
            Preconditions.checkArgument(indexRelationType!=null,"Could not find relation type: %s", indexRelationTypeName);
            index = mgmt.getRelationIndex(indexRelationType,indexName);
        }
        Preconditions.checkArgument(index!=null,"Could not find index: %s [%s]",indexName,indexRelationTypeName);
        log.info("Found index {}", indexName);
        validateIndexStatus();

        StandardTransactionBuilder txb = this.graph.buildTransaction();
        txb.commitTime(jobStartTime);
        writeTx = (StandardTitanTx)txb.start();
    } catch (final Exception e) {
        if (null != mgmt && mgmt.isOpen())
            mgmt.rollback();
        if (writeTx!=null && writeTx.isOpen())
            writeTx.rollback();
        metrics.incrementCustom(FAILED_TX);
        throw new TitanException(e.getMessage(), e);
    }
}
 
Example 31
Project: titan1withtp3.1   File: PartitionedVertexProgramExecutor.java   View source code 5 votes vote down vote up
public PartitionedVertexProgramExecutor(StandardTitanGraph graph, FulgoraMemory memory,
                             FulgoraVertexMemory vertexMemory, VertexProgram<M> vertexProgram) {
    this.graph=graph;
    this.idManager = graph.getIDManager();
    this.memory = memory;
    this.vertexMemory = vertexMemory;
    this.vertexProgram = vertexProgram;
}
 
Example 32
Project: titan1withtp3.1   File: VertexMapJob.java   View source code 5 votes vote down vote up
public static Executor getVertexMapJob(StandardTitanGraph graph, FulgoraVertexMemory vertexMemory,
                                       Map<MapReduce, FulgoraMapEmitter> mapJobs) {
    VertexMapJob job = new VertexMapJob(graph.getIDManager(), vertexMemory, mapJobs);
    for (Map.Entry<MapReduce, FulgoraMapEmitter> mapJob : mapJobs.entrySet()) {
        mapJob.getKey().workerStart(MapReduce.Stage.MAP);
    }
    return new Executor(graph, job);
}
 
Example 33
Project: titan1.0.1.kafka   File: SerializerGraphConfiguration.java   View source code 5 votes vote down vote up
@Before
public void initialize() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    config.set(GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS, TClass1.class.getName(), "attribute1");
    config.set(GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS, TClass1Serializer.class.getName(), "attribute1");
    config.set(GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS, TEnum.class.getName(), "attribute4");
    config.set(GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS, TEnumSerializer.class.getName(), "attribute4");
    graph = (StandardTitanGraph) TitanFactory.open(config);
}
 
Example 34
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 5 votes vote down vote up
private UpdateStatusTrigger(StandardTitanGraph graph, TitanSchemaVertex vertex, SchemaStatus newStatus, Iterable<PropertyKeyVertex> keys) {
    this.graph = graph;
    this.schemaVertexId = vertex.longId();
    this.newStatus = newStatus;
    this.propertyKeys = Sets.newHashSet(Iterables.transform(keys, new Function<PropertyKey, Long>() {
        @Nullable
        @Override
        public Long apply(@Nullable PropertyKey propertyKey) {
            return propertyKey.longId();
        }
    }));
}
 
Example 35
Project: titan1.0.1.kafka   File: ManagementLogger.java   View source code 5 votes vote down vote up
public ManagementLogger(StandardTitanGraph graph, Log sysLog, SchemaCache schemaCache, TimestampProvider times) {
    this.graph = graph;
    this.schemaCache = schemaCache;
    this.sysLog = sysLog;
    this.times = times;
    Preconditions.checkNotNull(times);
}
 
Example 36
Project: titan1.0.1.kafka   File: StandardLogProcessorFramework.java   View source code 5 votes vote down vote up
public StandardLogProcessorFramework(StandardTitanGraph graph) {
    Preconditions.checkArgument(graph!=null && graph.isOpen());
    this.graph = graph;
    this.serializer = graph.getDataSerializer();
    this.times = graph.getConfiguration().getTimestampProvider();
    this.processorLogs = new HashMap<String, Log>();
}
 
Example 37
Project: titan1.0.1.kafka   File: VertexJobConverter.java   View source code 5 votes vote down vote up
public static StandardTitanTx startTransaction(StandardTitanGraph graph) {
    StandardTransactionBuilder txb = graph.buildTransaction().readOnly();
    txb.setPreloadedData(true);
    txb.checkInternalVertexExistence(false);
    txb.dirtyVertexSize(0);
    txb.vertexCacheSize(0);
    return (StandardTitanTx)txb.start();
}
 
Example 38
Project: titan1.0.1.kafka   File: IndexUpdateJob.java   View source code 5 votes vote down vote up
public void workerIterationStart(TitanGraph graph, Configuration config, ScanMetrics metrics) {
    this.graph = (StandardTitanGraph)graph;
    Preconditions.checkArgument(config.has(GraphDatabaseConfiguration.JOB_START_TIME),"Invalid configuration for this job. Start time is required.");
    this.jobStartTime = Instant.ofEpochMilli(config.get(GraphDatabaseConfiguration.JOB_START_TIME));
    if (indexName == null) {
        Preconditions.checkArgument(config.has(INDEX_NAME), "Need to configure the name of the index to be repaired");
        indexName = config.get(INDEX_NAME);
        indexRelationTypeName = config.get(INDEX_RELATION_TYPE);
        log.info("Read index information: name={} type={}", indexName, indexRelationTypeName);
    }

    try {
        this.mgmt = (ManagementSystem)graph.openManagement();

        if (isGlobalGraphIndex()) {
            index = mgmt.getGraphIndex(indexName);
        } else {
            indexRelationType = mgmt.getRelationType(indexRelationTypeName);
            Preconditions.checkArgument(indexRelationType!=null,"Could not find relation type: %s", indexRelationTypeName);
            index = mgmt.getRelationIndex(indexRelationType,indexName);
        }
        Preconditions.checkArgument(index!=null,"Could not find index: %s [%s]",indexName,indexRelationTypeName);
        log.info("Found index {}", indexName);
        validateIndexStatus();

        StandardTransactionBuilder txb = this.graph.buildTransaction();
        txb.commitTime(jobStartTime);
        writeTx = (StandardTitanTx)txb.start();
    } catch (final Exception e) {
        if (null != mgmt && mgmt.isOpen())
            mgmt.rollback();
        if (writeTx!=null && writeTx.isOpen())
            writeTx.rollback();
        metrics.incrementCustom(FAILED_TX);
        throw new TitanException(e.getMessage(), e);
    }
}
 
Example 39
Project: titan1.0.1.kafka   File: PartitionedVertexProgramExecutor.java   View source code 5 votes vote down vote up
public PartitionedVertexProgramExecutor(StandardTitanGraph graph, FulgoraMemory memory,
                             FulgoraVertexMemory vertexMemory, VertexProgram<M> vertexProgram) {
    this.graph=graph;
    this.idManager = graph.getIDManager();
    this.memory = memory;
    this.vertexMemory = vertexMemory;
    this.vertexProgram = vertexProgram;
}
 
Example 40
Project: titan1.0.1.kafka   File: VertexMapJob.java   View source code 5 votes vote down vote up
public static Executor getVertexMapJob(StandardTitanGraph graph, FulgoraVertexMemory vertexMemory,
                                       Map<MapReduce, FulgoraMapEmitter> mapJobs) {
    VertexMapJob job = new VertexMapJob(graph.getIDManager(), vertexMemory, mapJobs);
    for (Map.Entry<MapReduce, FulgoraMapEmitter> mapJob : mapJobs.entrySet()) {
        mapJob.getKey().workerStart(MapReduce.Stage.MAP);
    }
    return new Executor(graph, job);
}