use of com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex in project torodb by torodb.
the class SharedWriteBackendTransactionImpl method dropIndex.
@Override
public void dropIndex(MetaDatabase db, MutableMetaCollection col, MetaIndex index) {
Preconditions.checkState(!isClosed(), "This transaction is closed");
getSqlInterface().getMetaDataWriteInterface().deleteMetaIndex(getDsl(), db, col, index);
Iterator<TableRef> tableRefIterator = index.streamTableRefs().iterator();
while (tableRefIterator.hasNext()) {
TableRef tableRef = tableRefIterator.next();
MutableMetaDocPart docPart = col.getMetaDocPartByTableRef(tableRef);
if (docPart != null) {
Iterator<? extends MetaIdentifiedDocPartIndex> docPartIndexesIterator = docPart.streamIndexes().iterator();
while (docPartIndexesIterator.hasNext()) {
MetaIdentifiedDocPartIndex docPartIndex = docPartIndexesIterator.next();
if (index.isCompatible(docPart, docPartIndex)) {
boolean existsAnyOtherCompatibleIndex = col.streamContainedMetaIndexes().anyMatch(otherIndex -> otherIndex != index && otherIndex.isCompatible(docPart, docPartIndex));
if (!existsAnyOtherCompatibleIndex) {
dropIndex(db, col, docPart, docPartIndex);
LOGGER.info("Dropped index {} for table {}", docPartIndex.getIdentifier(), docPart.getIdentifier());
}
}
}
}
}
}
use of com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex 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.MetaIdentifiedDocPartIndex 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;
}
use of com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex in project torodb by torodb.
the class AbstractStructureInterface method renameCollection.
@Override
public void renameCollection(DSLContext dsl, String fromSchemaName, MetaCollection fromCollection, String toSchemaName, MetaCollection toCollection) {
Iterator<? extends MetaDocPart> metaDocPartIterator = fromCollection.streamContainedMetaDocParts().iterator();
while (metaDocPartIterator.hasNext()) {
MetaDocPart fromMetaDocPart = metaDocPartIterator.next();
MetaDocPart toMetaDocPart = toCollection.getMetaDocPartByTableRef(fromMetaDocPart.getTableRef());
String renameStatement = getRenameTableStatement(fromSchemaName, fromMetaDocPart.getIdentifier(), toMetaDocPart.getIdentifier());
sqlHelper.executeUpdate(dsl, renameStatement, Context.RENAME_TABLE);
Iterator<? extends MetaIdentifiedDocPartIndex> metaDocPartIndexIterator = fromMetaDocPart.streamIndexes().iterator();
while (metaDocPartIndexIterator.hasNext()) {
MetaIdentifiedDocPartIndex fromMetaIndex = metaDocPartIndexIterator.next();
MetaIdentifiedDocPartIndex toMetaIndex = toMetaDocPart.streamIndexes().filter(index -> index.hasSameColumns(fromMetaIndex)).findAny().get();
String renameIndexStatement = getRenameIndexStatement(fromSchemaName, fromMetaIndex.getIdentifier(), toMetaIndex.getIdentifier());
sqlHelper.executeUpdate(dsl, renameIndexStatement, Context.RENAME_INDEX);
}
if (!fromSchemaName.equals(toSchemaName)) {
String setSchemaStatement = getSetTableSchemaStatement(fromSchemaName, fromMetaDocPart.getIdentifier(), toSchemaName);
sqlHelper.executeUpdate(dsl, setSchemaStatement, Context.SET_TABLE_SCHEMA);
}
}
}
use of com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex in project torodb by torodb.
the class BackendServiceImpl method enableIndexJobs.
private Stream<Consumer<DSLContext>> enableIndexJobs(MetaDatabase db, MetaCollection col) {
List<Consumer<DSLContext>> consumerList = new ArrayList<>();
Iterator<? extends MetaDocPart> docPartIterator = col.streamContainedMetaDocParts().iterator();
while (docPartIterator.hasNext()) {
MetaDocPart docPart = docPartIterator.next();
Iterator<? extends MetaIdentifiedDocPartIndex> docPartIndexIterator = docPart.streamIndexes().iterator();
while (docPartIndexIterator.hasNext()) {
MetaIdentifiedDocPartIndex docPartIndex = docPartIndexIterator.next();
consumerList.add(createIndexJob(db, docPart, docPartIndex));
}
}
return consumerList.stream();
}
Aggregations