Search in sources :

Example 6 with IndexProvider

use of org.janusgraph.diskstorage.indexing.IndexProvider in project janusgraph by JanusGraph.

the class Backend method clearStorage.

/**
 * Clears the storage of all registered backend data providers. This includes backend storage engines and index providers.
 * <p>
 * IMPORTANT: Clearing storage means that ALL data will be lost and cannot be recovered.
 *
 * @throws BackendException
 */
public synchronized void clearStorage() throws BackendException {
    if (!hasAttemptedClose) {
        hasAttemptedClose = true;
        managementLogManager.close();
        txLogManager.close();
        userLogManager.close();
        scanner.close();
        edgeStore.close();
        indexStore.close();
        idAuthority.close();
        systemConfig.close();
        userConfig.close();
        storeManager.clearStorage();
        storeManager.close();
        // Indexes
        for (IndexProvider index : indexes.values()) {
            index.clearStorage();
            index.close();
        }
    } else {
        log.debug("Backend {} has already been closed or cleared", this);
    }
}
Also used : MetricInstrumentedIndexProvider(org.janusgraph.diskstorage.util.MetricInstrumentedIndexProvider) IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider)

Example 7 with IndexProvider

use of org.janusgraph.diskstorage.indexing.IndexProvider in project janusgraph by JanusGraph.

the class Backend method close.

public synchronized void close() throws BackendException {
    if (!hasAttemptedClose) {
        hasAttemptedClose = true;
        ExceptionWrapper exceptionWrapper = new ExceptionWrapper();
        executeWithCatching(managementLogManager::close, exceptionWrapper);
        executeWithCatching(txLogManager::close, exceptionWrapper);
        executeWithCatching(userLogManager::close, exceptionWrapper);
        executeWithCatching(scanner::close, exceptionWrapper);
        if (edgeStore != null)
            executeWithCatching(edgeStore::close, exceptionWrapper);
        if (indexStore != null)
            executeWithCatching(indexStore::close, exceptionWrapper);
        if (idAuthority != null)
            executeWithCatching(idAuthority::close, exceptionWrapper);
        if (systemConfig != null)
            executeWithCatching(systemConfig::close, exceptionWrapper);
        if (userConfig != null)
            executeWithCatching(userConfig::close, exceptionWrapper);
        executeWithCatching(storeManager::close, exceptionWrapper);
        gracefulExecutorServiceShutdown(threadPool, threadPoolShutdownMaxWaitTime);
        // Indexes
        for (IndexProvider index : indexes.values()) {
            executeWithCatching(index::close, exceptionWrapper);
        }
        throwIfException(exceptionWrapper);
    } else {
        log.debug("Backend {} has already been closed or cleared", this);
    }
}
Also used : MetricInstrumentedIndexProvider(org.janusgraph.diskstorage.util.MetricInstrumentedIndexProvider) IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider) ExceptionWrapper(org.janusgraph.util.datastructures.ExceptionWrapper)

Example 8 with IndexProvider

use of org.janusgraph.diskstorage.indexing.IndexProvider in project janusgraph by JanusGraph.

the class ElasticsearchConfigTest method testIndexCreationOptions.

@ParameterizedTest
@MethodSource("useMappingsForES7Configuration")
public void testIndexCreationOptions(Boolean useMappingsForES7) throws InterruptedException, BackendException, IOException {
    final int shards = 7;
    final CommonsConfiguration cc = new CommonsConfiguration(ConfigurationUtil.createBaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
    if (useMappingsForES7) {
        cc.set("index." + INDEX_NAME + ".elasticsearch.use-mapping-for-es7", String.valueOf(true));
    }
    final ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE);
    esr.setConfiguration(config, INDEX_NAME);
    final Configuration indexConfig = config.restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    simpleWriteAndQuery(idx);
    idx.close();
    final ElasticSearchClient client = ElasticSearchSetup.REST_CLIENT.connect(indexConfig).getClient();
    assertEquals(String.valueOf(shards), client.getIndexSettings("janusgraph_jvmlocal_test_store").get("number_of_shards"));
    client.close();
}
Also used : IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) RestElasticSearchClient(org.janusgraph.diskstorage.es.rest.RestElasticSearchClient) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with IndexProvider

