Java Code Examples for com.thinkaurelius.titan.diskstorage.TemporaryBackendException

The following are top voted examples for showing how to use com.thinkaurelius.titan.diskstorage.TemporaryBackendException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: titan1withtp3.1   File: HBaseStoreManager.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 2
Project: incubator-atlas   File: HBaseStoreManager.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 3
Project: titan1.0.1.kafka   File: HBaseStoreManager.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 4
Project: titan0.5.4-hbase1.1.1-custom   File: HBaseStoreManager.java   Source Code and License 6 votes vote down vote up
private HTableDescriptor ensureTableExists(String tableName, String initialCFName, int ttlInSeconds) throws BackendException {
    HBaseAdmin 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.getBytes());
        } else {
            desc = createTable(tableName, initialCFName, ttlInSeconds, adm);
        }
    } catch (IOException e) {
        throw new TemporaryBackendException(e);
    } finally {
        IOUtils.closeQuietly(adm);
    }

    return desc;
}
 
Example 5
Project: incubator-atlas   File: HBaseStoreManager.java   Source Code and License 5 votes vote down vote up
/**
 * Deletes the specified table with all its columns.
 * ATTENTION: Invoking this method will delete the table if it exists and therefore causes data loss.
 */
@Override
public void clearStorage() throws BackendException {
    try (AdminMask adm = getAdminInterface()) {
        adm.clearTable(tableName, times.getTime().getNativeTimestamp());
    } catch (IOException e)
    {
        throw new TemporaryBackendException(e);
    }
}
 
Example 6
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 5 votes vote down vote up
@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);
    }
}
 
Example 7
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 5 votes vote down vote up
@Override
public void close() throws BackendException {
    logger.trace("Shutting down connection to Solr", solrClient);
    try {
        solrClient.close();
    } catch (IOException e) {
        throw new TemporaryBackendException(e);
    }
}
 
Example 8
Project: titan1withtp3.1   File: AbstractLocker.java   Source Code and License 4 votes vote down vote up
@Override
public void writeLock(KeyColumn lockID, StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {

    if (null != tx.getConfiguration().getGroupName()) {
        MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_WRITE, M_CALLS).inc();
    }

    if (lockState.has(tx, lockID)) {
        log.debug("Transaction {} already wrote lock on {}", tx, lockID);
        return;
    }

    if (lockLocally(lockID, tx)) {
        boolean ok = false;
        try {
            S stat = writeSingleLock(lockID, tx);
            lockLocally(lockID, stat.getExpirationTimestamp(), tx); // update local lock expiration time
            lockState.take(tx, lockID, stat);
            ok = true;
        } catch (TemporaryBackendException tse) {
            throw new TemporaryLockingException(tse);
        } catch (AssertionError ae) {
            // Concession to ease testing with mocks & behavior verification
            ok = true;
            throw ae;
        } catch (Throwable t) {
            throw new PermanentLockingException(t);
        } finally {
            if (!ok) {
                // lockState.release(tx, lockID); // has no effect
                unlockLocally(lockID, tx);
                if (null != tx.getConfiguration().getGroupName()) {
                    MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_WRITE, M_EXCEPTIONS).inc();
                }
            }
        }
    } else {
        // Fail immediately with no retries on local contention
        throw new PermanentLockingException("Local lock contention");
    }
}
 
