use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class BerkeleyJETx method openCursor.
Cursor openCursor(Database db) throws BackendException {
synchronized (openCursors) {
if (!isOpen) {
throw new PermanentBackendException("Transaction already closed");
}
Cursor cursor = db.openCursor(tx, null);
openCursors.add(cursor);
return cursor;
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class BerkeleyJEStoreManager method openDatabase.
@Override
public BerkeleyJEKeyValueStore openDatabase(String name) throws BackendException {
Preconditions.checkNotNull(name);
if (stores.containsKey(name)) {
return stores.get(name);
}
try {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setReadOnly(false);
dbConfig.setAllowCreate(true);
dbConfig.setTransactional(transactional);
dbConfig.setKeyPrefixing(true);
if (batchLoading) {
dbConfig.setDeferredWrite(true);
}
Database db = environment.openDatabase(null, name, dbConfig);
log.debug("Opened database {}", name);
BerkeleyJEKeyValueStore store = new BerkeleyJEKeyValueStore(name, db, this);
stores.put(name, store);
return store;
} catch (DatabaseException e) {
throw new PermanentBackendException("Could not open BerkeleyJE data store", e);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class BerkeleyJEStoreManager method beginTransaction.
@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);
} else {
if (txCfg instanceof TransactionConfiguration) {
if (!((TransactionConfiguration) txCfg).isSingleThreaded()) {
// Non-transactional cursors can't shared between threads, more info ThreadLocker.checkState
throw new PermanentBackendException("BerkeleyJE does not support non-transactional for multi threaded tx");
}
}
}
BerkeleyJETx btx = new BerkeleyJETx(tx, ConfigOption.getEnumValue(effectiveCfg.get(LOCK_MODE), LockMode.class), ConfigOption.getEnumValue(effectiveCfg.get(CACHE_MODE), CacheMode.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);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class HBaseSnapshotBinaryInputFormat method setConf.
@Override
public void setConf(final Configuration config) {
HBaseConfiguration.addHbaseResources(config);
super.setConf(config);
// Pass the extra pass-through properties directly to HBase/Hadoop config.
final Map<String, Object> configSub = janusgraphConf.getSubset(HBaseStoreManager.HBASE_CONFIGURATION_NAMESPACE);
for (Map.Entry<String, Object> entry : configSub.entrySet()) {
log.info("HBase configuration: setting {}={}", entry.getKey(), entry.getValue());
if (entry.getValue() == null)
continue;
config.set(entry.getKey(), entry.getValue().toString());
}
config.set("autotype", "none");
final Scan scanner = new Scan();
String cfName = mrConf.get(JanusGraphHadoopConfiguration.COLUMN_FAMILY_NAME);
// TODO the space-saving short name mapping leaks from HBaseStoreManager here
if (janusgraphConf.get(HBaseStoreManager.SHORT_CF_NAMES)) {
try {
final BiMap<String, String> shortCfMap = HBaseStoreManager.createShortCfMap(janusgraphConf);
cfName = HBaseStoreManager.shortenCfName(shortCfMap, cfName);
} catch (PermanentBackendException e) {
throw new RuntimeException(e);
}
}
edgeStoreFamily = Bytes.toBytes(cfName);
scanner.addFamily(edgeStoreFamily);
// This is a workaround, to be removed when convertScanToString becomes public in hbase package.
Method converter;
try {
converter = TableMapReduceUtil.class.getDeclaredMethod("convertScanToString", Scan.class);
converter.setAccessible(true);
config.set(TableInputFormat.SCAN, (String) converter.invoke(null, scanner));
} catch (Exception e) {
throw new RuntimeException(e);
}
final String snapshotName = janusgraphConf.get(HBaseStoreManager.HBASE_SNAPSHOT);
final String restoreDirString = janusgraphConf.get(HBaseStoreManager.HBASE_SNAPSHOT_RESTORE_DIR);
final Path restoreDir = new Path(restoreDirString);
try {
// This is a workaround. TableSnapshotInputFormat.setInput accepts a Job as parameter.
// And the Job.getInstance(config) create clone of the config, not setting on the
// passed in config.
Job job = Job.getInstance(config);
TableSnapshotInputFormat.setInput(job, snapshotName, restoreDir);
config.set(SNAPSHOT_NAME_KEY, job.getConfiguration().get(SNAPSHOT_NAME_KEY));
config.set(RESTORE_DIR_KEY, job.getConfiguration().get(RESTORE_DIR_KEY));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class ElasticSearchIndex method setupStoredScriptIfNeeded.
private void setupStoredScriptIfNeeded(String storedScriptId, String source) throws PermanentBackendException {
ImmutableMap<String, Object> preparedScript = compat.prepareScript(source).build();
String lang = (String) ((ImmutableMap<String, Object>) preparedScript.get(ES_SCRIPT_KEY)).get(ES_LANG_KEY);
try {
ESScriptResponse esScriptResponse = client.getStoredScript(storedScriptId);
if (Boolean.FALSE.equals(esScriptResponse.getFound()) || !Objects.equals(lang, esScriptResponse.getScript().getLang()) || !Objects.equals(source, esScriptResponse.getScript().getSource())) {
client.createStoredScript(storedScriptId, preparedScript);
}
} catch (final IOException e) {
throw new PermanentBackendException(e.getMessage(), e);
}
}
Aggregations