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

The following are top voted examples for showing how to use com.thinkaurelius.titan.diskstorage.BackendException. 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: mizo   File: MizoRDD.java   Source Code and License 6 votes vote down vote up
/**
 * Given a path for Titan config file, connects and gets the internal Titan types,
 * converting them to MizoTitanRelationTypes mapped by type-ids
 * @param titanConfigPath Path to Titan's config path
 * @return Mapping between relation type-ids to InternalRelationType instances
 */
protected static HashMap<Long, MizoTitanRelationType> loadRelationTypes(String titanConfigPath) {
    TitanGraph g = TitanFactory.open(titanConfigPath);
    StandardTitanTx tx = (StandardTitanTx)g.buildTransaction().readOnly().start();

    HashMap<Long, MizoTitanRelationType> relations = Maps.newHashMap();

    tx.query()
            .has(BaseKey.SchemaCategory, Contain.IN, Lists.newArrayList(TitanSchemaCategory.values()))
            .vertices()
            .forEach(v -> {
                if (v instanceof InternalRelationType)
                    relations.put(v.longId(), new MizoTitanRelationType((InternalRelationType)v));
            });

    tx.close();

    try {
        ((StandardTitanGraph)g).getBackend().close();
    } catch (BackendException e) {
        e.printStackTrace();
    }

    return relations;
}
 
Example 2
Project: titan0.5.4-hbase1.1.1-custom   File: BerkeleyJEStoreManager.java   Source Code and License 6 votes vote down vote up
@Override
public BerkeleyJETx beginTransaction(final BaseTransactionConfig txCfg) throws BackendException {
    try {
        Transaction tx = null;

        Configuration effectiveCfg =
                new MergedConfiguration(txCfg.getCustomOptions(), getStorageConfig());

        if (transactional) {
            TransactionConfig txnConfig = new TransactionConfig();
            effectiveCfg.get(ISOLATION_LEVEL).configure(txnConfig);
            tx = environment.beginTransaction(null, txnConfig);
        }
        BerkeleyJETx btx = new BerkeleyJETx(tx, effectiveCfg.get(LOCK_MODE), txCfg);

        if (log.isTraceEnabled()) {
            log.trace("Berkeley tx created", new TransactionBegin(btx.toString()));
        }

        return btx;
    } catch (DatabaseException e) {
        throw new PermanentBackendException("Could not start BerkeleyJE transaction", e);
    }
}
 
Example 3
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 4
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 5
Project: titan1withtp3.1   File: CassandraThriftStoreManager.java   Source Code and License 6 votes vote down vote up
private void retrySetKeyspace(String ksName, Cassandra.Client client) throws BackendException {
    final long end = System.currentTimeMillis() + (60L * 1000L);

    while (System.currentTimeMillis() <= end) {
        try {
            client.set_keyspace(ksName);
            return;
        } catch (Exception e) {
            log.warn("Exception when changing to keyspace {} after creating it", ksName, e);
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException ie) {
                throw new PermanentBackendException("Unexpected interrupt (shutting down?)", ie);
            }
        }
    }

    throw new PermanentBackendException("Could change to keyspace " + ksName + " after creating it");
}
 
Example 6
Project: titan1.0.1.kafka   File: BerkeleyJEStoreManager.java   Source Code and License 6 votes vote down vote up
@Override
public void mutateMany(Map<String, KVMutation> mutations, StoreTransaction txh) throws BackendException {
    for (Map.Entry<String,KVMutation> muts : mutations.entrySet()) {
        BerkeleyJEKeyValueStore store = openDatabase(muts.getKey());
        KVMutation mut = muts.getValue();

        if (!mut.hasAdditions() && !mut.hasDeletions()) {
            log.debug("Empty mutation set for {}, doing nothing", muts.getKey());
        } else {
            log.debug("Mutating {}", muts.getKey());
        }

        if (mut.hasAdditions()) {
            for (KeyValueEntry entry : mut.getAdditions()) {
                store.insert(entry.getKey(),entry.getValue(),txh);
                log.trace("Insertion on {}: {}", muts.getKey(), entry);
            }
        }
        if (mut.hasDeletions()) {
            for (StaticBuffer del : mut.getDeletions()) {
                store.delete(del,txh);
                log.trace("Deletion on {}: {}", muts.getKey(), del);
            }
        }
    }
}
 
