Search in sources :

Example 1 with TemporaryBackendException

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

the class HBaseStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String tableName, String columnFamily, int ttlInSeconds) throws BackendException {
    AdminMask adm = null;
    try {
        adm = getAdminInterface();
        HTableDescriptor desc = ensureTableExists(tableName, columnFamily, ttlInSeconds);
        Preconditions.checkNotNull(desc);
        HColumnDescriptor cf = desc.getFamily(Bytes.toBytes(columnFamily));
        // Create our column family, if necessary
        if (cf == null) {
            try {
                if (!adm.isTableDisabled(tableName)) {
                    adm.disableTable(tableName);
                }
            } catch (TableNotEnabledException e) {
                logger.debug("Table {} already disabled", tableName);
            } catch (IOException e) {
                throw new TemporaryBackendException(e);
            }
            try {
                HColumnDescriptor columnDescriptor = new HColumnDescriptor(columnFamily);
                setCFOptions(columnDescriptor, ttlInSeconds);
                adm.addColumn(tableName, columnDescriptor);
                try {
                    logger.debug("Added HBase ColumnFamily {}, waiting for 1 sec. to propogate.", columnFamily);
                    Thread.sleep(1000L);
                } catch (InterruptedException ie) {
                    throw new TemporaryBackendException(ie);
                }
                adm.enableTable(tableName);
            } catch (TableNotFoundException ee) {
                logger.error("TableNotFoundException", ee);
                throw new PermanentBackendException(ee);
            } catch (org.apache.hadoop.hbase.TableExistsException ee) {
                logger.debug("Swallowing exception {}", ee);
            } catch (IOException ee) {
                throw new TemporaryBackendException(ee);
            }
        }
    } finally {
        IOUtils.closeQuietly(adm);
    }
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException)

Example 2 with TemporaryBackendException

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

the class AstyanaxKeyColumnValueStore method getNamesSlice.

