Skip to content

Commit

Permalink
Support several PgContext in indexMaintenance.get* methods (#82)
Browse files Browse the repository at this point in the history
* Updated javadoc

* Added 'enrichWithSchema' method

* Added javadoc for ForeignKey

* Support several PgContext in indexMaintenance.get* methods

* Added  multiple schemas support to IndexesHealth

Co-authored-by: ivan.vakhrushev <[email protected]>
  • Loading branch information
mfvanek and ivan.vakhrushev authored Apr 26, 2020
1 parent 5484de6 commit aa6f9e1
Show file tree
Hide file tree
Showing 13 changed files with 951 additions and 238 deletions.
105 changes: 104 additions & 1 deletion src/main/java/io/github/mfvanek/pg/index/health/IndexesHealth.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,50 @@
import io.github.mfvanek.pg.model.UnusedIndex;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
* An entry point for collecting and managing statistics about the health of tables and indexes on all hosts in the cluster.
* An entry point for collecting and managing statistics
* about the health of tables and indexes on all hosts in the cluster.
*
* @author Ivan Vakhrushev
* @see PgContext
*/
public interface IndexesHealth {

/**
* Returns invalid (broken) indexes to be deleted or re-indexed on the master host in the specified schema.
*
* @param pgContext {@code PgContext} with the specified schema
* @return list of invalid indexes
* @see Index
*/
@Nonnull
List<Index> getInvalidIndexes(@Nonnull PgContext pgContext);

/**
* Returns invalid (broken) indexes to be deleted or re-indexed on the master host in the specified schemas.
*
* @param pgContexts a set of contexts specifying schemas
* @return list of invalid indexes
* @see Index
*/
@Nonnull
default List<Index> getInvalidIndexes(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getInvalidIndexes)
.flatMap(List::stream)
.collect(Collectors.toList());
}

/**
* Returns invalid (broken) indexes to be deleted or re-indexed on the master host in the public schema.
*
* @return list of invalid indexes
* @see Index
*/
@Nonnull
default List<Index> getInvalidIndexes() {
return getInvalidIndexes(PgContext.ofPublic());
Expand All @@ -43,6 +74,14 @@ default List<Index> getInvalidIndexes() {
@Nonnull
List<DuplicatedIndexes> getDuplicatedIndexes(@Nonnull PgContext pgContext);

@Nonnull
default List<DuplicatedIndexes> getDuplicatedIndexes(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getDuplicatedIndexes)
.flatMap(List::stream)
.collect(Collectors.toList());
}

@Nonnull
default List<DuplicatedIndexes> getDuplicatedIndexes() {
return getDuplicatedIndexes(PgContext.ofPublic());
Expand All @@ -51,6 +90,14 @@ default List<DuplicatedIndexes> getDuplicatedIndexes() {
@Nonnull
List<DuplicatedIndexes> getIntersectedIndexes(@Nonnull PgContext pgContext);

@Nonnull
default List<DuplicatedIndexes> getIntersectedIndexes(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getIntersectedIndexes)
.flatMap(List::stream)
.collect(Collectors.toList());
}

@Nonnull
default List<DuplicatedIndexes> getIntersectedIndexes() {
return getIntersectedIndexes(PgContext.ofPublic());
Expand All @@ -59,6 +106,14 @@ default List<DuplicatedIndexes> getIntersectedIndexes() {
@Nonnull
List<UnusedIndex> getUnusedIndexes(@Nonnull PgContext pgContext);

@Nonnull
default List<UnusedIndex> getUnusedIndexes(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getUnusedIndexes)
.flatMap(List::stream)
.collect(Collectors.toList());
}

@Nonnull
default List<UnusedIndex> getUnusedIndexes() {
return getUnusedIndexes(PgContext.ofPublic());
Expand All @@ -67,6 +122,14 @@ default List<UnusedIndex> getUnusedIndexes() {
@Nonnull
List<ForeignKey> getForeignKeysNotCoveredWithIndex(@Nonnull PgContext pgContext);

@Nonnull
default List<ForeignKey> getForeignKeysNotCoveredWithIndex(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getForeignKeysNotCoveredWithIndex)
.flatMap(List::stream)
.collect(Collectors.toList());
}

@Nonnull
default List<ForeignKey> getForeignKeysNotCoveredWithIndex() {
return getForeignKeysNotCoveredWithIndex(PgContext.ofPublic());
Expand All @@ -75,6 +138,14 @@ default List<ForeignKey> getForeignKeysNotCoveredWithIndex() {
@Nonnull
List<TableWithMissingIndex> getTablesWithMissingIndexes(@Nonnull PgContext pgContext);

@Nonnull
default List<TableWithMissingIndex> getTablesWithMissingIndexes(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getTablesWithMissingIndexes)
.flatMap(List::stream)
.collect(Collectors.toList());
}

@Nonnull
default List<TableWithMissingIndex> getTablesWithMissingIndexes() {
return getTablesWithMissingIndexes(PgContext.ofPublic());
Expand All @@ -83,6 +154,14 @@ default List<TableWithMissingIndex> getTablesWithMissingIndexes() {
@Nonnull
List<Table> getTablesWithoutPrimaryKey(@Nonnull PgContext pgContext);

@Nonnull
default List<Table> getTablesWithoutPrimaryKey(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getTablesWithoutPrimaryKey)
.flatMap(List::stream)
.collect(Collectors.toList());
}

@Nonnull
default List<Table> getTablesWithoutPrimaryKey() {
return getTablesWithoutPrimaryKey(PgContext.ofPublic());
Expand All @@ -99,6 +178,14 @@ default List<Table> getTablesWithoutPrimaryKey() {
@Nonnull
List<IndexWithNulls> getIndexesWithNullValues(@Nonnull PgContext pgContext);

@Nonnull
default List<IndexWithNulls> getIndexesWithNullValues(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getIndexesWithNullValues)
.flatMap(List::stream)
.collect(Collectors.toList());
}

/**
* Returns indexes in the public schema on master host that contain null values.
*
Expand All @@ -122,6 +209,14 @@ default List<IndexWithNulls> getIndexesWithNullValues() {
@Nonnull
List<IndexWithBloat> getIndexesWithBloat(@Nonnull PgContext pgContext);

@Nonnull
default List<IndexWithBloat> getIndexesWithBloat(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getIndexesWithBloat)
.flatMap(List::stream)
.collect(Collectors.toList());
}

/**
* Returns bloated indexes in the public schema on master host.
*
Expand All @@ -145,6 +240,14 @@ default List<IndexWithBloat> getIndexesWithBloat() {
@Nonnull
List<TableWithBloat> getTablesWithBloat(@Nonnull PgContext pgContext);

@Nonnull
default List<TableWithBloat> getTablesWithBloat(@Nonnull Collection<PgContext> pgContexts) {
return pgContexts.stream()
.map(this::getTablesWithBloat)
.flatMap(List::stream)
.collect(Collectors.toList());
}

/**
* Returns bloated tables in the public schema on master host.
*
Expand Down
Loading

0 comments on commit aa6f9e1

Please sign in to comment.