Example 9
Project: titan1withtp3.1   File: AbstractLocker.java   Source Code and License 4 votes vote down vote up
@Override
public void checkLocks(StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {

    if (null != tx.getConfiguration().getGroupName()) {
        MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
    }

    Map<KeyColumn, S> m = lockState.getLocksForTx(tx);

    if (m.isEmpty()) {
        return; // no locks for this tx
    }

    // We never receive interrupts in normal operation; one can only appear
    // during Thread.sleep(), and in that case it probably means the entire
    // Titan process is shutting down; for this reason, we return ASAP on an
    // interrupt
    boolean ok = false;
    try {
        for (KeyColumn kc : m.keySet()) {
            checkSingleLock(kc, m.get(kc), tx);
        }
        ok = true;
    } catch (TemporaryLockingException tle) {
        throw tle;
    } catch (PermanentLockingException ple) {
        throw ple;
    } catch (AssertionError ae) {
        throw ae; // Concession to ease testing with mocks & behavior verification
    } catch (InterruptedException e) {
        throw new TemporaryLockingException(e);
    } catch (TemporaryBackendException tse) {
        throw new TemporaryLockingException(tse);
    } catch (Throwable t) {
        throw new PermanentLockingException(t);
    } finally {
        if (!ok && null != tx.getConfiguration().getGroupName()) {
            MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
        }
    }
}
 
Example 10
Project: titan1withtp3.1   File: HBaseStoreManager.java   Source Code and License 4 votes vote down vote up
/**
     * Deletes the specified table with all its columns.
     * ATTENTION: Invoking this method will delete the table if it exists and therefore causes data loss.
     */
    @Override
    public void clearStorage() throws BackendException {
        try (AdminMask adm = getAdminInterface()) {
            adm.clearTable(tableName, times.getTime(times.getTime()));
        } catch (IOException e)
        {
            throw new TemporaryBackendException(e);
        }
//
//
//
//        try { // first of all, check if table exists, if not - we are done
//            adm = getAdminInterface();
//            if (!adm.tableExists(tableName)) {
//                logger.debug("clearStorage() called before table {} was created, skipping.", tableName);
//                return;
//            }
//        } catch (IOException e) {
//            throw new TemporaryBackendException(e);
//        } finally {
//            IOUtils.closeQuietly(adm);
//        }
//
////        long before = System.currentTimeMillis();
////        try {
////            adm.disableTable(tableName);
////            adm.deleteTable(tableName);
////        } catch (IOException e) {
////            throw new PermanentBackendException(e);
////        }
////        ensureTableExists(tableName, getCfNameForStoreName(GraphDatabaseConfiguration.SYSTEM_PROPERTIES_STORE_NAME), 0);
////        long after = System.currentTimeMillis();
////        logger.debug("Dropped and recreated table {} in {} ms", tableName, after - before);
//
//        HTable table = null;
//
//        try {
//            table = new HTable(hconf, tableName);
//
//            Scan scan = new Scan();
//            scan.setBatch(100);
//            scan.setCacheBlocks(false);
//            scan.setCaching(2000);
//            scan.setTimeRange(0, Long.MAX_VALUE);
//            scan.setMaxVersions(1);
//
//            ResultScanner scanner = null;
//
//            long timestamp = times.getTime(times.getTime());
//
//            try {
//                scanner = table.getScanner(scan);
//
//                for (Result res : scanner) {
//                    Delete d = new Delete(res.getRow());
//
//                    d.setTimestamp(timestamp);
//                    table.delete(d);
//                }
//            } finally {
//                IOUtils.closeQuietly(scanner);
//            }
//        } catch (IOException e) {
//            throw new TemporaryBackendException(e);
//        } finally {
//            IOUtils.closeQuietly(table);
//        }
    }
 
Example 11
Project: incubator-atlas   File: HBaseStoreManager.java   Source Code and License 4 votes vote down vote up
@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()));

    List<Row> batch = new ArrayList<>(commandsPerKey.size()); // actual batch operation

    // 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);
}
 
Example 12
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 4 votes vote down vote up
private BackendException storageException(Exception solrException) {
    return new TemporaryBackendException("Unable to complete query on Solr.", solrException);
}
 