Example 7
Project: titan1.0.1.kafka   File: KCVSConfiguration.java   Source Code and License 6 votes vote down vote up
/**
 * Reads the configuration property for this StoreManager
 *
 * @param key Key identifying the configuration property
 * @return Value stored for the key or null if the configuration property has not (yet) been defined.
 * @throws com.thinkaurelius.titan.diskstorage.BackendException
 */
@Override
public <O> O get(final String key, final Class<O> datatype) {
    StaticBuffer column = string2StaticBuffer(key);
    final KeySliceQuery query = new KeySliceQuery(rowKey,column, BufferUtil.nextBiggerBuffer(column));
    StaticBuffer result = BackendOperation.execute(new BackendOperation.Transactional<StaticBuffer>() {
        @Override
        public StaticBuffer call(StoreTransaction txh) throws BackendException {
            List<Entry> entries = store.getSlice(query,txh);
            if (entries.isEmpty()) return null;
            return entries.get(0).getValueAs(StaticBuffer.STATIC_FACTORY);
        }

        @Override
        public String toString() {
            return "getConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
    if (result==null) return null;
    return staticBuffer2Object(result, datatype);
}
 
Example 8
Project: titan1withtp3.1   File: StandardLockCleanerRunnable.java   Source Code and License 6 votes vote down vote up
private void runWithExceptions() throws BackendException {
    StaticBuffer lockKey = serializer.toLockKey(target.getKey(), target.getColumn());
    List<Entry> locks = store.getSlice(new KeySliceQuery(lockKey, LOCK_COL_START, LOCK_COL_END), tx); // TODO reduce LOCK_COL_END based on cutoff

    ImmutableList.Builder<StaticBuffer> b = ImmutableList.builder();

    for (Entry lc : locks) {
        TimestampRid tr = serializer.fromLockColumn(lc.getColumn(), times);
        if (tr.getTimestamp().isBefore(cutoff)) {
            log.info("Deleting expired lock on {} by rid {} with timestamp {} (before or at cutoff {})",
                    new Object[] { target, tr.getRid(), tr.getTimestamp(), cutoff });
            b.add(lc.getColumn());
        } else {
            log.debug("Ignoring lock on {} by rid {} with timestamp {} (timestamp is after cutoff {})",
                    new Object[] { target, tr.getRid(), tr.getTimestamp(), cutoff });
        }
    }

    List<StaticBuffer> dels = b.build();

    if (!dels.isEmpty()) {
        store.mutate(lockKey, ImmutableList.<Entry>of(), dels, tx);
        log.info("Deleted {} expired locks (before or at cutoff {})", dels.size(), cutoff);
    }
}
 
Example 9
Project: titan0.5.4-hbase1.1.1-custom   File: BerkeleyJEKeyValueStore.java   Source Code and License 6 votes vote down vote up
@Override
public StaticBuffer get(StaticBuffer key, StoreTransaction txh) throws BackendException {
    Transaction tx = getTransaction(txh);
    try {
        DatabaseEntry dbkey = key.as(ENTRY_FACTORY);
        DatabaseEntry data = new DatabaseEntry();

        log.trace("db={}, op=get, tx={}", name, txh);

        OperationStatus status = db.get(tx, dbkey, data, getLockMode(txh));

        if (status == OperationStatus.SUCCESS) {
            return getBuffer(data);
        } else {
            return null;
        }
    } catch (DatabaseException e) {
        throw new PermanentBackendException(e);
    }
}
 
Example 10
Project: titan1.0.1.kafka   File: ElasticSearchConfigTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testLocalNodeUsingExt() throws BackendException, InterruptedException {

    String baseDir = Joiner.on(File.separator).join("target", "es", "jvmlocal_ext");

    assertFalse(new File(baseDir + File.separator + "data").exists());

    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs");
    ModifiableConfiguration config =
            new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
                    cc, BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);
    idx.close();

    assertTrue(new File(baseDir + File.separator + "data").exists());
}
 
Example 11
Project: titan1.0.1.kafka   File: KCVSConfiguration.java   Source Code and License 6 votes vote down vote up
private Map<String,Object> toMap() {
    Map<String,Object> entries = Maps.newHashMap();
    List<Entry> result = BackendOperation.execute(new BackendOperation.Transactional<List<Entry>>() {
        @Override
        public List<Entry> call(StoreTransaction txh) throws BackendException {
            return store.getSlice(new KeySliceQuery(rowKey, BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)),txh);
        }

        @Override
        public String toString() {
            return "setConfiguration";
        }
    },txProvider, times, maxOperationWaitTime);

    for (Entry entry : result) {
        String key = staticBuffer2String(entry.getColumnAs(StaticBuffer.STATIC_FACTORY));
        Object value = staticBuffer2Object(entry.getValueAs(StaticBuffer.STATIC_FACTORY), Object.class);
        entries.put(key,value);
    }
    return entries;
}
 
Example 12
Project: titan1withtp3.1   File: LockCleanerRunnableTest.java   Source Code and License 6 votes vote down vote up
/**
 * Simplest case test of the lock cleaner.
 */
@Test
public void testDeleteSingleLock() throws BackendException {
    Instant now = Instant.ofEpochMilli(1L);

    Entry expiredLockCol = StaticArrayEntry.of(codec.toLockCol(now,
            defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
    EntryList expiredSingleton = StaticArrayEntryList.of(expiredLockCol);

    now = now.plusMillis(1);
    del = new StandardLockCleanerRunnable(store, kc, tx, codec, now, TimestampProviders.MILLI);

    expect(store.getSlice(eq(ksq), eq(tx)))
            .andReturn(expiredSingleton);

    store.mutate(
            eq(key),
            eq(ImmutableList.<Entry> of()),
            eq(ImmutableList.<StaticBuffer> of(expiredLockCol.getColumn())),
            anyObject(StoreTransaction.class));

    ctrl.replay();
    del.run();
}
 
Example 13
Project: titan1withtp3.1   File: LockCleanerRunnableTest.java   Source Code and License 6 votes vote down vote up
/**
 * Locks with timestamps equal to or numerically greater than the cleaner
 * cutoff timestamp must be preserved. Test that the cleaner reads locks by
 * slicing the store and then does <b>not</b> attempt to write.
 */
@Test
public void testPreservesLocksAtOrAfterCutoff() throws BackendException {
    final Instant cutoff = Instant.ofEpochMilli(10L);

    Entry currentLock = StaticArrayEntry.of(codec.toLockCol(cutoff,
            defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
    Entry futureLock = StaticArrayEntry.of(codec.toLockCol(cutoff.plusMillis(1),
            defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
    EntryList locks = StaticArrayEntryList.of(currentLock, futureLock);

    // Don't increment cutoff: lockCol is exactly at the cutoff timestamp
    del = new StandardLockCleanerRunnable(store, kc, tx, codec, cutoff, TimestampProviders.MILLI);

    expect(store.getSlice(eq(ksq), eq(tx))).andReturn(locks);

    ctrl.replay();
    del.run();
}
 
Example 14
Project: titan0.5.4-hbase1.1.1-custom   File: ElasticSearchConfigTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testLocalNodeUsingYaml() throws BackendException, InterruptedException {

    String baseDir = Joiner.on("/").join("target", "es", "jvmlocal_yml");

    assertFalse(new File(baseDir + File.separator + "data").exists());

    ModifiableConfiguration config = GraphDatabaseConfiguration.buildConfiguration();
    config.set(INTERFACE, ElasticSearchSetup.NODE, INDEX_NAME);
    config.set(INDEX_CONF_FILE,
            Joiner.on(File.separator).join("target", "test-classes", "es_jvmlocal.yml"), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);
    idx.close();

    assertTrue(new File(baseDir + File.separator + "data").exists());
}
 
Example 15
Project: titan1withtp3.1   File: BerkeleyJEStoreManager.java   Source Code and License 6 votes vote down vote up
@Override
public BerkeleyJETx beginTransaction(final BaseTransactionConfig txCfg) throws BackendException {
    try {
        Transaction tx = null;

        Configuration effectiveCfg =
                new MergedConfiguration(txCfg.getCustomOptions(), getStorageConfig());

        if (transactional) {
            TransactionConfig txnConfig = new TransactionConfig();
            ConfigOption.getEnumValue(effectiveCfg.get(ISOLATION_LEVEL),IsolationLevel.class).configure(txnConfig);
            tx = environment.beginTransaction(null, txnConfig);
        }
        BerkeleyJETx btx = new BerkeleyJETx(tx, ConfigOption.getEnumValue(effectiveCfg.get(LOCK_MODE),LockMode.class), txCfg);

        if (log.isTraceEnabled()) {
            log.trace("Berkeley tx created", new TransactionBegin(btx.toString()));
        }

        return btx;
    } catch (DatabaseException e) {
        throw new PermanentBackendException("Could not start BerkeleyJE transaction", e);
    }
}
 
Example 16
Project: titan1withtp3.1   File: ElasticSearchConfigTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testLocalNodeUsingYaml() throws BackendException, InterruptedException {

    String baseDir = Joiner.on(File.separator).join("target", "es", "jvmlocal_yml");

    assertFalse(new File(baseDir + File.separator + "data").exists());

    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    config.set(INDEX_CONF_FILE,
            Joiner.on(File.separator).join("target", "test-classes", "es_jvmlocal.yml"), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);
    idx.close();

    assertTrue(new File(baseDir + File.separator + "data").exists());
}
 
Example 17
Project: titan1.0.1.kafka   File: ElasticSearchConfigTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testLocalNodeUsingYaml() throws BackendException, InterruptedException {

    String baseDir = Joiner.on(File.separator).join("target", "es", "jvmlocal_yml");

    assertFalse(new File(baseDir + File.separator + "data").exists());

    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    config.set(INDEX_CONF_FILE,
            Joiner.on(File.separator).join("target", "test-classes", "es_jvmlocal.yml"), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);
    idx.close();

    assertTrue(new File(baseDir + File.separator + "data").exists());
}
 
Example 18
Project: titan1withtp3.1   File: ElasticSearchConfigTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testLocalNodeUsingExt() throws BackendException, InterruptedException {

    String baseDir = Joiner.on(File.separator).join("target", "es", "jvmlocal_ext");

    assertFalse(new File(baseDir + File.separator + "data").exists());

    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs");
    ModifiableConfiguration config =
            new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
                    cc, BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);
    idx.close();

    assertTrue(new File(baseDir + File.separator + "data").exists());
}
 
Example 19
Project: titan0.5.4-hbase1.1.1-custom   File: BerkeleyJEStoreManager.java   Source Code and License 6 votes vote down vote up
@Override
public void mutateMany(Map<String, KVMutation> mutations, StoreTransaction txh) throws BackendException {
    for (Map.Entry<String,KVMutation> muts : mutations.entrySet()) {
        BerkeleyJEKeyValueStore store = openDatabase(muts.getKey());
        KVMutation mut = muts.getValue();

        if (!mut.hasAdditions() && !mut.hasDeletions()) {
            log.debug("Empty mutation set for {}, doing nothing", muts.getKey());
        } else {
            log.debug("Mutating {}", muts.getKey());
        }

        if (mut.hasAdditions()) {
            for (KeyValueEntry entry : mut.getAdditions()) {
                store.insert(entry.getKey(),entry.getValue(),txh);
                log.trace("Insertion on {}: {}", muts.getKey(), entry);
            }
        }
        if (mut.hasDeletions()) {
            for (StaticBuffer del : mut.getDeletions()) {
                store.delete(del,txh);
                log.trace("Deletion on {}: {}", muts.getKey(), del);
            }
        }
    }
}
 
Example 20
Project: titan1.0.1.kafka   File: BerkeleyJEKeyValueStore.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized void close() throws BackendException {
    try {
        if(isOpen) db.close();
    } catch (DatabaseException e) {
        throw new PermanentBackendException(e);
    }
    if (isOpen) manager.removeDatabase(this);
    isOpen = false;
}
 
Example 21
Project: titan1.0.1.kafka   File: MetricInstrumentedStore.java   Source Code and License 5 votes vote down vote up
@Override
public EntryList getSlice(final KeySliceQuery query, final StoreTransaction txh) throws BackendException {
    return runWithMetrics(txh, metricsStoreName, M_GET_SLICE,
        new StorageCallable<EntryList>() {
            public EntryList call() throws BackendException {
                EntryList result = backend.getSlice(query, txh);
                recordSliceMetrics(txh, result);
                return result;
            }
        }
    );
}
 
Example 22
Project: titan1withtp3.1   File: CassandraThriftStoreManager.java   Source Code and License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public IPartitioner getCassandraPartitioner() throws BackendException {
    CTConnection conn = null;
    try {
        conn = pool.borrowObject(SYSTEM_KS);
        return FBUtilities.newPartitioner(conn.getClient().describe_partitioner());
    } catch (Exception e) {
        throw new TemporaryBackendException(e);
    } finally {
        pool.returnObjectUnsafe(SYSTEM_KS, conn);
    }
}
 
Example 23
Project: titan1.0.1.kafka   File: TitanGraphBaseTest.java   Source Code and License 5 votes vote down vote up
public static void clearGraph(WriteConfiguration config) throws BackendException {
    ModifiableConfiguration adjustedConfig = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,config.copy(), BasicConfiguration.Restriction.NONE);
    adjustedConfig.set(GraphDatabaseConfiguration.LOCK_LOCAL_MEDIATOR_GROUP, "tmp");
    adjustedConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "inst");
    Backend backend = new Backend(adjustedConfig);
    backend.initialize(adjustedConfig);
    backend.clearStorage();
}
 
Example 24
Project: titan1withtp3.1   File: ElasticSearchConfigTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testNetworkNodeUsingYaml() throws BackendException, InterruptedException {
    ElasticsearchRunner esr = new ElasticsearchRunner(".", "networkNodeUsingYaml.yml");
    esr.start();
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    config.set(INDEX_CONF_FILE,
            Joiner.on(File.separator).join("target", "test-classes", "es_cfg_nodeclient.yml"), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);
    idx.close();

    config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    config.set(HEALTH_REQUEST_TIMEOUT, "5s", INDEX_NAME);
    config.set(INDEX_CONF_FILE,
            Joiner.on(File.separator).join("target", "test-classes", "es_cfg_bogus_nodeclient.yml"), INDEX_NAME);
    indexConfig = config.restrictTo(INDEX_NAME);

    Throwable failure = null;
    try {
        idx = new ElasticSearchIndex(indexConfig);
    } catch (Throwable t) {
        failure = t;
    }
    //idx.close();
    Assert.assertNotNull("ES client failed to throw exception on connection failure", failure);
    esr.stop();
}
 
Example 25
Project: titan1withtp3.1   File: AbstractCassandraStoreTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testDisableCFCompressor() throws BackendException {

    final String cf = TEST_CF_NAME + "_nocompress";

    ModifiableConfiguration config = getBaseStorageConfiguration();
    config.set(AbstractCassandraStoreManager.CF_COMPRESSION,false);
    AbstractCassandraStoreManager mgr = openStorageManager(config);

    // N.B.: clearStorage() truncates CFs but does not delete them
    mgr.openDatabase(cf);

    assertEquals(Collections.emptyMap(), mgr.getCompressionOptions(cf));
}
 
Example 26
Project: titan0.5.4-hbase1.1.1-custom   File: BerkeleyJEStoreManager.java   Source Code and License 5 votes vote down vote up
public BerkeleyJEStoreManager(Configuration configuration) throws BackendException {
        super(configuration);
        stores = new HashMap<String, BerkeleyJEKeyValueStore>();

        int cachePercentage = configuration.get(JVM_CACHE);
        initialize(cachePercentage);

        features = new StandardStoreFeatures.Builder()
                    .orderedScan(true)
                    .transactional(transactional)
                    .keyConsistent(GraphDatabaseConfiguration.buildConfiguration())
                    .locking(true)
                    .keyOrdered(true)
                    .build();

//        features = new StoreFeatures();
//        features.supportsOrderedScan = true;
//        features.supportsUnorderedScan = false;
//        features.supportsBatchMutation = false;
//        features.supportsTxIsolation = transactional;
//        features.supportsConsistentKeyOperations = true;
//        features.supportsLocking = true;
//        features.isKeyOrdered = true;
//        features.isDistributed = false;
//        features.hasLocalKeyPartition = false;
//        features.supportsMultiQuery = false;
    }
 
Example 27
Project: titan1.0.1.kafka   File: HBaseStoreManager.java   Source Code and License 5 votes vote down vote up
@Override
public Deployment getDeployment() {
    List<KeyRange> local;
    try {
        local = getLocalKeyPartition();
        return null != local && !local.isEmpty() ? Deployment.LOCAL : Deployment.REMOTE;
    } catch (BackendException e) {
        // propagating StorageException might be a better approach
        throw new RuntimeException(e);
    }
}
 
Example 28
Project: titan0.5.4-hbase1.1.1-custom   File: LocalStoreManager.java   Source Code and License 5 votes vote down vote up
public LocalStoreManager(Configuration storageConfig) throws BackendException {
    super(storageConfig);
    String storageDir = storageConfig.get(STORAGE_DIRECTORY);
    if (null == storageDir) {
        directory = null;
    } else { 
        directory = DirectoryUtil.getOrCreateDataDirectory(storageDir);
    }
}
 
Example 29
Project: titan1.0.1.kafka   File: TTLKCVSManager.java   Source Code and License 5 votes vote down vote up
@Override
public KeyColumnValueStore openDatabase(String name, StoreMetaData.Container metaData) throws BackendException {
    KeyColumnValueStore store = manager.openDatabase(name);
    int storeTTL = -1;
    if (metaData.contains(StoreMetaData.TTL)) {
        storeTTL = (Integer) metaData.get(StoreMetaData.TTL);
    }
    Preconditions.checkArgument(storeTTL>0,"TTL must be positive: %s", storeTTL);
    ttlEnabledStores.put(name, storeTTL);
    return new TTLKCVS(store, storeTTL);
}
 
Example 30
Project: titan1withtp3.1   File: KCVSConfiguration.java   Source Code and License 5 votes vote down vote up
public KCVSConfiguration(BackendOperation.TransactionalProvider txProvider, Configuration config,
                         KeyColumnValueStore store, String identifier) throws BackendException {
    Preconditions.checkArgument(txProvider!=null && store!=null && config!=null);
    Preconditions.checkArgument(StringUtils.isNotBlank(identifier));
    this.txProvider = txProvider;
    this.times = config.get(TIMESTAMP_PROVIDER);
    this.store = store;
    this.identifier = identifier;
    this.rowKey = string2StaticBuffer(this.identifier);
    this.serializer = new StandardSerializer();
}
 
Example 31
Project: titan0.5.4-hbase1.1.1-custom   File: StandardLockCleanerRunnable.java   Source Code and License 5 votes vote down vote up
@Override
public void run() {
    try {
        runWithExceptions();
    } catch (BackendException e) {
        log.warn("Expired lock cleaner failed", e);
    }
}
 
Example 32
Project: titan0.5.4-hbase1.1.1-custom   File: BerkeleyBlueprintsTest.java   Source Code and License 5 votes vote down vote up
@Override
public void extraCleanUp(String uid) throws BackendException {
    String dir = BerkeleyStorageSetup.getHomeDir(uid);
    BerkeleyJEStoreManager s = new BerkeleyJEStoreManager(BerkeleyStorageSetup.getBerkeleyJEConfiguration(dir));
    s.clearStorage();
    s.close();
    File dirFile = new File(dir);
    Assert.assertFalse(dirFile.exists() && dirFile.listFiles().length > 0);
}
 
Example 33
Project: titan1.0.1.kafka   File: ElasticSearchConfigTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testIndexCreationOptions() throws InterruptedException, BackendException {
    final int shards = 77;

    ElasticsearchRunner esr = new ElasticsearchRunner(".", "indexCreationOptions.yml");
    esr.start();
    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "indexCreationOptions");
    ModifiableConfiguration config =
            new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
                    cc, BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);



    ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
    settingsBuilder.put("discovery.zen.ping.multicast.enabled", "false");
    settingsBuilder.put("discovery.zen.ping.unicast.hosts", "localhost,127.0.0.1:9300");
    settingsBuilder.put("cluster.name", "indexCreationOptions");
    NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
    nodeBuilder.client(true).data(false).local(false);
    Node n = nodeBuilder.build().start();

    GetSettingsResponse response = n.client().admin().indices().getSettings(new GetSettingsRequest().indices("titan")).actionGet();
    assertEquals(String.valueOf(shards), response.getSetting("titan", "index.number_of_shards"));

    idx.close();
    n.stop();
    esr.stop();
}
 
Example 34
Project: titan0.5.4-hbase1.1.1-custom   File: IndexProviderTest.java   Source Code and License 5 votes vote down vote up
public void open() throws BackendException {
    index = openIndex();
    indexFeatures = index.getFeatures();
    allKeys = getMapping(indexFeatures);
    indexRetriever = getIndexRetriever(allKeys);

    newTx();
}
 
Example 35
Project: titan1withtp3.1   File: HBaseStoreManager.java   Source Code and License 5 votes vote down vote up
@Override
public Deployment getDeployment() {
    List<KeyRange> local;
    try {
        local = getLocalKeyPartition();
        return null != local && !local.isEmpty() ? Deployment.LOCAL : Deployment.REMOTE;
    } catch (BackendException e) {
        // propagating StorageException might be a better approach
        throw new RuntimeException(e);
    }
}
 
Example 36
Project: titan0.5.4-hbase1.1.1-custom   File: EmbeddedBlueprintsTest.java   Source Code and License 5 votes vote down vote up
@Override
public void extraCleanUp(String uid) throws BackendException {
    ModifiableConfiguration mc =
            new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, getGraphConfig(), Restriction.NONE);
    StoreManager m = new CassandraEmbeddedStoreManager(mc);
    m.clearStorage();
    m.close();
}
 
Example 37
Project: titan1.0.1.kafka   File: StandardTitanTx.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized void commit() {
    Preconditions.checkArgument(isOpen(), "The transaction has already been closed");
    boolean success = false;
    if (null != config.getGroupName()) {
        MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "commit").inc();
    }
    try {
        if (hasModifications()) {
            graph.commit(addedRelations.getAll(), deletedRelations.values(), this);
        } else {
            txHandle.commit();
        }
        success = true;
    } catch (Exception e) {
        try {
            txHandle.rollback();
        } catch (BackendException e1) {
            throw new TitanException("Could not rollback after a failed commit", e);
        }
        throw new TitanException("Could not commit transaction due to exception during persistence", e);
    } finally {
        releaseTransaction();
        if (null != config.getGroupName() && !success) {
            MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "commit.exceptions").inc();
        }
    }
}
 
