use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.
the class TitanHadoopSetupImpl method getTypeInspector.
@Override
public TypeInspector getTypeInspector() {
//Pre-load schema
for (TitanSchemaCategory sc : TitanSchemaCategory.values()) {
for (TitanVertex k : QueryUtil.getVertices(tx, BaseKey.SchemaCategory, sc)) {
assert k instanceof TitanSchemaVertex;
TitanSchemaVertex s = (TitanSchemaVertex) k;
if (sc.hasName()) {
String name = s.name();
Preconditions.checkNotNull(name);
}
TypeDefinitionMap dm = s.getDefinition();
Preconditions.checkNotNull(dm);
s.getRelated(TypeDefinitionCategory.TYPE_MODIFIER, Direction.OUT);
s.getRelated(TypeDefinitionCategory.TYPE_MODIFIER, Direction.IN);
}
}
return tx;
}
use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.
the class IndexRemoveJob method validateIndexStatus.
@Override
protected void validateIndexStatus() {
if (index instanceof RelationTypeIndex) {
//Nothing specific to be done
} else if (index instanceof TitanGraphIndex) {
TitanGraphIndex gindex = (TitanGraphIndex) index;
if (gindex.isMixedIndex())
throw new UnsupportedOperationException("Cannot remove mixed indexes through Titan. This can " + "only be accomplished in the indexing system directly.");
CompositeIndexType indexType = (CompositeIndexType) mgmt.getSchemaVertex(index).asIndexType();
graphIndexId = indexType.getID();
} else
throw new UnsupportedOperationException("Unsupported index found: " + index);
//Must be a relation type index or a composite graph index
TitanSchemaVertex schemaVertex = mgmt.getSchemaVertex(index);
SchemaStatus actualStatus = schemaVertex.getStatus();
Preconditions.checkArgument(actualStatus == SchemaStatus.DISABLED, "The index [%s] must be disabled before it can be removed", indexName);
}
use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.
the class IndexRepairJob method validateIndexStatus.
/**
* Check that our target index is in either the ENABLED or REGISTERED state.
*/
@Override
protected void validateIndexStatus() {
TitanSchemaVertex schemaVertex = mgmt.getSchemaVertex(index);
Set<SchemaStatus> acceptableStatuses = SchemaAction.REINDEX.getApplicableStatus();
boolean isValidIndex = true;
String invalidIndexHint;
if (index instanceof RelationTypeIndex || (index instanceof TitanGraphIndex && ((TitanGraphIndex) index).isCompositeIndex())) {
SchemaStatus actualStatus = schemaVertex.getStatus();
isValidIndex = acceptableStatuses.contains(actualStatus);
invalidIndexHint = String.format("The index has status %s, but one of %s is required", actualStatus, acceptableStatuses);
} else {
Preconditions.checkArgument(index instanceof TitanGraphIndex, "Unexpected index: %s", index);
TitanGraphIndex gindex = (TitanGraphIndex) index;
Preconditions.checkArgument(gindex.isMixedIndex());
Map<String, SchemaStatus> invalidKeyStatuses = new HashMap<>();
int acceptableFields = 0;
for (PropertyKey key : gindex.getFieldKeys()) {
SchemaStatus status = gindex.getIndexStatus(key);
if (status != SchemaStatus.DISABLED && !acceptableStatuses.contains(status)) {
isValidIndex = false;
invalidKeyStatuses.put(key.name(), status);
log.warn("Index {} has key {} in an invalid status {}", index, key, status);
}
if (acceptableStatuses.contains(status))
acceptableFields++;
}
invalidIndexHint = String.format("The following index keys have invalid status: %s (status must be one of %s)", Joiner.on(",").withKeyValueSeparator(" has status ").join(invalidKeyStatuses), acceptableStatuses);
if (isValidIndex && acceptableFields == 0) {
isValidIndex = false;
invalidIndexHint = "The index does not contain any valid keys";
}
}
Preconditions.checkArgument(isValidIndex, "The index %s is in an invalid state and cannot be indexed. %s", indexName, invalidIndexHint);
// TODO consider retrieving the current Job object and calling killJob() if !isValidIndex -- would be more efficient than throwing an exception on the first pair processed by each mapper
log.debug("Index {} is valid for re-indexing");
}
use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.
the class ManagementSystem method commit.
@Override
public synchronized void commit() {
ensureOpen();
//Commit config changes
if (transactionalConfig.hasMutations()) {
DataOutput out = graph.getDataSerializer().getDataOutput(128);
out.writeObjectNotNull(MgmtLogType.CONFIG_MUTATION);
transactionalConfig.logMutations(out);
sysLog.add(out.getStaticBuffer());
}
transactionalConfig.commit();
//Commit underlying transaction
transaction.commit();
//Communicate schema changes
if (!updatedTypes.isEmpty()) {
mgmtLogger.sendCacheEviction(updatedTypes, updatedTypeTriggers, getOpenInstancesInternal());
for (TitanSchemaVertex schemaVertex : updatedTypes) {
schemaCache.expireSchemaElement(schemaVertex.longId());
}
}
if (graphShutdownRequired)
graph.close();
close();
}
use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.
the class StandardTransactionLogProcessor method fixSecondaryFailure.
private void fixSecondaryFailure(final StandardTransactionId txId, final TxEntry entry) {
logRecoveryMsg("Attempting to repair partially failed transaction [%s]", txId);
if (entry.entry == null) {
logRecoveryMsg("Trying to repair expired or unpersisted transaction [%s] (Ignore in startup)", txId);
return;
}
boolean userLogFailure = true;
boolean secIndexFailure = true;
final Predicate<String> isFailedIndex;
final TransactionLogHeader.Entry commitEntry = entry.entry;
final TransactionLogHeader.SecondaryFailures secFail = entry.failures;
if (secFail != null) {
userLogFailure = secFail.userLogFailure;
secIndexFailure = !secFail.failedIndexes.isEmpty();
isFailedIndex = new Predicate<String>() {
@Override
public boolean apply(@Nullable String s) {
return secFail.failedIndexes.contains(s);
}
};
} else {
isFailedIndex = Predicates.alwaysTrue();
}
// I) Restore external indexes
if (secIndexFailure) {
//1) Collect all elements (vertices and relations) and the indexes for which they need to be restored
final SetMultimap<String, IndexRestore> indexRestores = HashMultimap.create();
BackendOperation.execute(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
StandardTitanTx tx = (StandardTitanTx) graph.newTransaction();
try {
for (TransactionLogHeader.Modification modification : commitEntry.getContentAsModifications(serializer)) {
InternalRelation rel = ModificationDeserializer.parseRelation(modification, tx);
//Collect affected vertex indexes
for (MixedIndexType index : getMixedIndexes(rel.getType())) {
if (index.getElement() == ElementCategory.VERTEX && isFailedIndex.apply(index.getBackingIndexName())) {
assert rel.isProperty();
indexRestores.put(index.getBackingIndexName(), new IndexRestore(rel.getVertex(0).longId(), ElementCategory.VERTEX, getIndexId(index)));
}
}
//See if relation itself is affected
for (RelationType relType : rel.getPropertyKeysDirect()) {
for (MixedIndexType index : getMixedIndexes(relType)) {
if (index.getElement().isInstance(rel) && isFailedIndex.apply(index.getBackingIndexName())) {
assert rel.id() instanceof RelationIdentifier;
indexRestores.put(index.getBackingIndexName(), new IndexRestore(rel.id(), ElementCategory.getByClazz(rel.getClass()), getIndexId(index)));
}
}
}
}
} finally {
if (tx.isOpen())
tx.rollback();
}
return true;
}
}, readTime);
//2) Restore elements per backing index
for (final String indexName : indexRestores.keySet()) {
final StandardTitanTx tx = (StandardTitanTx) graph.newTransaction();
try {
BackendTransaction btx = tx.getTxHandle();
final IndexTransaction indexTx = btx.getIndexTransaction(indexName);
BackendOperation.execute(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
Map<String, Map<String, List<IndexEntry>>> restoredDocs = Maps.newHashMap();
for (IndexRestore restore : indexRestores.get(indexName)) {
TitanSchemaVertex indexV = (TitanSchemaVertex) tx.getVertex(restore.indexId);
MixedIndexType index = (MixedIndexType) indexV.asIndexType();
TitanElement element = restore.retrieve(tx);
if (element != null) {
graph.getIndexSerializer().reindexElement(element, index, restoredDocs);
} else {
//Element is deleted
graph.getIndexSerializer().removeElement(restore.elementId, index, restoredDocs);
}
}
indexTx.restore(restoredDocs);
indexTx.commit();
return true;
}
@Override
public String toString() {
return "IndexMutation";
}
}, persistenceTime);
} finally {
if (tx.isOpen())
tx.rollback();
}
}
}
// II) Restore log messages
final String logTxIdentifier = (String) commitEntry.getMetadata().get(LogTxMeta.LOG_ID);
if (userLogFailure && logTxIdentifier != null) {
TransactionLogHeader txHeader = new TransactionLogHeader(txCounter.incrementAndGet(), times.getTime(), times);
final StaticBuffer userLogContent = txHeader.serializeUserLog(serializer, commitEntry, txId);
BackendOperation.execute(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
final Log userLog = graph.getBackend().getUserLog(logTxIdentifier);
Future<Message> env = userLog.add(userLogContent);
if (env.isDone()) {
env.get();
}
return true;
}
}, persistenceTime);
}
}
Aggregations