Search in sources :

Example 16 with TemporaryBackendException

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

the class AstyanaxStoreManager method ensureKeyspaceExists.

private void ensureKeyspaceExists(Cluster cl) throws BackendException {
    KeyspaceDefinition ksDef;
    try {
        ksDef = cl.describeKeyspace(keySpaceName);
        if (null != ksDef && ksDef.getName().equals(keySpaceName)) {
            log.debug("Found keyspace {}", keySpaceName);
            return;
        }
    } catch (ConnectionException e) {
        log.debug("Failed to describe keyspace {}", keySpaceName);
    }
    log.debug("Creating keyspace {}...", keySpaceName);
    try {
        ksDef = cl.makeKeyspaceDefinition().setName(keySpaceName).setStrategyClass(storageConfig.get(REPLICATION_STRATEGY)).setStrategyOptions(strategyOptions);
        cl.addKeyspace(ksDef);
        log.debug("Created keyspace {}", keySpaceName);
    } catch (ConnectionException e) {
        log.debug("Failed to create keyspace {}", keySpaceName);
        throw new TemporaryBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 17 with TemporaryBackendException

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

the class HBaseStoreManager method ensureTableExists.

private TableDescriptor ensureTableExists(TableName tableName, String initialCFName, int ttlInSeconds) throws BackendException {
    Admin adm = null;
    TableDescriptor desc;
    try {
        // Create our table, if necessary
        adm = getAdminInterface();
        /*
             * Some HBase versions / implementations respond badly to attempts to create a
             * table without at least one CF. See #661. Creating a CF along with
             * the table avoids HBase carping.
             */
        if (adm.tableExists(tableName)) {
            desc = adm.getDescriptor(tableName);
            // Check and warn if long and short cf names are interchangeably used for the same table.
            if (shortCfNames && initialCFName.equals(shortCfNameMap.get(SYSTEM_PROPERTIES_STORE_NAME))) {
                String longCFName = shortCfNameMap.inverse().get(initialCFName);
                if (desc.getColumnFamily(Bytes.toBytes(longCFName)) != null) {
                    logger.warn("Configuration {}=true, but the table \"{}\" already has column family with long name \"{}\".", SHORT_CF_NAMES.getName(), tableName, longCFName);
                    logger.warn("Check {} configuration.", SHORT_CF_NAMES.getName());
                }
            } else if (!shortCfNames && initialCFName.equals(SYSTEM_PROPERTIES_STORE_NAME)) {
                String shortCFName = shortCfNameMap.get(initialCFName);
                if (desc.getColumnFamily(Bytes.toBytes(shortCFName)) != null) {
                    logger.warn("Configuration {}=false, but the table \"{}\" already has column family with short name \"{}\".", SHORT_CF_NAMES.getName(), tableName, shortCFName);
                    logger.warn("Check {} configuration.", SHORT_CF_NAMES.getName());
                }
            }
        } else {
            desc = createTable(tableName, initialCFName, ttlInSeconds, adm);
        }
    } catch (IOException e) {
        throw new TemporaryBackendException(e);
    } finally {
        IOUtils.closeQuietly(adm);
    }
    return desc;
}
Also used : TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 18 with TemporaryBackendException

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

the class HBaseStoreManager method mutateMany.

@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException {
    Long putTimestamp = null;
    Long delTimestamp = null;
    MaskedTimestamp commitTime = null;
    if (assignTimestamp) {
        commitTime = new MaskedTimestamp(txh);
        putTimestamp = commitTime.getAdditionTime(times);
        delTimestamp = commitTime.getDeletionTime(times);
    }
    // In case of an addition and deletion with identical timestamps, the
    // deletion tombstone wins.
    // https://hbase.apache.org/book/versions.html#d244e4250
    final Map<StaticBuffer, Pair<List<Put>, Delete>> commandsPerKey = convertToCommands(mutations, putTimestamp, delTimestamp);
    // actual batch operation
    final List<Row> batch = new ArrayList<>(commandsPerKey.size());
    // convert sorted commands into representation required for 'batch' operation
    for (Pair<List<Put>, Delete> commands : commandsPerKey.values()) {
        if (commands.getFirst() != null && !commands.getFirst().isEmpty())
            batch.addAll(commands.getFirst());
        if (commands.getSecond() != null)
            batch.add(commands.getSecond());
    }
    try {
        Table table = null;
        try {
            table = cnx.getTable(tableName);
            table.batch(batch, new Object[batch.size()]);
        } finally {
            IOUtils.closeQuietly(table);
        }
    } catch (IOException | InterruptedException e) {
        throw new TemporaryBackendException(e);
    }
    if (commitTime != null) {
        sleepAfterWrite(commitTime);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Row(org.apache.hadoop.hbase.client.Row) Pair(org.apache.hadoop.hbase.util.Pair)

Example 19 with TemporaryBackendException

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

the class LuceneIndex method query.

@Override
public Stream<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever information, BaseTransaction tx) throws BackendException {
    final Query q;
    try {
        q = getQueryParser(query.getStore(), information).parse(query.getQuery());
    // Lucene query parser does not take additional parameters so any parameters on the RawQuery are ignored.
    } catch (final ParseException e) {
        throw new PermanentBackendException("Could not parse raw query: " + query.getQuery(), e);
    }
    try {
        final IndexSearcher searcher = ((Transaction) tx).getSearcher(query.getStore());
        if (searcher == null) {
            // Index does not yet exist
            return Collections.unmodifiableList(new ArrayList<RawQuery.Result<String>>()).stream();
        }
        final long time = System.currentTimeMillis();
        // TODO: can we make offset more efficient in Lucene?
        final int offset = query.getOffset();
        int adjustedLimit = query.hasLimit() ? query.getLimit() : Integer.MAX_VALUE - 1;
        if (adjustedLimit < Integer.MAX_VALUE - 1 - offset)
            adjustedLimit += offset;
        else
            adjustedLimit = Integer.MAX_VALUE - 1;
        final TopDocs docs;
        if (query.getOrders().isEmpty()) {
            docs = searcher.search(q, adjustedLimit);
        } else {
            docs = searcher.search(q, adjustedLimit, getSortOrder(query.getOrders(), information.get(query.getStore())));
        }
        log.debug("Executed query [{}] in {} ms", q, System.currentTimeMillis() - time);
        final List<RawQuery.Result<String>> result = new ArrayList<>(docs.scoreDocs.length);
        for (int i = offset; i < docs.scoreDocs.length; i++) {
            final IndexableField field = searcher.doc(docs.scoreDocs[i].doc, FIELDS_TO_LOAD).getField(DOCID);
            result.add(new RawQuery.Result<>(field == null ? null : field.stringValue(), docs.scoreDocs[i].score));
        }
        return result.stream();
    } catch (final IOException e) {
        throw new TemporaryBackendException("Could not execute Lucene query", e);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) IndexQuery(org.janusgraph.diskstorage.indexing.IndexQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) RawQuery(org.janusgraph.diskstorage.indexing.RawQuery) DocValuesFieldExistsQuery(org.apache.lucene.search.DocValuesFieldExistsQuery) TermQuery(org.apache.lucene.search.TermQuery) NormsFieldExistsQuery(org.apache.lucene.search.NormsFieldExistsQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DoublePoint(org.apache.lucene.document.DoublePoint) LongPoint(org.apache.lucene.document.LongPoint) IntPoint(org.apache.lucene.document.IntPoint) TopDocs(org.apache.lucene.search.TopDocs) IndexableField(org.apache.lucene.index.IndexableField) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) BaseTransaction(org.janusgraph.diskstorage.BaseTransaction) RawQuery(org.janusgraph.diskstorage.indexing.RawQuery) ParseException(org.apache.lucene.queryparser.classic.ParseException)

Example 20 with TemporaryBackendException

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

the class LuceneIndex method query.

@Override
public Stream<String> query(IndexQuery query, KeyInformation.IndexRetriever information, BaseTransaction tx) throws BackendException {
    // Construct query
    final String store = query.getStore();
    final LuceneCustomAnalyzer delegatingAnalyzer = delegatingAnalyzerFor(store, information);
    final SearchParams searchParams = convertQuery(query.getCondition(), information.get(store), delegatingAnalyzer);
    try {
        final IndexSearcher searcher = ((Transaction) tx).getSearcher(query.getStore());
        if (searcher == null) {
            // Index does not yet exist
            return Collections.unmodifiableList(new ArrayList<String>()).stream();
        }
        Query q = searchParams.getQuery();
        if (null == q)
            q = new MatchAllDocsQuery();
        final long time = System.currentTimeMillis();
        final TopDocs docs;
        int limit = query.hasLimit() ? query.getLimit() : Integer.MAX_VALUE - 1;
        if (query.getOrder().isEmpty()) {
            docs = searcher.search(q, limit);
        } else {
            docs = searcher.search(q, limit, getSortOrder(query.getOrder(), information.get(store)));
        }
        log.debug("Executed query [{}] in {} ms", q, System.currentTimeMillis() - time);
        final List<String> result = new ArrayList<>(docs.scoreDocs.length);
        for (int i = 0; i < docs.scoreDocs.length; i++) {
            final IndexableField field = searcher.doc(docs.scoreDocs[i].doc, FIELDS_TO_LOAD).getField(DOCID);
            result.add(field == null ? null : field.stringValue());
        }
        return result.stream();
    } catch (final IOException e) {
        throw new TemporaryBackendException("Could not execute Lucene query", e);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) IndexQuery(org.janusgraph.diskstorage.indexing.IndexQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) RawQuery(org.janusgraph.diskstorage.indexing.RawQuery) DocValuesFieldExistsQuery(org.apache.lucene.search.DocValuesFieldExistsQuery) TermQuery(org.apache.lucene.search.TermQuery) NormsFieldExistsQuery(org.apache.lucene.search.NormsFieldExistsQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) ArrayList(java.util.ArrayList) IOException(java.io.IOException) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DoublePoint(org.apache.lucene.document.DoublePoint) LongPoint(org.apache.lucene.document.LongPoint) IntPoint(org.apache.lucene.document.IntPoint) TopDocs(org.apache.lucene.search.TopDocs) IndexableField(org.apache.lucene.index.IndexableField) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) BaseTransaction(org.janusgraph.diskstorage.BaseTransaction)

Aggregations

TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)32 IOException (java.io.IOException)13 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)13 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)11 ArrayList (java.util.ArrayList)8 BackendException (org.janusgraph.diskstorage.BackendException)7 List (java.util.List)6 Test (org.junit.jupiter.api.Test)6 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)5 HashMap (java.util.HashMap)5 IndexSearcher (org.apache.lucene.search.IndexSearcher)5 BaseTransaction (org.janusgraph.diskstorage.BaseTransaction)5 Duration (java.time.Duration)4 Map (java.util.Map)4 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 DocValuesFieldExistsQuery (org.apache.lucene.search.DocValuesFieldExistsQuery)4 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)4 NormsFieldExistsQuery (org.apache.lucene.search.NormsFieldExistsQuery)4