Search in sources :

Example 1 with Index

use of jetbrains.exodus.query.metadata.Index in project xodus by JetBrains.

the class UniqueKeyIndicesEngine method updateUniqueKeyIndices.

public void updateUniqueKeyIndices(@NotNull final Iterable<Index> indices) {
    final Environment environment = persistentStore.getEnvironment();
    environment.suspendGC();
    try {
        persistentStore.executeInTransaction(new StoreTransactionalExecutable() {

            @Override
            public void execute(@NotNull StoreTransaction txn) {
                final PersistentStoreTransaction t = (PersistentStoreTransaction) txn;
                final PersistentStoreTransaction snapshot = t.getSnapshot();
                try {
                    final Collection<String> indexNames = new HashSet<>();
                    for (final String dbName : environment.getAllStoreNames(t.getEnvironmentTransaction())) {
                        if (isUniqueKeyIndexName(dbName)) {
                            indexNames.add(dbName);
                        }
                    }
                    for (final Index index : indices) {
                        final String indexName = getUniqueKeyIndexName(index);
                        if (indexNames.contains(indexName)) {
                            indexNames.remove(indexName);
                        } else {
                            createUniqueKeyIndex(t, snapshot, index);
                        }
                    }
                    // remove obsolete indices
                    for (final String indexName : indexNames) {
                        removeObsoleteUniqueKeyIndex(t, indexName);
                    }
                    if (logger.isTraceEnabled()) {
                        logger.trace("Flush index persistent transaction " + t);
                    }
                    t.flush();
                } finally {
                    // reading snapshot is obsolete now
                    snapshot.abort();
                }
            }
        });
    } finally {
        environment.resumeGC();
    }
}
Also used : Environment(jetbrains.exodus.env.Environment) Index(jetbrains.exodus.query.metadata.Index)

Aggregations

Environment (jetbrains.exodus.env.Environment)1 Index (jetbrains.exodus.query.metadata.Index)1