public Map<StaticBuffer, EntryList> getNamesSlice(List<StaticBuffer> keys, SliceQuery query, StoreTransaction txh) throws BackendException {
    /*
         * RowQuery<K,C> should be parametrized as
         * RowQuery<ByteBuffer,ByteBuffer>. However, this causes the following
         * compilation error when attempting to call withColumnRange on a
         * RowQuery<ByteBuffer,ByteBuffer> instance:
         *
         * java.lang.Error: Unresolved compilation problem: The method
         * withColumnRange(ByteBuffer, ByteBuffer, boolean, int) is ambiguous
         * for the type RowQuery<ByteBuffer,ByteBuffer>
         *
         * The compiler substitutes ByteBuffer=C for both startColumn and
         * endColumn, compares it to its identical twin with that type
         * hard-coded, and dies.
         *
         */
    // Add one for last column potentially removed in CassandraHelper.makeEntryList
    final int queryLimit = query.getLimit() + (query.hasLimit() ? 1 : 0);
    final int pageLimit = Math.min(this.readPageSize, queryLimit);
    ByteBuffer sliceStart = query.getSliceStart().asByteBuffer();
    final ByteBuffer sliceEnd = query.getSliceEnd().asByteBuffer();
    final RowSliceQuery rq = keyspace.prepareQuery(columnFamily).setConsistencyLevel(getTx(txh).getReadConsistencyLevel().getAstyanax()).withRetryPolicy(retryPolicy.duplicate()).getKeySlice(CassandraHelper.convert(keys));
    // Don't directly chain due to ambiguity resolution; see top comment
    rq.withColumnRange(sliceStart, sliceEnd, false, pageLimit);
    final OperationResult<Rows<ByteBuffer, ByteBuffer>> r;
    try {
        r = (OperationResult<Rows<ByteBuffer, ByteBuffer>>) rq.execute();
    } catch (ConnectionException e) {
        throw new TemporaryBackendException(e);
    }
    final Rows<ByteBuffer, ByteBuffer> rows = r.getResult();
    final Map<StaticBuffer, EntryList> result = new HashMap<>(rows.size());
    for (Row<ByteBuffer, ByteBuffer> row : rows) {
        assert !result.containsKey(row.getKey());
        final ByteBuffer key = row.getKey();
        ColumnList<ByteBuffer> pageColumns = row.getColumns();
        final List<Column<ByteBuffer>> queryColumns = new ArrayList();
        Iterables.addAll(queryColumns, pageColumns);
        while (pageColumns.size() == pageLimit && queryColumns.size() < queryLimit) {
            final Column<ByteBuffer> lastColumn = queryColumns.get(queryColumns.size() - 1);
            sliceStart = lastColumn.getName();
            // No possibility of two values at the same column name, so start the
            // next slice one bit after the last column found by the previous query.
            // byte[] is little-endian
            Integer position = null;
            for (int i = sliceStart.array().length - 1; i >= 0; i--) {
                if (sliceStart.array()[i] < Byte.MAX_VALUE) {
                    position = i;
                    sliceStart.array()[i]++;
                    break;
                }
            }
            if (null == position) {
                throw new PermanentBackendException("Column was not incrementable");
            }
            final RowQuery pageQuery = keyspace.prepareQuery(columnFamily).setConsistencyLevel(getTx(txh).getReadConsistencyLevel().getAstyanax()).withRetryPolicy(retryPolicy.duplicate()).getKey(row.getKey());
            // Don't directly chain due to ambiguity resolution; see top comment
            pageQuery.withColumnRange(sliceStart, sliceEnd, false, pageLimit);
            final OperationResult<ColumnList<ByteBuffer>> pageResult;
            try {
                pageResult = (OperationResult<ColumnList<ByteBuffer>>) pageQuery.execute();
            } catch (ConnectionException e) {
                throw new TemporaryBackendException(e);
            }
            if (Thread.interrupted()) {
                throw new TraversalInterruptedException();
            }
            // Reset the incremented position to avoid leaking mutations up the
            // stack to callers - sliceStart.array() in fact refers to a column name
            // that will be later read to deserialize an edge (since we assigned it
            // via de-referencing a column from the previous query).
            sliceStart.array()[position]--;
            pageColumns = pageResult.getResult();
            Iterables.addAll(queryColumns, pageColumns);
        }
        result.put(StaticArrayBuffer.of(key), CassandraHelper.makeEntryList(queryColumns, entryGetter, query.getSliceEnd(), query.getLimit()));
    }
    return result;
}
Also used : TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) EntryList(org.janusgraph.diskstorage.EntryList) ByteBuffer(java.nio.ByteBuffer) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) Column(com.netflix.astyanax.model.Column) RowSliceQuery(com.netflix.astyanax.query.RowSliceQuery) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) ColumnList(com.netflix.astyanax.model.ColumnList) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) RowQuery(com.netflix.astyanax.query.RowQuery) Rows(com.netflix.astyanax.model.Rows)

Example 3 with TemporaryBackendException

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

the class AstyanaxStoreManager method mutateMany.