Example 13
Project: titan1.0.1.kafka   File: AbstractLocker.java   Source Code and License 4 votes vote down vote up
@Override
public void writeLock(KeyColumn lockID, StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {

    if (null != tx.getConfiguration().getGroupName()) {
        MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_WRITE, M_CALLS).inc();
    }

    if (lockState.has(tx, lockID)) {
        log.debug("Transaction {} already wrote lock on {}", tx, lockID);
        return;
    }

    if (lockLocally(lockID, tx)) {
        boolean ok = false;
        try {
            S stat = writeSingleLock(lockID, tx);
            lockLocally(lockID, stat.getExpirationTimestamp(), tx); // update local lock expiration time
            lockState.take(tx, lockID, stat);
            ok = true;
        } catch (TemporaryBackendException tse) {
            throw new TemporaryLockingException(tse);
        } catch (AssertionError ae) {
            // Concession to ease testing with mocks & behavior verification
            ok = true;
            throw ae;
        } catch (Throwable t) {
            throw new PermanentLockingException(t);
        } finally {
            if (!ok) {
                // lockState.release(tx, lockID); // has no effect
                unlockLocally(lockID, tx);
                if (null != tx.getConfiguration().getGroupName()) {
                    MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_WRITE, M_EXCEPTIONS).inc();
                }
            }
        }
    } else {
        // Fail immediately with no retries on local contention
        throw new PermanentLockingException("Local lock contention");
    }
}
 
Example 14
Project: titan1.0.1.kafka   File: AbstractLocker.java   Source Code and License 4 votes vote down vote up
@Override
public void checkLocks(StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {

    if (null != tx.getConfiguration().getGroupName()) {
        MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
    }

    Map<KeyColumn, S> m = lockState.getLocksForTx(tx);

    if (m.isEmpty()) {
        return; // no locks for this tx
    }

    // We never receive interrupts in normal operation; one can only appear
    // during Thread.sleep(), and in that case it probably means the entire
    // Titan process is shutting down; for this reason, we return ASAP on an
    // interrupt
    boolean ok = false;
    try {
        for (KeyColumn kc : m.keySet()) {
            checkSingleLock(kc, m.get(kc), tx);
        }
        ok = true;
    } catch (TemporaryLockingException tle) {
        throw tle;
    } catch (PermanentLockingException ple) {
        throw ple;
    } catch (AssertionError ae) {
        throw ae; // Concession to ease testing with mocks & behavior verification
    } catch (InterruptedException e) {
        throw new TemporaryLockingException(e);
    } catch (TemporaryBackendException tse) {
        throw new TemporaryLockingException(tse);
    } catch (Throwable t) {
        throw new PermanentLockingException(t);
    } finally {
        if (!ok && null != tx.getConfiguration().getGroupName()) {
            MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
        }
    }
}
 
Example 15
Project: titan1.0.1.kafka   File: HBaseStoreManager.java   Source Code and License 4 votes vote down vote up
/**
     * Deletes the specified table with all its columns.
     * ATTENTION: Invoking this method will delete the table if it exists and therefore causes data loss.
     */
    @Override
    public void clearStorage() throws BackendException {
        try (AdminMask adm = getAdminInterface()) {
            adm.clearTable(tableName, times.getTime(times.getTime()));
        } catch (IOException e)
        {
            throw new TemporaryBackendException(e);
        }
//
//
//
//        try { // first of all, check if table exists, if not - we are done
//            adm = getAdminInterface();
//            if (!adm.tableExists(tableName)) {
//                logger.debug("clearStorage() called before table {} was created, skipping.", tableName);
//                return;
//            }
//        } catch (IOException e) {
//            throw new TemporaryBackendException(e);
//        } finally {
//            IOUtils.closeQuietly(adm);
//        }
//
////        long before = System.currentTimeMillis();
////        try {
////            adm.disableTable(tableName);
////            adm.deleteTable(tableName);
////        } catch (IOException e) {
////            throw new PermanentBackendException(e);
////        }
////        ensureTableExists(tableName, getCfNameForStoreName(GraphDatabaseConfiguration.SYSTEM_PROPERTIES_STORE_NAME), 0);
////        long after = System.currentTimeMillis();
////        logger.debug("Dropped and recreated table {} in {} ms", tableName, after - before);
//
//        HTable table = null;
//
//        try {
//            table = new HTable(hconf, tableName);
//
//            Scan scan = new Scan();
//            scan.setBatch(100);
//            scan.setCacheBlocks(false);
//            scan.setCaching(2000);
//            scan.setTimeRange(0, Long.MAX_VALUE);
//            scan.setMaxVersions(1);
//
//            ResultScanner scanner = null;
//
//            long timestamp = times.getTime(times.getTime());
//
//            try {
//                scanner = table.getScanner(scan);
//
//                for (Result res : scanner) {
//                    Delete d = new Delete(res.getRow());
//
//                    d.setTimestamp(timestamp);
//                    table.delete(d);
//                }
//            } finally {
//                IOUtils.closeQuietly(scanner);
//            }
//        } catch (IOException e) {
//            throw new TemporaryBackendException(e);
//        } finally {
//            IOUtils.closeQuietly(table);
//        }
    }
 
Example 16
Project: titan0.5.4-hbase1.1.1-custom   File: AbstractLocker.java   Source Code and License 4 votes vote down vote up
@Override
public void writeLock(KeyColumn lockID, StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {

    if (null != tx.getConfiguration().getGroupName()) {
        MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_WRITE, M_CALLS).inc();
    }

    if (lockState.has(tx, lockID)) {
        log.debug("Transaction {} already wrote lock on {}", tx, lockID);
        return;
    }

    if (lockLocally(lockID, tx)) {
        boolean ok = false;
        try {
            S stat = writeSingleLock(lockID, tx);
            lockLocally(lockID, stat.getExpirationTimestamp(), tx); // update local lock expiration time
            lockState.take(tx, lockID, stat);
            ok = true;
        } catch (TemporaryBackendException tse) {
            throw new TemporaryLockingException(tse);
        } catch (AssertionError ae) {
            // Concession to ease testing with mocks & behavior verification
            ok = true;
            throw ae;
        } catch (Throwable t) {
            throw new PermanentLockingException(t);
        } finally {
            if (!ok) {
                // lockState.release(tx, lockID); // has no effect
                unlockLocally(lockID, tx);
                if (null != tx.getConfiguration().getGroupName()) {
                    MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_WRITE, M_EXCEPTIONS).inc();
                }
            }
        }
    } else {
        // Fail immediately with no retries on local contention
        throw new PermanentLockingException("Local lock contention");
    }
}
 
