Search in sources :

Example 21 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.

the class ElasticSearchIndex method runCommonQuery.

private ElasticSearchResponse runCommonQuery(RawQuery query, BaseTransaction tx, int size, boolean useScroll) throws BackendException {
    final ElasticSearchRequest sr = new ElasticSearchRequest();
    sr.setQuery(compat.queryString(query.getQuery()));
    sr.setFrom(0);
    sr.setSize(size);
    try {
        return client.search(getIndexStoreName(query.getStore()), useMultitypeIndex ? query.getStore() : null, compat.createRequestBody(sr, query.getParameters()), useScroll);
    } catch (final IOException | UncheckedIOException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 22 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.

the class ElasticSearchIndex method register.

@Override
public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException {
    final Class<?> dataType = information.getDataType();
    final Mapping map = Mapping.getMapping(information);
    Preconditions.checkArgument(map == Mapping.DEFAULT || AttributeUtil.isString(dataType) || (map == Mapping.PREFIX_TREE && AttributeUtil.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]", map, dataType);
    final String indexStoreName = getIndexStoreName(store);
    if (useExternalMappings) {
        try {
            // We check if the externalMapping have the property 'key'
            final IndexMapping mappings = client.getMapping(indexStoreName, store);
            if (mappings == null || (!mappings.isDynamic() && !mappings.getProperties().containsKey(key))) {
                // Error if it is not dynamic and have not the property 'key'
                throw new PermanentBackendException("The external mapping for index '" + indexStoreName + "' and type '" + store + "' do not have property '" + key + "'");
            } else if (mappings.isDynamic()) {
                // If it is dynamic, we push the unknown property 'key'
                this.pushMapping(store, key, information);
            }
        } catch (final IOException e) {
            throw new PermanentBackendException(e);
        }
    } else {
        try {
            checkForOrCreateIndex(indexStoreName);
        } catch (final IOException e) {
            throw new PermanentBackendException(e);
        }
        this.pushMapping(store, key, information);
    }
}
Also used : IndexMapping(org.janusgraph.diskstorage.es.IndexMappings.IndexMapping) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Mapping(org.janusgraph.core.schema.Mapping) IndexMapping(org.janusgraph.diskstorage.es.IndexMappings.IndexMapping) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 23 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method testExternalMappingsViaMapping.

@Test
public void testExternalMappingsViaMapping() throws Exception {
    final Duration maxWrite = Duration.ofMillis(2000L);
    final String storeName = "test_mapping";
    final Configuration indexConfig = GraphDatabaseConfiguration.buildGraphConfiguration().set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME).restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    final ElasticMajorVersion version = ((ElasticSearchIndex) idx).getVersion();
    // Test create index KO mapping is not push
    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);
    try {
        idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
        fail("should fail");
    } catch (final PermanentBackendException ignored) {
    }
    final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
    newMapping.setEntity(new StringEntity(objectMapper.writeValueAsString(readMapping(version, "/strict_mapping.json")), Charset.forName("UTF-8")));
    executeRequest(newMapping);
    // Test date property OK
    idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
    // Test weight property KO
    try {
        idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
        fail("should fail");
    } catch (final BackendException ignored) {
    }
    itx.rollback();
    idx.close();
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Duration(java.time.Duration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) HttpPut(org.apache.http.client.methods.HttpPut) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) StringEntity(org.apache.http.entity.StringEntity) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) Test(org.junit.Test)

Example 24 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.

the class HBaseSnapshotBinaryInputFormat method setConf.

