use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class CassandraThriftStoreManager method mutateMany.
@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException {
Preconditions.checkNotNull(mutations);
final MaskedTimestamp commitTime = new MaskedTimestamp(txh);
ConsistencyLevel consistency = getTx(txh).getWriteConsistencyLevel().getThrift();
// Generate Thrift-compatible batch_mutate() datastructure
// key -> cf -> cassmutation
int size = 0;
for (final Map<StaticBuffer, KCVMutation> mutation : mutations.values()) {
size += mutation.size();
}
final Map<ByteBuffer, Map<String, List<org.apache.cassandra.thrift.Mutation>>> batch = new HashMap<>(size);
for (final Map.Entry<String, Map<StaticBuffer, KCVMutation>> keyMutation : mutations.entrySet()) {
final String columnFamily = keyMutation.getKey();
for (final Map.Entry<StaticBuffer, KCVMutation> mutEntry : keyMutation.getValue().entrySet()) {
ByteBuffer keyBB = mutEntry.getKey().asByteBuffer();
// Get or create the single Cassandra Mutation object responsible for this key
// Most mutations only modify the edgeStore and indexStore
final Map<String, List<org.apache.cassandra.thrift.Mutation>> cfmutation = batch.computeIfAbsent(keyBB, k -> new HashMap<>(3));
final KCVMutation mutation = mutEntry.getValue();
final List<org.apache.cassandra.thrift.Mutation> thriftMutation = new ArrayList<>(mutations.size());
if (mutation.hasDeletions()) {
for (final StaticBuffer buf : mutation.getDeletions()) {
final Deletion d = new Deletion();
final SlicePredicate sp = new SlicePredicate();
sp.addToColumn_names(buf.as(StaticBuffer.BB_FACTORY));
d.setPredicate(sp);
d.setTimestamp(commitTime.getDeletionTime(times));
org.apache.cassandra.thrift.Mutation m = new org.apache.cassandra.thrift.Mutation();
m.setDeletion(d);
thriftMutation.add(m);
}
}
if (mutation.hasAdditions()) {
for (final Entry ent : mutation.getAdditions()) {
final ColumnOrSuperColumn columnOrSuperColumn = new ColumnOrSuperColumn();
final Column column = new Column(ent.getColumnAs(StaticBuffer.BB_FACTORY));
column.setValue(ent.getValueAs(StaticBuffer.BB_FACTORY));
column.setTimestamp(commitTime.getAdditionTime(times));
final Integer ttl = (Integer) ent.getMetaData().get(EntryMetaData.TTL);
if (null != ttl && ttl > 0) {
column.setTtl(ttl);
}
columnOrSuperColumn.setColumn(column);
org.apache.cassandra.thrift.Mutation m = new org.apache.cassandra.thrift.Mutation();
m.setColumn_or_supercolumn(columnOrSuperColumn);
thriftMutation.add(m);
}
}
cfmutation.put(columnFamily, thriftMutation);
}
}
CTConnection conn = null;
try {
conn = pool.borrowObject(keySpaceName);
Cassandra.Client client = conn.getClient();
if (atomicBatch) {
client.atomic_batch_mutate(batch, consistency);
} else {
client.batch_mutate(batch, consistency);
}
} catch (Exception ex) {
throw CassandraThriftKeyColumnValueStore.convertException(ex);
} finally {
pool.returnObjectUnsafe(keySpaceName, conn);
}
sleepAfterWrite(txh, commitTime);
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class CassandraThriftStoreManager method exists.
@Override
public boolean exists() throws BackendException {
CTConnection connection = null;
try {
connection = pool.borrowObject(SYSTEM_KS);
final Cassandra.Client client = connection.getClient();
try {
// Side effect: throws Exception if keyspaceName doesn't exist
// Don't remove
client.set_keyspace(keySpaceName);
client.set_keyspace(SYSTEM_KS);
return true;
} catch (InvalidRequestException e) {
return false;
}
} catch (Exception e) {
throw new TemporaryBackendException(e);
} finally {
pool.returnObjectUnsafe(SYSTEM_KS, connection);
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class ManagementSystem method updateIndex.
/* --------------
Schema Update
--------------- */
@Override
public IndexJobFuture updateIndex(Index index, SchemaAction updateAction) {
Preconditions.checkArgument(index != null, "Need to provide an index");
Preconditions.checkArgument(updateAction != null, "Need to provide update action");
JanusGraphSchemaVertex schemaVertex = getSchemaVertex(index);
Set<JanusGraphSchemaVertex> dependentTypes;
Set<PropertyKeyVertex> keySubset = ImmutableSet.of();
if (index instanceof RelationTypeIndex) {
dependentTypes = ImmutableSet.of((JanusGraphSchemaVertex) ((InternalRelationType) schemaVertex).getBaseType());
if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
return null;
} else if (index instanceof JanusGraphIndex) {
IndexType indexType = schemaVertex.asIndexType();
dependentTypes = Sets.newHashSet();
if (indexType.isCompositeIndex()) {
if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
return null;
for (PropertyKey key : ((JanusGraphIndex) index).getFieldKeys()) {
dependentTypes.add((PropertyKeyVertex) key);
}
} else {
keySubset = Sets.newHashSet();
MixedIndexType mixedIndexType = (MixedIndexType) indexType;
Set<SchemaStatus> applicableStatus = updateAction.getApplicableStatus();
for (ParameterIndexField field : mixedIndexType.getFieldKeys()) {
if (applicableStatus.contains(field.getStatus()))
keySubset.add((PropertyKeyVertex) field.getFieldKey());
}
if (keySubset.isEmpty())
return null;
dependentTypes.addAll(keySubset);
}
} else
throw new UnsupportedOperationException("Updates not supported for index: " + index);
IndexIdentifier indexId = new IndexIdentifier(index);
StandardScanner.Builder builder;
IndexJobFuture future;
switch(updateAction) {
case REGISTER_INDEX:
setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
updatedTypes.add(schemaVertex);
updatedTypes.addAll(dependentTypes);
setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.REGISTERED, keySubset));
future = new EmptyIndexJobFuture();
break;
case REINDEX:
builder = graph.getBackend().buildEdgeScanJob();
builder.setFinishJob(indexId.getIndexJobFinisher(graph, SchemaAction.ENABLE_INDEX));
builder.setJobId(indexId);
builder.setJob(VertexJobConverter.convert(graph, new IndexRepairJob(indexId.indexName, indexId.relationTypeName)));
try {
future = builder.execute();
} catch (BackendException e) {
throw new JanusGraphException(e);
}
break;
case ENABLE_INDEX:
setStatus(schemaVertex, SchemaStatus.ENABLED, keySubset);
updatedTypes.add(schemaVertex);
if (!keySubset.isEmpty())
updatedTypes.addAll(dependentTypes);
future = new EmptyIndexJobFuture();
break;
case DISABLE_INDEX:
setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
updatedTypes.add(schemaVertex);
if (!keySubset.isEmpty())
updatedTypes.addAll(dependentTypes);
setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.DISABLED, keySubset));
future = new EmptyIndexJobFuture();
break;
case REMOVE_INDEX:
if (index instanceof RelationTypeIndex) {
builder = graph.getBackend().buildEdgeScanJob();
} else {
JanusGraphIndex graphIndex = (JanusGraphIndex) index;
if (graphIndex.isMixedIndex())
throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly.");
builder = graph.getBackend().buildGraphIndexScanJob();
}
builder.setFinishJob(indexId.getIndexJobFinisher());
builder.setJobId(indexId);
builder.setJob(new IndexRemoveJob(graph, indexId.indexName, indexId.relationTypeName));
try {
future = builder.execute();
} catch (BackendException e) {
throw new JanusGraphException(e);
}
break;
default:
throw new UnsupportedOperationException("Update action not supported: " + updateAction);
}
return future;
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class KCVSConfiguration method close.
@Override
public void close() {
try {
store.close();
txProvider.close();
IOUtils.closeQuietly(serializer);
} catch (BackendException e) {
throw new JanusGraphException("Could not close configuration store", e);
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class KCVSConfiguration method set.
public <O> void set(String key, O value, O expectedValue, final boolean checkExpectedValue) {
final StaticBuffer column = string2StaticBuffer(key);
final List<Entry> additions;
final List<StaticBuffer> deletions;
if (value != null) {
// Addition
additions = new ArrayList<>(1);
deletions = KeyColumnValueStore.NO_DELETIONS;
StaticBuffer val = object2StaticBuffer(value);
additions.add(StaticArrayEntry.of(column, val));
} else {
// Deletion
additions = KeyColumnValueStore.NO_ADDITIONS;
deletions = Lists.newArrayList(column);
}
final StaticBuffer expectedValueBuffer;
if (checkExpectedValue && expectedValue != null) {
expectedValueBuffer = object2StaticBuffer(expectedValue);
} else {
expectedValueBuffer = null;
}
BackendOperation.execute(new BackendOperation.Transactional<Boolean>() {
@Override
public Boolean call(StoreTransaction txh) throws BackendException {
if (checkExpectedValue)
store.acquireLock(rowKey, column, expectedValueBuffer, txh);
store.mutate(rowKey, additions, deletions, txh);
return true;
}
@Override
public String toString() {
return "setConfiguration";
}
}, txProvider, times, maxOperationWaitTime);
}
Aggregations