Example 38
Project: titan1.0.1.kafka   File: ExpectedValueCheckingStoreManager.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized KeyColumnValueStore openDatabase(String name) throws BackendException {
    if (stores.containsKey(name)) return stores.get(name);
    KeyColumnValueStore store = manager.openDatabase(name);
    final String lockerName = store.getName() + lockStoreSuffix;
    ExpectedValueCheckingStore wrappedStore = new ExpectedValueCheckingStore(store, lockerProvider.getLocker(lockerName));
    stores.put(name,wrappedStore);
    return wrappedStore;
}
 
Example 39
Project: titan0.5.4-hbase1.1.1-custom   File: KCVSUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Retrieves the value for the specified column and key under the given transaction
 * from the store if such exists, otherwise returns NULL
 *
 * @param store  Store
 * @param key    Key
 * @param column Column
 * @param txh    Transaction
 * @return Value for key and column or NULL if such does not exist
 */
public static StaticBuffer get(KeyColumnValueStore store, StaticBuffer key, StaticBuffer column, StoreTransaction txh) throws BackendException {
    KeySliceQuery query = new KeySliceQuery(key, column, BufferUtil.nextBiggerBuffer(column)).setLimit(2);
    List<Entry> result = store.getSlice(query, txh);
    if (result.size() > 1)
        log.warn("GET query returned more than 1 result: store {} | key {} | column {}", new Object[]{store.getName(),
                key, column});

    if (result.isEmpty()) return null;
    else return result.get(0).getValueAs(StaticBuffer.STATIC_FACTORY);
}
 
