use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.
the class AstyanaxStoreManager method ensureKeyspaceExists.
private void ensureKeyspaceExists(Cluster cl) throws BackendException {
KeyspaceDefinition ksDef;
try {
ksDef = cl.describeKeyspace(keySpaceName);
if (null != ksDef && ksDef.getName().equals(keySpaceName)) {
log.debug("Found keyspace {}", keySpaceName);
return;
}
} catch (ConnectionException e) {
log.debug("Failed to describe keyspace {}", keySpaceName);
}
log.debug("Creating keyspace {}...", keySpaceName);
try {
ksDef = cl.makeKeyspaceDefinition().setName(keySpaceName).setStrategyClass(storageConfig.get(REPLICATION_STRATEGY)).setStrategyOptions(strategyOptions);
cl.addKeyspace(ksDef);
log.debug("Created keyspace {}", keySpaceName);
} catch (ConnectionException e) {
log.debug("Failed to create keyspace {}", keySpaceName);
throw new TemporaryBackendException(e);
}
}
use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.
the class HBaseStoreManager method ensureTableExists.
private TableDescriptor ensureTableExists(TableName tableName, String initialCFName, int ttlInSeconds) throws BackendException {
Admin adm = null;
TableDescriptor desc;
try {
// Create our table, if necessary
adm = getAdminInterface();
/*
* Some HBase versions / implementations 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.getDescriptor(tableName);
// Check and warn if long and short cf names are interchangeably used for the same table.
if (shortCfNames && initialCFName.equals(shortCfNameMap.get(SYSTEM_PROPERTIES_STORE_NAME))) {
String longCFName = shortCfNameMap.inverse().get(initialCFName);
if (desc.getColumnFamily(Bytes.toBytes(longCFName)) != null) {
logger.warn("Configuration {}=true, but the table \"{}\" already has column family with long name \"{}\".", SHORT_CF_NAMES.getName(), tableName, longCFName);
logger.warn("Check {} configuration.", SHORT_CF_NAMES.getName());
}
} else if (!shortCfNames && initialCFName.equals(SYSTEM_PROPERTIES_STORE_NAME)) {
String shortCFName = shortCfNameMap.get(initialCFName);
if (desc.getColumnFamily(Bytes.toBytes(shortCFName)) != null) {
logger.warn("Configuration {}=false, but the table \"{}\" already has column family with short name \"{}\".", SHORT_CF_NAMES.getName(), tableName, shortCFName);
logger.warn("Check {} configuration.", SHORT_CF_NAMES.getName());
}
}
} else {
desc = createTable(tableName, initialCFName, ttlInSeconds, adm);
}
} catch (IOException e) {
throw new TemporaryBackendException(e);
} finally {
IOUtils.closeQuietly(adm);
}
return desc;
}
use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.
the class HBaseStoreManager method mutateMany.
@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException {
Long putTimestamp = null;
Long delTimestamp = null;
MaskedTimestamp commitTime = null;
if (assignTimestamp) {
commitTime = new MaskedTimestamp(txh);
putTimestamp = commitTime.getAdditionTime(times);
delTimestamp = commitTime.getDeletionTime(times);
}
// In case of an addition and deletion with identical timestamps, the
// deletion tombstone wins.
// https://hbase.apache.org/book/versions.html#d244e4250
final Map<StaticBuffer, Pair<List<Put>, Delete>> commandsPerKey = convertToCommands(mutations, putTimestamp, delTimestamp);
// actual batch operation
final List<Row> batch = new ArrayList<>(commandsPerKey.size());
// convert sorted commands into representation required for 'batch' operation
for (Pair<List<Put>, Delete> commands : commandsPerKey.values()) {
if (commands.getFirst() != null && !commands.getFirst().isEmpty())
batch.addAll(commands.getFirst());
if (commands.getSecond() != null)
batch.add(commands.getSecond());
}
try {
Table table = null;
try {
table = cnx.getTable(tableName);
table.batch(batch, new Object[batch.size()]);
} finally {
IOUtils.closeQuietly(table);
}
} catch (IOException | InterruptedException e) {
throw new TemporaryBackendException(e);
}
if (commitTime != null) {
sleepAfterWrite(commitTime);
}
}
use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.
the class LuceneIndex method query.
@Override
public Stream<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever information, BaseTransaction tx) throws BackendException {
final Query q;
try {
q = getQueryParser(query.getStore(), information).parse(query.getQuery());
// Lucene query parser does not take additional parameters so any parameters on the RawQuery are ignored.
} catch (final ParseException e) {
throw new PermanentBackendException("Could not parse raw query: " + query.getQuery(), e);
}
try {
final IndexSearcher searcher = ((Transaction) tx).getSearcher(query.getStore());
if (searcher == null) {
// Index does not yet exist
return Collections.unmodifiableList(new ArrayList<RawQuery.Result<String>>()).stream();
}
final long time = System.currentTimeMillis();
// TODO: can we make offset more efficient in Lucene?
final int offset = query.getOffset();
int adjustedLimit = query.hasLimit() ? query.getLimit() : Integer.MAX_VALUE - 1;
if (adjustedLimit < Integer.MAX_VALUE - 1 - offset)
adjustedLimit += offset;
else
adjustedLimit = Integer.MAX_VALUE - 1;
final TopDocs docs;
if (query.getOrders().isEmpty()) {
docs = searcher.search(q, adjustedLimit);
} else {
docs = searcher.search(q, adjustedLimit, getSortOrder(query.getOrders(), information.get(query.getStore())));
}
log.debug("Executed query [{}] in {} ms", q, System.currentTimeMillis() - time);
final List<RawQuery.Result<String>> result = new ArrayList<>(docs.scoreDocs.length);
for (int i = offset; i < docs.scoreDocs.length; i++) {
final IndexableField field = searcher.doc(docs.scoreDocs[i].doc, FIELDS_TO_LOAD).getField(DOCID);
result.add(new RawQuery.Result<>(field == null ? null : field.stringValue(), docs.scoreDocs[i].score));
}
return result.stream();
} catch (final IOException e) {
throw new TemporaryBackendException("Could not execute Lucene query", e);
}
}
use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.
the class LuceneIndex method query.
@Override
public Stream<String> query(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 Collections.unmodifiableList(new ArrayList<String>()).stream();
}
Query q = searchParams.getQuery();
if (null == q)
q = new MatchAllDocsQuery();
final long time = System.currentTimeMillis();
final TopDocs docs;
int limit = query.hasLimit() ? query.getLimit() : Integer.MAX_VALUE - 1;
if (query.getOrder().isEmpty()) {
docs = searcher.search(q, limit);
} else {
docs = searcher.search(q, limit, getSortOrder(query.getOrder(), information.get(store)));
}
log.debug("Executed query [{}] in {} ms", q, System.currentTimeMillis() - time);
final List<String> result = new ArrayList<>(docs.scoreDocs.length);
for (int i = 0; i < docs.scoreDocs.length; i++) {
final IndexableField field = searcher.doc(docs.scoreDocs[i].doc, FIELDS_TO_LOAD).getField(DOCID);
result.add(field == null ? null : field.stringValue());
}
return result.stream();
} catch (final IOException e) {
throw new TemporaryBackendException("Could not execute Lucene query", e);
}
}
Aggregations