Search in sources :

Example 6 with WriteConfiguration

use of org.janusgraph.diskstorage.configuration.WriteConfiguration in project janusgraph by JanusGraph.

the class JanusGraphTest method testManagedOptionMasking.

@Test
public void testManagedOptionMasking() throws BackendException {
    // Can't use clopen(...) for this test, because it's aware local vs global option types and
    // uses ManagementSystem where necessary.  We want to simulate an erroneous attempt to
    // override global options by tweaking the local config file (ignoring ManagementSystem),
    // so we have to bypass clopen(...).
    // clopen(
    // option(ALLOW_STALE_CONFIG), false,
    // option(ATTRIBUTE_ALLOW_ALL_SERIALIZABLE), false);
    // Check this test's assumptions about option default values
    Duration customCommitTime = Duration.ofMillis(456L);
    Preconditions.checkState(ALLOW_STALE_CONFIG.getDefaultValue());
    Preconditions.checkState(ALLOW_STALE_CONFIG.getType().equals(ConfigOption.Type.MASKABLE));
    Preconditions.checkState(!customCommitTime.equals(MAX_COMMIT_TIME.getDefaultValue()));
    // Disallow managed option masking and verify exception at graph startup
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), false);
    wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime);
    try {
        graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
        fail("Masking managed config options should be disabled in this configuration");
    } catch (JanusGraphConfigurationException e) {
        // Exception should cite the problematic setting's full name
        assertTrue(e.getMessage().contains(ConfigElement.getPath(MAX_COMMIT_TIME)));
    }
    // Allow managed option masking (default config again) and check that the local value is ignored and
    // that no exception is thrown
    close();
    wc = getConfiguration();
    wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), true);
    wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime);
    graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
    // Local value should be overridden by the default that already exists in the backend
    assertEquals(MAX_COMMIT_TIME.getDefaultValue(), graph.getConfiguration().getMaxCommitTime());
    // Wipe the storage backend
    graph.getBackend().clearStorage();
    try {
        graph.close();
    } catch (Throwable t) {
        log.debug("Swallowing throwable during shutdown after clearing backend storage", t);
    }
    // Bootstrap a new DB with managed option masking disabled
    wc = getConfiguration();
    wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), false);
    graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
    close();
    // Check for expected exception
    wc = getConfiguration();
    wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime);
    try {
        graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
        fail("Masking managed config options should be disabled in this configuration");
    } catch (JanusGraphConfigurationException e) {
        // Exception should cite the problematic setting's full name
        assertTrue(e.getMessage().contains(ConfigElement.getPath(MAX_COMMIT_TIME)));
    }
    // Now check that ALLOW_STALE_CONFIG is actually MASKABLE -- enable it in the local config
    wc = getConfiguration();
    wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), true);
    wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime);
    graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
    // Local value should be overridden by the default that already exists in the backend
    assertEquals(MAX_COMMIT_TIME.getDefaultValue(), graph.getConfiguration().getMaxCommitTime());
}
Also used : JanusGraphConfigurationException(org.janusgraph.core.JanusGraphConfigurationException) Duration(java.time.Duration) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) Test(org.junit.Test)

Example 7 with WriteConfiguration

use of org.janusgraph.diskstorage.configuration.WriteConfiguration in project janusgraph by JanusGraph.

the class AbstractJanusGraphProvider method clear.

// @Override
// public <ID> ID reconstituteGraphSONIdentifier(final Class<? extends Element> clazz, final Object id) {
// if (Edge.class.isAssignableFrom(clazz)) {
// // JanusGraphSONModule toStrings the edgeId - expect a String value for the id
// if (!(id instanceof String)) throw new RuntimeException("Expected a String value for the RelationIdentifier");
// return (ID) RelationIdentifier.parse((String) id);
// } else {
// return (ID) id;
// }
// }
@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
    if (null != g) {
        while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
        JanusGraph graph = (JanusGraph) g;
        if (graph.isOpen()) {
            if (g.tx().isOpen())
                g.tx().rollback();
            try {
                g.close();
            } catch (IOException | IllegalStateException e) {
                logger.warn("Titan graph may not have closed cleanly", e);
            }
        }
    }
    WriteConfiguration config = new CommonsConfiguration(configuration);
    BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
    if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
        JanusGraphBaseTest.clearGraph(config);
    }
}
Also used : Graph(org.apache.tinkerpop.gremlin.structure.Graph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) WrappedGraph(org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedGraph) JanusGraph(org.janusgraph.core.JanusGraph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraph(org.janusgraph.core.JanusGraph) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) IOException(java.io.IOException) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) WrappedGraph(org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedGraph)

Example 8 with WriteConfiguration

use of org.janusgraph.diskstorage.configuration.WriteConfiguration in project janusgraph by JanusGraph.

the class JanusGraphPartitionGraphTest method getConfiguration.

@Override
public WriteConfiguration getConfiguration() {
    WriteConfiguration config = getBaseConfiguration();
    ModifiableConfiguration modifiableConfiguration = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
    // Let GraphDatabaseConfiguration's config freezer set CLUSTER_PARTITION
    // modifiableConfiguration.set(GraphDatabaseConfiguration.CLUSTER_PARTITION,true);
    modifiableConfiguration.set(GraphDatabaseConfiguration.CLUSTER_MAX_PARTITIONS, numPartitions);
    // uses SimpleBulkPlacementStrategy by default
    modifiableConfiguration.set(SimpleBulkPlacementStrategy.CONCURRENT_PARTITIONS, 3 * numPartitions);
    return config;
}
Also used : ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration)

Example 9 with WriteConfiguration

use of org.janusgraph.diskstorage.configuration.WriteConfiguration in project janusgraph by JanusGraph.

the class CassandraGraphTest method testCustomConfigUsedByTx.

@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 = (StandardJanusGraph) JanusGraphFactory.open(wc);
    StandardJanusGraphTx tx = (StandardJanusGraphTx) 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();
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) Test(org.junit.Test)

Example 10 with WriteConfiguration

use of org.janusgraph.diskstorage.configuration.WriteConfiguration in project janusgraph by JanusGraph.

the class CassandraGraphTest method testGraphConfigUsedByThreadBoundTx.

@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 = (StandardJanusGraph) JanusGraphFactory.open(wc);
    StandardJanusGraphTx tx = (StandardJanusGraphTx) 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));
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) Test(org.junit.Test)

Aggregations

WriteConfiguration (org.janusgraph.diskstorage.configuration.WriteConfiguration)10 Test (org.junit.Test)7 StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)3 BasicConfiguration (org.janusgraph.diskstorage.configuration.BasicConfiguration)2 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Duration (java.time.Duration)1 Appender (org.apache.log4j.Appender)1 Level (org.apache.log4j.Level)1 Logger (org.apache.log4j.Logger)1 PatternLayout (org.apache.log4j.PatternLayout)1 WriterAppender (org.apache.log4j.WriterAppender)1 Graph (org.apache.tinkerpop.gremlin.structure.Graph)1 WrappedGraph (org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedGraph)1 JanusGraph (org.janusgraph.core.JanusGraph)1 JanusGraphConfigurationException (org.janusgraph.core.JanusGraphConfigurationException)1 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)1 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)1 CassandraGraphTest (org.janusgraph.graphdb.CassandraGraphTest)1