Example 40
Project: titan1.0.1.kafka   File: BerkeleyJEStoreManager.java   Source Code and License 5 votes vote down vote up
public BerkeleyJEStoreManager(Configuration configuration) throws BackendException {
        super(configuration);
        stores = new HashMap<String, BerkeleyJEKeyValueStore>();

        int cachePercentage = configuration.get(JVM_CACHE);
        initialize(cachePercentage);

        features = new StandardStoreFeatures.Builder()
                    .orderedScan(true)
                    .transactional(transactional)
                    .keyConsistent(GraphDatabaseConfiguration.buildGraphConfiguration())
                    .locking(true)
                    .keyOrdered(true)
                    .scanTxConfig(GraphDatabaseConfiguration.buildGraphConfiguration()
                            .set(ISOLATION_LEVEL, IsolationLevel.READ_UNCOMMITTED.toString()))
                    .supportsInterruption(false)
                    .build();

//        features = new StoreFeatures();
//        features.supportsOrderedScan = true;
//        features.supportsUnorderedScan = false;
//        features.supportsBatchMutation = false;
//        features.supportsTxIsolation = transactional;
//        features.supportsConsistentKeyOperations = true;
//        features.supportsLocking = true;
//        features.isKeyOrdered = true;
//        features.isDistributed = false;
//        features.hasLocalKeyPartition = false;
//        features.supportsMultiQuery = false;
    }