Skip to content

Commit

Permalink
Rename ClusterMetadataMarker to ClusterMetadataManifest
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <soosinha@amazon.com>
  • Loading branch information
soosinha committed Aug 30, 2023
1 parent 8f8e034 commit 6998fbd
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 135 deletions.
42 changes: 21 additions & 21 deletions server/src/main/java/org/opensearch/gateway/GatewayMetaState.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import org.opensearch.common.util.concurrent.OpenSearchThreadPoolExecutor;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.env.NodeMetadata;
import org.opensearch.gateway.remote.ClusterMetadataMarker;
import org.opensearch.gateway.remote.ClusterMetadataManifest;
import org.opensearch.gateway.remote.RemoteClusterStateService;
import org.opensearch.node.Node;
import org.opensearch.plugins.MetadataUpgrader;
Expand Down Expand Up @@ -611,7 +611,7 @@ public static class RemotePersistedState implements PersistedState {
private static final Logger logger = LogManager.getLogger(RemotePersistedState.class);

private ClusterState lastAcceptedState;
private ClusterMetadataMarker lastAcceptedMarker;
private ClusterMetadataManifest lastAcceptedManifest;
private final RemoteClusterStateService remoteClusterStateService;

public RemotePersistedState(final RemoteClusterStateService remoteClusterStateService) {
Expand Down Expand Up @@ -644,16 +644,16 @@ public void setLastAcceptedState(ClusterState clusterState) {
lastAcceptedState = clusterState;
return;
}
final ClusterMetadataMarker marker;
final ClusterMetadataManifest manifest;
if (shouldWriteFullClusterState(clusterState)) {
marker = remoteClusterStateService.writeFullMetadata(clusterState);
manifest = remoteClusterStateService.writeFullMetadata(clusterState);
} else {
assert verifyMarkerAndClusterState(lastAcceptedMarker, lastAcceptedState) == true
: "Previous Marker and previous ClusterState are not in sync";
marker = remoteClusterStateService.writeIncrementalMetadata(lastAcceptedState, clusterState, lastAcceptedMarker);
assert verifyManifestAndClusterState(lastAcceptedManifest, lastAcceptedState) == true
: "Previous manifest and previous ClusterState are not in sync";
manifest = remoteClusterStateService.writeIncrementalMetadata(lastAcceptedState, clusterState, lastAcceptedManifest);
}
assert verifyMarkerAndClusterState(marker, clusterState) == true : "Marker and ClusterState are not in sync";
lastAcceptedMarker = marker;
assert verifyManifestAndClusterState(manifest, clusterState) == true : "Manifest and ClusterState are not in sync";
lastAcceptedManifest = manifest;
lastAcceptedState = clusterState;
} catch (RepositoryMissingException e) {
// TODO This logic needs to be modified once PR for repo registration during bootstrap is pushed
Expand All @@ -666,25 +666,25 @@ assert verifyMarkerAndClusterState(lastAcceptedMarker, lastAcceptedState) == tru
}
}

