use of com.torodb.core.transaction.metainf.MetaIndex in project torodb by torodb.
the class SqlWriteTorodTransaction method dropIndex.
@SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT", justification = "Findbugs thinks MutableMetaCollection#removeMetaIndexByName" + "has no side effect")
@Override
public boolean dropIndex(String dbName, String colName, String indexName) {
MutableMetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
if (db == null) {
return false;
}
MutableMetaCollection col = db.getMetaCollectionByName(colName);
if (col == null) {
return false;
}
MetaIndex index = col.getMetaIndexByName(indexName);
if (index == null) {
return false;
}
col.removeMetaIndexByName(indexName);
getInternalTransaction().getBackendTransaction().dropIndex(db, col, index);
return true;
}
use of com.torodb.core.transaction.metainf.MetaIndex in project torodb by torodb.
the class SqlTorodTransaction method getIndexInfo.
@Override
public IndexInfo getIndexInfo(String dbName, String colName, String idxName) throws IndexNotFoundException {
MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
if (db == null) {
throw new IndexNotFoundException(dbName, colName, idxName);
}
MetaCollection col = db.getMetaCollectionByName(colName);
if (col == null) {
throw new IndexNotFoundException(dbName, colName, idxName);
}
MetaIndex idx = col.getMetaIndexByName(idxName);
if (idx == null) {
throw new IndexNotFoundException(dbName, colName, idxName);
}
return createIndexInfo(idx);
}
use of com.torodb.core.transaction.metainf.MetaIndex in project torodb by torodb.
the class ExclusiveWriteBackendTransactionImpl method copyMetaCollection.
private void copyMetaCollection(MetaDatabase fromDb, MetaCollection fromColl, MutableMetaDatabase toDb, MutableMetaCollection toColl) {
IdentifierFactory identifierFactory = getIdentifierFactory();
Iterator<? extends MetaIndex> fromMetaIndexIterator = fromColl.streamContainedMetaIndexes().iterator();
while (fromMetaIndexIterator.hasNext()) {
MetaIndex fromMetaIndex = fromMetaIndexIterator.next();
MutableMetaIndex toMetaIndex = toColl.addMetaIndex(fromMetaIndex.getName(), fromMetaIndex.isUnique());
getSqlInterface().getMetaDataWriteInterface().addMetaIndex(getDsl(), toDb, toColl, toMetaIndex);
copyIndexFields(fromMetaIndex, toDb, toColl, toMetaIndex);
}
Iterator<? extends MetaDocPart> fromMetaDocPartIterator = fromColl.streamContainedMetaDocParts().iterator();
while (fromMetaDocPartIterator.hasNext()) {
MetaDocPart fromMetaDocPart = fromMetaDocPartIterator.next();
MutableMetaDocPart toMetaDocPart = toColl.addMetaDocPart(fromMetaDocPart.getTableRef(), identifierFactory.toDocPartIdentifier(toDb, toColl.getName(), fromMetaDocPart.getTableRef()));
getSqlInterface().getMetaDataWriteInterface().addMetaDocPart(getDsl(), toDb, toColl, toMetaDocPart);
copyScalar(identifierFactory, fromMetaDocPart, toDb, toColl, toMetaDocPart);
copyFields(identifierFactory, fromMetaDocPart, toDb, toColl, toMetaDocPart);
copyIndexes(identifierFactory, fromMetaDocPart, toDb, toColl, toMetaDocPart);
int nextRid = ridGenerator.getDocPartRidGenerator(fromDb.getName(), fromColl.getName()).nextRid(fromMetaDocPart.getTableRef());
ridGenerator.getDocPartRidGenerator(toDb.getName(), toColl.getName()).setNextRid(toMetaDocPart.getTableRef(), nextRid - 1);
}
}
use of com.torodb.core.transaction.metainf.MetaIndex in project torodb by torodb.
the class SharedWriteBackendTransactionImpl method addField.
@Override
public void addField(MetaDatabase db, MetaCollection col, MutableMetaDocPart docPart, MetaField newField) throws UserException {
Preconditions.checkState(!isClosed(), "This transaction is closed");
getSqlInterface().getMetaDataWriteInterface().addMetaField(getDsl(), db, col, docPart, newField);
getSqlInterface().getStructureInterface().addColumnToDocPartTable(getDsl(), db.getIdentifier(), docPart.getIdentifier(), newField.getIdentifier(), getSqlInterface().getDataTypeProvider().getDataType(newField.getType()));
List<Tuple2<MetaIndex, List<String>>> missingIndexes = col.getMissingIndexesForNewField(docPart, newField);
for (Tuple2<MetaIndex, List<String>> missingIndexEntry : missingIndexes) {
MetaIndex missingIndex = missingIndexEntry.v1();
List<String> identifiers = missingIndexEntry.v2();
MutableMetaDocPartIndex docPartIndex = docPart.getOrCreatePartialMutableDocPartIndexForMissingIndexAndNewField(missingIndex, identifiers, newField);
if (missingIndex.isMatch(docPart, identifiers, docPartIndex)) {
List<Tuple2<String, Boolean>> columnList = new ArrayList<>(docPartIndex.size());
for (String identifier : identifiers) {
MetaDocPartIndexColumn docPartIndexColumn = docPartIndex.getMetaDocPartIndexColumnByIdentifier(identifier);
columnList.add(new Tuple2<>(docPartIndexColumn.getIdentifier(), docPartIndexColumn.getOrdering().isAscending()));
}
MetaIdentifiedDocPartIndex identifiedDocPartIndex = docPartIndex.immutableCopy(identifierFactory.toIndexIdentifier(db, docPart.getIdentifier(), columnList));
getSqlInterface().getMetaDataWriteInterface().addMetaDocPartIndex(getDsl(), db, col, docPart, identifiedDocPartIndex);
for (String identifier : identifiers) {
MetaDocPartIndexColumn docPartIndexColumn = docPartIndex.getMetaDocPartIndexColumnByIdentifier(identifier);
getSqlInterface().getMetaDataWriteInterface().addMetaDocPartIndexColumn(getDsl(), db, col, docPart, identifiedDocPartIndex, docPartIndexColumn);
}
getSqlInterface().getStructureInterface().createIndex(getDsl(), identifiedDocPartIndex.getIdentifier(), db.getIdentifier(), docPart.getIdentifier(), columnList, docPartIndex.isUnique());
LOGGER.info("Created index {} for table {} associated to logical index {}.{}.{}", identifiedDocPartIndex.getIdentifier(), docPart.getIdentifier(), db.getName(), col.getName(), missingIndex.getName());
}
}
}
use of com.torodb.core.transaction.metainf.MetaIndex in project torodb by torodb.
the class AbstractMetaDataReadInterface method getIndexSize.
@Override
public Long getIndexSize(@Nonnull DSLContext dsl, @Nonnull MetaDatabase database, @Nonnull MetaCollection collection, @Nonnull String indexName) {
long result = 0;
MetaIndex index = collection.getMetaIndexByName(indexName);
Iterator<TableRef> tableRefIterator = index.streamTableRefs().iterator();
while (tableRefIterator.hasNext()) {
TableRef tableRef = tableRefIterator.next();
MetaDocPart docPart = collection.getMetaDocPartByTableRef(tableRef);
Iterator<? extends MetaIdentifiedDocPartIndex> docPartIndexIterator = docPart.streamIndexes().iterator();
while (docPartIndexIterator.hasNext()) {
MetaIdentifiedDocPartIndex docPartIndex = docPartIndexIterator.next();
if (index.isCompatible(docPart, docPartIndex)) {
long relatedIndexCount = collection.streamContainedMetaIndexes().filter(i -> i.isCompatible(docPart, docPartIndex)).count();
String statement = getReadIndexSizeStatement(database.getIdentifier(), docPart.getIdentifier(), docPartIndex.getIdentifier());
result += sqlHelper.executeStatementWithResult(dsl, statement, Context.FETCH).get(0).into(Long.class) / relatedIndexCount;
}
}
}
return result;
}
Aggregations