Example 17
Project: titan0.5.4-hbase1.1.1-custom   File: AbstractLocker.java   Source Code and License 4 votes vote down vote up
@Override
public void checkLocks(StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {

    if (null != tx.getConfiguration().getGroupName()) {
        MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
    }

    Map<KeyColumn, S> m = lockState.getLocksForTx(tx);

    if (m.isEmpty()) {
        return; // no locks for this tx
    }

    // We never receive interrupts in normal operation; one can only appear
    // during Thread.sleep(), and in that case it probably means the entire
    // Titan process is shutting down; for this reason, we return ASAP on an
    // interrupt
    boolean ok = false;
    try {
        for (KeyColumn kc : m.keySet()) {
            checkSingleLock(kc, m.get(kc), tx);
        }
        ok = true;
    } catch (TemporaryLockingException tle) {
        throw tle;
    } catch (PermanentLockingException ple) {
        throw ple;
    } catch (AssertionError ae) {
        throw ae; // Concession to ease testing with mocks & behavior verification
    } catch (InterruptedException e) {
        throw new TemporaryLockingException(e);
    } catch (TemporaryBackendException tse) {
        throw new TemporaryLockingException(tse);
    } catch (Throwable t) {
        throw new PermanentLockingException(t);
    } finally {
        if (!ok && null != tx.getConfiguration().getGroupName()) {
            MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
        }
    }
}