Skip to content

Commit

Permalink
rename to SnapshotDeletionsPending
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrx committed Oct 18, 2021
1 parent 9a73ba7 commit 579c21f
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public static List<Entry> getNamedWriteables() {
SnapshotDeletionsInProgress::readDiffFrom);
registerClusterCustom(entries, RepositoryCleanupInProgress.TYPE, RepositoryCleanupInProgress::new,
RepositoryCleanupInProgress::readDiffFrom);
registerClusterCustom(entries, SnapshotDeletionsInPending.TYPE, SnapshotDeletionsInPending::new,
SnapshotDeletionsInPending::readDiffFrom);
registerClusterCustom(entries, SnapshotDeletionsPending.TYPE, SnapshotDeletionsPending::new,
SnapshotDeletionsPending::readDiffFrom);
// Metadata
registerMetadataCustom(entries, RepositoriesMetadata.TYPE, RepositoriesMetadata::new, RepositoriesMetadata::readDiffFrom);
registerMetadataCustom(entries, IngestMetadata.TYPE, IngestMetadata::new, IngestMetadata::readDiffFrom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
/**
* Represents snapshots marked as to be deleted and pending deletion.
*/
public class SnapshotDeletionsInPending extends AbstractNamedDiffable<Custom> implements Custom {
public class SnapshotDeletionsPending extends AbstractNamedDiffable<Custom> implements Custom {

public static final SnapshotDeletionsInPending EMPTY = new SnapshotDeletionsInPending(Collections.emptySortedSet());
public static final SnapshotDeletionsPending EMPTY = new SnapshotDeletionsPending(Collections.emptySortedSet());
public static final String TYPE = "snapshot_deletions_pending";

public static final int MAX_PENDING_DELETIONS = 500;
Expand All @@ -44,12 +44,12 @@ public class SnapshotDeletionsInPending extends AbstractNamedDiffable<Custom> im
*/
private final SortedSet<Entry> entries;

private SnapshotDeletionsInPending(SortedSet<Entry> entries) {
private SnapshotDeletionsPending(SortedSet<Entry> entries) {
this.entries = unmodifiableSortedSet(Objects.requireNonNull(entries));
assert entries.size() <= MAX_PENDING_DELETIONS : entries.size() + " > " + MAX_PENDING_DELETIONS;
}

public SnapshotDeletionsInPending(StreamInput in) throws IOException {
public SnapshotDeletionsPending(StreamInput in) throws IOException {
this(new TreeSet<>(in.readSet(Entry::new)));
}

Expand Down Expand Up @@ -90,7 +90,7 @@ public Version getMinimalSupportedVersion() {
return Version.CURRENT.minimumCompatibilityVersion();
}

public SnapshotDeletionsInPending withRemovedSnapshots(Set<SnapshotId> snapshotIds) {
public SnapshotDeletionsPending withRemovedSnapshots(Set<SnapshotId> snapshotIds) {
if (snapshotIds == null || snapshotIds.isEmpty()) {
return this;
}
Expand All @@ -104,13 +104,13 @@ public SnapshotDeletionsInPending withRemovedSnapshots(Set<SnapshotId> snapshotI
} else if (updatedEntries.isEmpty()) {
return EMPTY;
} else {
return new SnapshotDeletionsInPending(updatedEntries);
return new SnapshotDeletionsPending(updatedEntries);
}
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder("SnapshotDeletionsInPending[");
final StringBuilder builder = new StringBuilder("SnapshotDeletionsPending[");
boolean prepend = true;

final Iterator<Entry> iterator = entries.stream().iterator();
Expand Down Expand Up @@ -216,8 +216,8 @@ public static final class Builder {
private final SortedSet<Entry> entries = new TreeSet<>();
private final Consumer<Entry> consumer;

public Builder(SnapshotDeletionsInPending snapshotDeletionsInPending, Consumer<Entry> onLimitExceeded) {
entries.addAll(snapshotDeletionsInPending.entries);
public Builder(SnapshotDeletionsPending snapshotDeletionsPending, Consumer<Entry> onLimitExceeded) {
entries.addAll(snapshotDeletionsPending.entries);
this.consumer = onLimitExceeded;
}

Expand All @@ -237,9 +237,9 @@ public Builder add(String repositoryName, String repositoryUuid, SnapshotId snap
return this;
}

public SnapshotDeletionsInPending build() {
public SnapshotDeletionsPending build() {
ensureLimit();
return entries.isEmpty() == false ? new SnapshotDeletionsInPending(entries) : EMPTY;
return entries.isEmpty() == false ? new SnapshotDeletionsPending(entries) : EMPTY;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.RestoreInProgress;
import org.elasticsearch.cluster.SnapshotDeletionsInPending;
import org.elasticsearch.cluster.SnapshotDeletionsPending;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
Expand Down Expand Up @@ -149,31 +149,31 @@ public ClusterState deleteIndices(ClusterState currentState, Set<Index> indices)
}

// update snapshot(s) marked as to delete
final SnapshotDeletionsInPending deletionsInPending = currentState.custom(
SnapshotDeletionsInPending.TYPE,
SnapshotDeletionsInPending.EMPTY
final SnapshotDeletionsPending deletionsInPending = currentState.custom(
SnapshotDeletionsPending.TYPE,
SnapshotDeletionsPending.EMPTY
);
final SnapshotDeletionsInPending updatedPendingDeletes = updateSnapshotDeletionsPending(deletionsInPending, indicesToDelete, meta);
final SnapshotDeletionsPending updatedPendingDeletes = updateSnapshotDeletionsPending(deletionsInPending, indicesToDelete, meta);
if (updatedPendingDeletes != deletionsInPending) {
if (customBuilder == null) {
customBuilder = ImmutableOpenMap.builder(currentState.getCustoms());
}
customBuilder.put(SnapshotDeletionsInPending.TYPE, updatedPendingDeletes);
customBuilder.put(SnapshotDeletionsPending.TYPE, updatedPendingDeletes);
}
if (customBuilder != null) {
builder.customs(customBuilder.build());
}
return allocationService.reroute(builder.build(), "deleted indices [" + indices + "]");
}

private SnapshotDeletionsInPending updateSnapshotDeletionsPending(
final SnapshotDeletionsInPending pendingDeletions,
private SnapshotDeletionsPending updateSnapshotDeletionsPending(
final SnapshotDeletionsPending pendingDeletions,
final Set<Index> indicesToDelete,
final Metadata metadata
) {
if (indicesToDelete.isEmpty() == false) {
final long timestamp = Instant.now().toEpochMilli();
SnapshotDeletionsInPending.Builder builder = null;
SnapshotDeletionsPending.Builder builder = null;
boolean changed = false;

for (Index indexToDelete : indicesToDelete) {
Expand Down Expand Up @@ -215,13 +215,13 @@ private SnapshotDeletionsInPending updateSnapshotDeletionsPending(
}
if (canDeleteSnapshot) {
if (builder == null) {
builder = new SnapshotDeletionsInPending.Builder(
builder = new SnapshotDeletionsPending.Builder(
pendingDeletions,
evicted -> logger.warn(
() -> new ParameterizedMessage(
"maximum number of snapshots [{}] awaiting deletion has been reached in "
+ "cluster state before snapshot [{}] deleted on [{}] in repository [{}/{}] could be deleted",
SnapshotDeletionsInPending.MAX_PENDING_DELETIONS,
SnapshotDeletionsPending.MAX_PENDING_DELETIONS,
evicted.getSnapshotId(),
Instant.ofEpochMilli(evicted.getCreationTime()).atZone(ZoneOffset.UTC),
evicted.getRepositoryName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.RepositoryCleanupInProgress;
import org.elasticsearch.cluster.SnapshotDeletionsInPending;
import org.elasticsearch.cluster.SnapshotDeletionsInProgress;
import org.elasticsearch.cluster.SnapshotDeletionsPending;
import org.elasticsearch.cluster.SnapshotsInProgress;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
Expand Down Expand Up @@ -2506,7 +2506,7 @@ private ClusterState updateRepositoryGenerationsIfNecessary(ClusterState state,
}
}
updatedDeletionsInProgress = changedDeletions ? SnapshotDeletionsInProgress.of(deletionEntries) : null;
final SnapshotDeletionsInPending pendingDeletions = state.custom(SnapshotDeletionsInPending.TYPE);
final SnapshotDeletionsPending pendingDeletions = state.custom(SnapshotDeletionsPending.TYPE);
return SnapshotsService.updateWithSnapshots(state, updatedSnapshotsInProgress, updatedDeletionsInProgress, pendingDeletions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.RestoreInProgress;
import org.elasticsearch.cluster.RestoreInProgress.ShardRestoreStatus;
import org.elasticsearch.cluster.SnapshotDeletionsInPending;
import org.elasticsearch.cluster.SnapshotDeletionsInProgress;
import org.elasticsearch.cluster.SnapshotDeletionsPending;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.DataStream;
Expand Down Expand Up @@ -1377,7 +1377,7 @@ private void ensureSnapshotNotDeletedOrPendingDeletion(ClusterState currentState
"cannot restore a snapshot while a snapshot deletion is in-progress [" + deletionsInProgress.getEntries().get(0) + "]"
);
}
SnapshotDeletionsInPending pendingDeletions = currentState.custom(SnapshotDeletionsInPending.TYPE);
SnapshotDeletionsPending pendingDeletions = currentState.custom(SnapshotDeletionsPending.TYPE);
if (pendingDeletions != null && pendingDeletions.contains(snapshot.getSnapshotId())) {
throw new ConcurrentSnapshotExecutionException(
snapshot,
Expand Down
Loading

0 comments on commit 579c21f

Please sign in to comment.