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);
}
}
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);
}
}
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();
}
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();
}
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);
}
Aggregations