use of org.janusgraph.diskstorage.indexing.IndexProvider in project janusgraph by JanusGraph.

the class ElasticsearchConfigTest method testExternalMappingsViaTemplate.

@ParameterizedTest
@MethodSource("useMappingsForES7Configuration")
public void testExternalMappingsViaTemplate(Boolean useMappingsForES7) throws Exception {
    final Duration maxWrite = Duration.ofMillis(2000L);
    final String storeName = "test_mapping";
    final ModifiableConfiguration modifiableConfiguration = esr.setConfiguration(GraphDatabaseConfiguration.buildGraphConfiguration(), INDEX_NAME).set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME);
    if (useMappingsForES7) {
        modifiableConfiguration.set(USE_MAPPING_FOR_ES7, true, INDEX_NAME);
    }
    final Configuration indexConfig = modifiableConfiguration.restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    final Map<String, Object> content = new HashMap<>(2);
    content.put("template", "janusgraph_test_mapping*");
    if (isMappingUsed(idx)) {
        content.put("mappings", readTypesMapping("/strict_mapping.json").getMappings());
    } else {
        content.put("mappings", readTypelessMapping("/typeless_strict_mapping.json").getMappings());
    }
    executeRequestWithStringEntity(idx, "_template/template_1", content);
    final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
    executeRequest(newMapping);
    final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD));
    final BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
    final IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
    // Test that the "date" property works well.
    idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
    // Test that the "weight" property throws an exception.
    try {
        idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
        fail("should fail");
    } catch (final BackendException e) {
        log.debug(e.getMessage(), e);
    }
    itx.rollback();
    idx.close();
}
Also used : BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) HashMap(java.util.HashMap) IndexTransaction(org.janusgraph.diskstorage.indexing.IndexTransaction) Duration(java.time.Duration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) HttpPut(org.apache.http.client.methods.HttpPut) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with IndexProvider

use of org.janusgraph.diskstorage.indexing.IndexProvider in project janusgraph by JanusGraph.

the class Backend method getIndexes.

private static Map<String, IndexProvider> getIndexes(Configuration config) {
    Set<String> containedIndexNamespaces = config.getContainedNamespaces(INDEX_NS);
    Map<String, IndexProvider> indexesMap = new HashMap<>(containedIndexNamespaces.size());
    for (String index : containedIndexNamespaces) {
        Preconditions.checkArgument(StringUtils.isNotBlank(index), "Invalid index name [%s]", index);
        log.info("Configuring index [{}]", index);
        IndexProvider provider = getImplementationClass(config.restrictTo(index), config.get(INDEX_BACKEND, index), StandardIndexProvider.getAllProviderClasses());
        Preconditions.checkNotNull(provider);
        if (config.get(BASIC_METRICS)) {
            provider = new MetricInstrumentedIndexProvider(provider, METRICS_INDEX_PROVIDER_NAME + "." + index);
        }
        indexesMap.put(index, provider);
    }
    return Collections.unmodifiableMap(indexesMap);
}
Also used : MetricInstrumentedIndexProvider(org.janusgraph.diskstorage.util.MetricInstrumentedIndexProvider) IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MetricInstrumentedIndexProvider(org.janusgraph.diskstorage.util.MetricInstrumentedIndexProvider)

Aggregations

IndexProvider (org.janusgraph.diskstorage.indexing.IndexProvider)10 BasicConfiguration (org.janusgraph.diskstorage.configuration.BasicConfiguration)5 Configuration (org.janusgraph.diskstorage.configuration.Configuration)5 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)5 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)5 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)5 IndexTransaction (org.janusgraph.diskstorage.indexing.IndexTransaction)4 MetricInstrumentedIndexProvider (org.janusgraph.diskstorage.util.MetricInstrumentedIndexProvider)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Duration (java.time.Duration)3 HashMap (java.util.HashMap)3 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)3 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)3 KeyInformation (org.janusgraph.diskstorage.indexing.KeyInformation)3 StandardBaseTransactionConfig (org.janusgraph.diskstorage.util.StandardBaseTransactionConfig)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BackendException (org.janusgraph.diskstorage.BackendException)2 RestElasticSearchClient (org.janusgraph.diskstorage.es.rest.RestElasticSearchClient)2 Map (java.util.Map)1