@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> batch, StoreTransaction txh) throws BackendException {
    MutationBatch m = keyspaceContext.getClient().prepareMutationBatch().withAtomicBatch(atomicBatch).setConsistencyLevel(getTx(txh).getWriteConsistencyLevel().getAstyanax()).withRetryPolicy(retryPolicy.duplicate());
    final MaskedTimestamp commitTime = new MaskedTimestamp(txh);
    for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> batchentry : batch.entrySet()) {
        String storeName = batchentry.getKey();
        Preconditions.checkArgument(openStores.containsKey(storeName), "Store cannot be found: " + storeName);
        ColumnFamily<ByteBuffer, ByteBuffer> columnFamily = openStores.get(storeName).getColumnFamily();
        Map<StaticBuffer, KCVMutation> mutations = batchentry.getValue();
        for (Map.Entry<StaticBuffer, KCVMutation> ent : mutations.entrySet()) {
            // The CLMs for additions and deletions are separated because
            // Astyanax's operation timestamp cannot be set on a per-delete
            // or per-addition basis.
            KCVMutation janusgraphMutation = ent.getValue();
            ByteBuffer key = ent.getKey().asByteBuffer();
            if (janusgraphMutation.hasDeletions()) {
                ColumnListMutation<ByteBuffer> deletions = m.withRow(columnFamily, key);
                deletions.setTimestamp(commitTime.getDeletionTime(times));
                for (StaticBuffer b : janusgraphMutation.getDeletions()) deletions.deleteColumn(b.as(StaticBuffer.BB_FACTORY));
            }
            if (janusgraphMutation.hasAdditions()) {
                ColumnListMutation<ByteBuffer> updates = m.withRow(columnFamily, key);
                updates.setTimestamp(commitTime.getAdditionTime(times));
                for (Entry e : janusgraphMutation.getAdditions()) {
                    Integer ttl = (Integer) e.getMetaData().get(EntryMetaData.TTL);
                    if (null != ttl && ttl > 0) {
                        updates.putColumn(e.getColumnAs(StaticBuffer.BB_FACTORY), e.getValueAs(StaticBuffer.BB_FACTORY), ttl);
                    } else {
                        updates.putColumn(e.getColumnAs(StaticBuffer.BB_FACTORY), e.getValueAs(StaticBuffer.BB_FACTORY));
                    }
                }
            }
        }
    }
    try {
        m.execute();
    } catch (ConnectionException e) {
        throw new TemporaryBackendException(e);
    }
    sleepAfterWrite(txh, commitTime);
}
Also used : ByteBuffer(java.nio.ByteBuffer) KCVMutation(org.janusgraph.diskstorage.keycolumnvalue.KCVMutation) Entry(org.janusgraph.diskstorage.Entry) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) MutationBatch(com.netflix.astyanax.MutationBatch) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 4 with TemporaryBackendException

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

the class AstyanaxStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String name) throws BackendException {
    Cluster cl = clusterContext.getClient();
    try {
        KeyspaceDefinition ksDef = cl.describeKeyspace(keySpaceName);
        boolean found = false;
        if (null != ksDef) {
            for (ColumnFamilyDefinition cfDef : ksDef.getColumnFamilyList()) {
                found |= cfDef.getName().equals(name);
            }
        }
        if (!found) {
            ColumnFamilyDefinition cfDef = cl.makeColumnFamilyDefinition().setName(name).setKeyspace(keySpaceName).setComparatorType("org.apache.cassandra.db.marshal.BytesType");
            final ImmutableMap.Builder<String, String> compressionOptions = new ImmutableMap.Builder<>();
            if (storageConfig.has(COMPACTION_STRATEGY)) {
                cfDef.setCompactionStrategy(storageConfig.get(COMPACTION_STRATEGY));
            }
            if (!compactionOptions.isEmpty()) {
                cfDef.setCompactionStrategyOptions(compactionOptions);
            }
            if (compressionEnabled) {
                compressionOptions.put("sstable_compression", compressionClass).put("chunk_length_kb", Integer.toString(compressionChunkSizeKB));
            }
            cl.addColumnFamily(cfDef.setCompressionOptions(compressionOptions.build()));
        }
    } catch (ConnectionException e) {
        throw new TemporaryBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) Cluster(com.netflix.astyanax.Cluster) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 5 with TemporaryBackendException

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

the class LuceneIndex method queryCount.

@Override
public Long queryCount(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 0L;
        }
        Query q = searchParams.getQuery();
        final long time = System.currentTimeMillis();
        // We ignore offset and limit for totals
        final TopDocs docs = searcher.search(q, 1);
        log.debug("Executed query [{}] in {} ms", q, System.currentTimeMillis() - time);
        return docs.totalHits.value;
    } catch (final IOException e) {
        throw new TemporaryBackendException("Could not execute Lucene query", e);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) BaseTransaction(org.janusgraph.diskstorage.BaseTransaction) 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) IOException(java.io.IOException)

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