Search in sources :

Example 1 with MetaIndex

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;
}
Also used : MutableMetaIndex(com.torodb.core.transaction.metainf.MutableMetaIndex) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with MetaIndex

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);
}
Also used : MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) IndexNotFoundException(com.torodb.core.exceptions.user.IndexNotFoundException)

Example 3 with MetaIndex

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);
    }
}
Also used : MutableMetaIndex(com.torodb.core.transaction.metainf.MutableMetaIndex) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart) MutableMetaIndex(com.torodb.core.transaction.metainf.MutableMetaIndex) IdentifierFactory(com.torodb.core.d2r.IdentifierFactory)

Example 4 with MetaIndex

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());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) Tuple2(org.jooq.lambda.tuple.Tuple2) ArrayList(java.util.ArrayList) List(java.util.List) MutableMetaDocPartIndex(com.torodb.core.transaction.metainf.MutableMetaDocPartIndex) MetaDocPartIndexColumn(com.torodb.core.transaction.metainf.MetaDocPartIndexColumn)

Example 5 with MetaIndex

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;
}
Also used : MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) KvTable(com.torodb.backend.tables.KvTable) Singleton(javax.inject.Singleton) Condition(org.jooq.Condition) MetaDocPartTable(com.torodb.backend.tables.MetaDocPartTable) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) Inject(javax.inject.Inject) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) Record1(org.jooq.Record1) DSLContext(org.jooq.DSLContext) Context(com.torodb.backend.ErrorHandler.Context) Nonnull(javax.annotation.Nonnull) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Record(org.jooq.Record) Iterator(java.util.Iterator) KvRecord(com.torodb.backend.tables.records.KvRecord) Collection(java.util.Collection) MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) Result(org.jooq.Result) TableRef(com.torodb.core.TableRef) Stream(java.util.stream.Stream) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) MetaInfoKey(com.torodb.core.backend.MetaInfoKey) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MetaDatabaseRecord(com.torodb.backend.tables.records.MetaDatabaseRecord) MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) TableRef(com.torodb.core.TableRef)

Aggregations

MetaIndex (com.torodb.core.transaction.metainf.MetaIndex)6 MutableMetaIndex (com.torodb.core.transaction.metainf.MutableMetaIndex)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)2 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)2 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)2 MetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex)2 Iterator (java.util.Iterator)2 Optional (java.util.Optional)2 Preconditions (com.google.common.base.Preconditions)1 Context (com.torodb.backend.ErrorHandler.Context)1 KvTable (com.torodb.backend.tables.KvTable)1 MetaDocPartTable (com.torodb.backend.tables.MetaDocPartTable)1 KvRecord (com.torodb.backend.tables.records.KvRecord)1 MetaDatabaseRecord (com.torodb.backend.tables.records.MetaDatabaseRecord)1 TableRef (com.torodb.core.TableRef)1 MetaInfoKey (com.torodb.core.backend.MetaInfoKey)1 IdentifierFactory (com.torodb.core.d2r.IdentifierFactory)1 IndexNotFoundException (com.torodb.core.exceptions.user.IndexNotFoundException)1 ImmutableMetaDocPartIndexColumn (com.torodb.core.transaction.metainf.ImmutableMetaDocPartIndexColumn)1