private boolean verifyMarkerAndClusterState(ClusterMetadataMarker marker, ClusterState clusterState) {
assert marker != null : "ClusterMetadataMarker is null";
private boolean verifyManifestAndClusterState(ClusterMetadataManifest manifest, ClusterState clusterState) {
assert manifest != null : "ClusterMetadataManifest is null";
assert clusterState != null : "ClusterState is null";
assert clusterState.metadata().indices().size() == marker.getIndices().size()
: "Number of indices in last accepted state and marker are different";
marker.getIndices().stream().forEach(md -> {
assert clusterState.metadata().indices().size() == manifest.getIndices().size()
: "Number of indices in last accepted state and manifest are different";
manifest.getIndices().stream().forEach(md -> {
assert clusterState.metadata().indices().containsKey(md.getIndexName())
: "Last accepted state does not contain the index : " + md.getIndexName();
assert clusterState.metadata().indices().get(md.getIndexName()).getIndexUUID().equals(md.getIndexUUID())
: "Last accepted state and marker do not have same UUID for index : " + md.getIndexName();
: "Last accepted state and manifest do not have same UUID for index : " + md.getIndexName();
});
return true;
}

private boolean shouldWriteFullClusterState(ClusterState clusterState) {
if (lastAcceptedState == null
|| lastAcceptedMarker == null
|| lastAcceptedManifest == null
|| lastAcceptedState.term() != clusterState.term()
|| lastAcceptedMarker.getOpensearchVersion() != Version.CURRENT) {
|| lastAcceptedManifest.getOpensearchVersion() != Version.CURRENT) {
return true;
}
return false;
Expand All @@ -694,17 +694,17 @@ private boolean shouldWriteFullClusterState(ClusterState clusterState) {
public void markLastAcceptedStateAsCommitted() {
try {
if (lastAcceptedState == null
|| lastAcceptedMarker == null
|| lastAcceptedManifest == null
|| lastAcceptedState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
// On the initial bootstrap, repository will not be available. So we do not persist the cluster state and bail out.
logger.trace("Cluster is not yet ready to publish state to remote store");
return;
}
final ClusterMetadataMarker committedMarker = remoteClusterStateService.markLastStateAsCommitted(
final ClusterMetadataManifest committedManifest = remoteClusterStateService.markLastStateAsCommitted(
lastAcceptedState,
lastAcceptedMarker
lastAcceptedManifest
);
lastAcceptedMarker = committedMarker;
lastAcceptedManifest = committedManifest;
} catch (Exception e) {
handleExceptionOnWrite(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import java.util.Objects;

/**
* Marker file which contains the details of the uploaded entity metadata
* Manifest file which contains the details of the uploaded entity metadata
*
* @opensearch.internal
*/
public class ClusterMetadataMarker implements Writeable, ToXContentFragment {
public class ClusterMetadataManifest implements Writeable, ToXContentFragment {

private static final ParseField CLUSTER_TERM_FIELD = new ParseField("cluster_term");
private static final ParseField STATE_VERSION_FIELD = new ParseField("state_version");
Expand Down Expand Up @@ -74,9 +74,9 @@ private static List<UploadedIndexMetadata> indices(Object[] fields) {
return (List<UploadedIndexMetadata>) fields[7];
}

private static final ConstructingObjectParser<ClusterMetadataMarker, Void> PARSER = new ConstructingObjectParser<>(
"cluster_metadata_marker",
fields -> new ClusterMetadataMarker(
private static final ConstructingObjectParser<ClusterMetadataManifest, Void> PARSER = new ConstructingObjectParser<>(
"cluster_metadata_manifest",
fields -> new ClusterMetadataManifest(
term(fields),
version(fields),
clusterUUID(fields),
Expand Down Expand Up @@ -144,7 +144,7 @@ public boolean isCommitted() {
return committed;
}

public ClusterMetadataMarker(
public ClusterMetadataManifest(
long clusterTerm,
long version,
String clusterUUID,
Expand All @@ -164,7 +164,7 @@ public ClusterMetadataMarker(
this.indices = Collections.unmodifiableList(indices);
}

public ClusterMetadataMarker(StreamInput in) throws IOException {
public ClusterMetadataManifest(StreamInput in) throws IOException {
this.clusterTerm = in.readVLong();
this.stateVersion = in.readVLong();
this.clusterUUID = in.readString();
Expand All @@ -179,8 +179,8 @@ public static Builder builder() {
return new Builder();
}

public static Builder builder(ClusterMetadataMarker marker) {
return new Builder(marker);
public static Builder builder(ClusterMetadataManifest manifest) {
return new Builder(manifest);
}

@Override
Expand Down Expand Up @@ -222,7 +222,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
final ClusterMetadataMarker that = (ClusterMetadataMarker) o;
final ClusterMetadataManifest that = (ClusterMetadataManifest) o;
return Objects.equals(indices, that.indices)
&& clusterTerm == that.clusterTerm
&& stateVersion == that.stateVersion
Expand All @@ -243,12 +243,12 @@ public String toString() {
return Strings.toString(MediaTypeRegistry.JSON, this);
}

public static ClusterMetadataMarker fromXContent(XContentParser parser) throws IOException {
public static ClusterMetadataManifest fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}

/**
* Builder for ClusterMetadataMarker
* Builder for ClusterMetadataManifest
*
* @opensearch.internal
*/
Expand Down Expand Up @@ -311,19 +311,19 @@ public Builder() {
indices = new ArrayList<>();
}

public Builder(ClusterMetadataMarker marker) {
this.clusterTerm = marker.clusterTerm;
this.stateVersion = marker.stateVersion;
this.clusterUUID = marker.clusterUUID;
this.stateUUID = marker.stateUUID;
this.opensearchVersion = marker.opensearchVersion;
this.nodeId = marker.nodeId;
this.committed = marker.committed;
this.indices = new ArrayList<>(marker.indices);
public Builder(ClusterMetadataManifest manifest) {
this.clusterTerm = manifest.clusterTerm;
this.stateVersion = manifest.stateVersion;
this.clusterUUID = manifest.clusterUUID;
this.stateUUID = manifest.stateUUID;
this.opensearchVersion = manifest.opensearchVersion;
this.nodeId = manifest.nodeId;
this.committed = manifest.committed;
this.indices = new ArrayList<>(manifest.indices);
}

public ClusterMetadataMarker build() {
return new ClusterMetadataMarker(
public ClusterMetadataManifest build() {
return new ClusterMetadataManifest(
clusterTerm,
stateVersion,
clusterUUID,
Expand Down

0 comments on commit 6998fbd

Please sign in to comment.