Search in sources :

Example 6 with TemporaryBackendException

use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project incubator-atlas by apache.

the class HBaseStoreManager method mutateMany.

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

Example 7 with TemporaryBackendException

use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project incubator-atlas by apache.

the class Solr5Index method restore.

@Override
public void restore(Map<String, Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException {
    try {
        for (Map.Entry<String, Map<String, List<IndexEntry>>> stores : documents.entrySet()) {
            final String collectionName = stores.getKey();
            List<String> deleteIds = new ArrayList<>();
            List<SolrInputDocument> newDocuments = new ArrayList<>();
            for (Map.Entry<String, List<IndexEntry>> entry : stores.getValue().entrySet()) {
                final String docID = entry.getKey();
                final List<IndexEntry> content = entry.getValue();
                if (content == null || content.isEmpty()) {
                    if (logger.isTraceEnabled())
                        logger.trace("Deleting document [{}]", docID);
                    deleteIds.add(docID);
                    continue;
                }
                newDocuments.add(new SolrInputDocument() {

                    {
                        setField(getKeyFieldId(collectionName), docID);
                        for (IndexEntry addition : content) {
                            Object fieldValue = addition.value;
                            setField(addition.field, convertValue(fieldValue));
                        }
                    }
                });
            }
            commitDeletes(collectionName, deleteIds);
            commitDocumentChanges(collectionName, newDocuments);
        }
    } catch (Exception e) {
        throw new TemporaryBackendException("Could not restore Solr index", e);
    }
}
Also used : ArrayList(java.util.ArrayList) IndexEntry(com.thinkaurelius.titan.diskstorage.indexing.IndexEntry) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) SolrInputDocument(org.apache.solr.common.SolrInputDocument) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with TemporaryBackendException

use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project incubator-atlas by apache.

the class HBaseStoreManager method ensureTableExists.

private HTableDescriptor ensureTableExists(String tableName, String initialCFName, int ttlInSeconds) throws BackendException {
    AdminMask adm = null;
    HTableDescriptor desc;
    try {
        // Create our table, if necessary
        adm = getAdminInterface();
        /*
             * Some HBase versions/impls 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.getTableDescriptor(tableName);
        } else {
            desc = createTable(tableName, initialCFName, ttlInSeconds, adm);
        }
    } catch (IOException e) {
        throw new TemporaryBackendException(e);
    } finally {
        IOUtils.closeQuietly(adm);
    }
    return desc;
}
Also used : TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 9 with TemporaryBackendException

use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project titan by thinkaurelius.

the class IDPoolTest method testAllocationTimeoutAndRecovery.

@Test
public void testAllocationTimeoutAndRecovery() throws BackendException {
    IMocksControl ctrl = EasyMock.createStrictControl();
    final int partition = 42;
    final int idNamespace = 777;
    final Duration timeout = Duration.ofSeconds(1L);
    final IDAuthority mockAuthority = ctrl.createMock(IDAuthority.class);
    // Sleep for two seconds, then throw a backendexception
    // this whole delegate could be deleted if we abstracted StandardIDPool's internal executor and stopwatches
    expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andDelegateTo(new IDAuthority() {

        @Override
        public IDBlock getIDBlock(int partition, int idNamespace, Duration timeout) throws BackendException {
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                fail();
            }
            throw new TemporaryBackendException("slow backend");
        }

        @Override
        public List<KeyRange> getLocalIDPartition() throws BackendException {
            throw new IllegalArgumentException();
        }

        @Override
        public void setIDBlockSizer(IDBlockSizer sizer) {
            throw new IllegalArgumentException();
        }

        @Override
        public void close() throws BackendException {
            throw new IllegalArgumentException();
        }

        @Override
        public String getUniqueID() {
            throw new IllegalArgumentException();
        }

        @Override
        public boolean supportsInterruption() {
            return true;
        }
    });
    expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andReturn(new IDBlock() {

        @Override
        public long numIds() {
            return 2;
        }

        @Override
        public long getId(long index) {
            return 200;
        }
    });
    expect(mockAuthority.supportsInterruption()).andStubReturn(true);
    ctrl.replay();
    StandardIDPool pool = new StandardIDPool(mockAuthority, partition, idNamespace, Integer.MAX_VALUE, timeout, 0.1);
    try {
        pool.nextID();
        fail();
    } catch (TitanException e) {
    }
    long nextID = pool.nextID();
    assertEquals(200, nextID);
    ctrl.verify();
}
Also used : IDBlockSizer(com.thinkaurelius.titan.graphdb.database.idassigner.IDBlockSizer) Duration(java.time.Duration) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) IMocksControl(org.easymock.IMocksControl) StandardIDPool(com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) IDAuthority(com.thinkaurelius.titan.diskstorage.IDAuthority) IDBlock(com.thinkaurelius.titan.diskstorage.IDBlock) TitanException(com.thinkaurelius.titan.core.TitanException) List(java.util.List) Test(org.junit.Test)

Example 10 with TemporaryBackendException

use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project titan by thinkaurelius.

the class AstyanaxStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String name, String comparator) 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(comparator);
            ImmutableMap.Builder<String, String> compressionOptions = new ImmutableMap.Builder<String, String>();
            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(com.thinkaurelius.titan.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)

Aggregations

TemporaryBackendException (com.thinkaurelius.titan.diskstorage.TemporaryBackendException)13 IOException (java.io.IOException)7 PermanentBackendException (com.thinkaurelius.titan.diskstorage.PermanentBackendException)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)3 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)3 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)3 ArrayList (java.util.ArrayList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)2 Duration (java.time.Duration)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 Delete (org.apache.hadoop.hbase.client.Delete)2 Put (org.apache.hadoop.hbase.client.Put)2 Row (org.apache.hadoop.hbase.client.Row)2