@Override
public void setConf(final Configuration config) {
    HBaseConfiguration.addHbaseResources(config);
    super.setConf(config);
    // Pass the extra pass-through properties directly to HBase/Hadoop config.
    final Map<String, Object> configSub = janusgraphConf.getSubset(HBaseStoreManager.HBASE_CONFIGURATION_NAMESPACE);
    for (Map.Entry<String, Object> entry : configSub.entrySet()) {
        log.info("HBase configuration: setting {}={}", entry.getKey(), entry.getValue());
        if (entry.getValue() == null)
            continue;
        config.set(entry.getKey(), entry.getValue().toString());
    }
    config.set("autotype", "none");
    final Scan scanner = new Scan();
    String cfName = mrConf.get(JanusGraphHadoopConfiguration.COLUMN_FAMILY_NAME);
    // TODO the space-saving short name mapping leaks from HBaseStoreManager here
    if (janusgraphConf.get(HBaseStoreManager.SHORT_CF_NAMES)) {
        try {
            final BiMap<String, String> shortCfMap = HBaseStoreManager.createShortCfMap(janusgraphConf);
            cfName = HBaseStoreManager.shortenCfName(shortCfMap, cfName);
        } catch (PermanentBackendException e) {
            throw new RuntimeException(e);
        }
    }
    edgeStoreFamily = Bytes.toBytes(cfName);
    scanner.addFamily(edgeStoreFamily);
    // This is a workaround, to be removed when convertScanToString becomes public in hbase package.
    Method converter;
    try {
        converter = TableMapReduceUtil.class.getDeclaredMethod("convertScanToString", Scan.class);
        converter.setAccessible(true);
        config.set(TableInputFormat.SCAN, (String) converter.invoke(null, scanner));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    final String snapshotName = janusgraphConf.get(HBaseStoreManager.HBASE_SNAPSHOT);
    final String restoreDirString = janusgraphConf.get(HBaseStoreManager.HBASE_SNAPSHOT_RESTORE_DIR);
    final Path restoreDir = new Path(restoreDirString);
    try {
        // This is a workaround. TableSnapshotInputFormat.setInput accepts a Job as parameter.
        // And the Job.getInstance(config) create clone of the config, not setting on the
        // passed in config.
        Job job = Job.getInstance(config);
        TableSnapshotInputFormat.setInput(job, snapshotName, restoreDir);
        config.set(SNAPSHOT_NAME_KEY, job.getConfiguration().get(SNAPSHOT_NAME_KEY));
        config.set(RESTORE_DIR_KEY, job.getConfiguration().get(RESTORE_DIR_KEY));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Method(java.lang.reflect.Method) IOException(java.io.IOException) IOException(java.io.IOException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) TableMapReduceUtil(org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil) Scan(org.apache.hadoop.hbase.client.Scan) Job(org.apache.hadoop.mapreduce.Job) Map(java.util.Map) BiMap(com.google.common.collect.BiMap)

Example 25 with PermanentBackendException

use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.

the class SolrIndex method clearStorage.

@Override
public void clearStorage() throws BackendException {
    try {
        if (mode != Mode.CLOUD) {
            logger.error("Operation only supported for SolrCloud. Cores must be deleted manually through the Solr API when using HTTP mode.");
            return;
        }
        logger.debug("Clearing storage from Solr: {}", solrClient);
        final ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader();
        zkStateReader.forciblyRefreshAllClusterStateSlow();
        final ClusterState clusterState = zkStateReader.getClusterState();
        for (final String collection : clusterState.getCollectionsMap().keySet()) {
            logger.debug("Clearing collection [{}] in Solr", collection);
            // Collection is not dropped because it may have been created externally
            final UpdateRequest deleteAll = newUpdateRequest();
            deleteAll.deleteByQuery("*:*");
            solrClient.request(deleteAll, collection);
        }
    } catch (final SolrServerException e) {
        logger.error("Unable to clear storage from index due to server error on Solr.", e);
        throw new PermanentBackendException(e);
    } catch (final IOException e) {
        logger.error("Unable to clear storage from index due to low-level I/O error.", e);
        throw new PermanentBackendException(e);
    } catch (final Exception e) {
        logger.error("Unable to clear storage from index due to general error.", e);
        throw new PermanentBackendException(e);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UncheckedIOException(java.io.UncheckedIOException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) BackendException(org.janusgraph.diskstorage.BackendException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Aggregations

PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)29 IOException (java.io.IOException)12 BackendException (org.janusgraph.diskstorage.BackendException)9 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)9 UncheckedIOException (java.io.UncheckedIOException)8 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)7 Map (java.util.Map)5 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)5 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 KeeperException (org.apache.zookeeper.KeeperException)4 Rows (com.netflix.astyanax.model.Rows)3 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)3 BiMap (com.google.common.collect.BiMap)2 Keyspace (com.netflix.astyanax.Keyspace)2 ColumnFamilyDefinition (com.netflix.astyanax.ddl.ColumnFamilyDefinition)2 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)2 RowSliceQuery (com.netflix.astyanax.query.RowSliceQuery)2 ByteBuffer (java.nio.ByteBuffer)2 Duration (java.time.Duration)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2