-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Segment Replication] Rolling upgrade support for default codecs #7698
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,13 @@ | |
import org.apache.lucene.codecs.Codec; | ||
import org.apache.lucene.codecs.lucene95.Lucene95Codec; | ||
import org.apache.lucene.codecs.lucene95.Lucene95Codec.Mode; | ||
import org.opensearch.Version; | ||
import org.opensearch.common.Nullable; | ||
import org.opensearch.common.collect.MapBuilder; | ||
import org.opensearch.index.mapper.MapperService; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
|
@@ -58,8 +61,11 @@ public class CodecService { | |
public static final String BEST_COMPRESSION_CODEC = "best_compression"; | ||
/** the raw unfiltered lucene default. useful for testing */ | ||
public static final String LUCENE_DEFAULT_CODEC = "lucene_default"; | ||
static Map<Version, String> versionStringMap = new HashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This variable declaration can go inside |
||
public static Map<Version, String> opensearchVersionToLuceneCodec; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable can be scoped protected that still allows integrations overriding CodecService to provide their own mapping |
||
|
||
public CodecService(@Nullable MapperService mapperService, Logger logger) { | ||
loadMap(); | ||
final MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder(); | ||
if (mapperService == null) { | ||
codecs.put(DEFAULT_CODEC, new Lucene95Codec()); | ||
|
@@ -75,6 +81,14 @@ public CodecService(@Nullable MapperService mapperService, Logger logger) { | |
this.codecs = codecs.immutableMap(); | ||
} | ||
|
||
public void loadMap() { | ||
versionStringMap.put(Version.fromString("3.0.0"), "Lucene95"); | ||
versionStringMap.put(Version.fromString("2.8.0"), "Lucene95"); | ||
versionStringMap.put(Version.fromString("2.7.1"), "Lucene95"); | ||
versionStringMap.put(Version.fromString("2.7.0"), "Lucene95"); | ||
Comment on lines
+85
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
opensearchVersionToLuceneCodec = Collections.unmodifiableMap(new HashMap<>(versionStringMap)); | ||
} | ||
|
||
public Codec codec(String name) { | ||
Codec codec = codecs.get(name); | ||
if (codec == null) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,13 @@ | |
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||
import org.apache.lucene.store.AlreadyClosedException; | ||
import org.opensearch.action.support.ChannelActionListener; | ||
import org.opensearch.cluster.ClusterChangedEvent; | ||
import org.opensearch.cluster.ClusterStateListener; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.cluster.node.DiscoveryNode; | ||
import org.opensearch.cluster.node.DiscoveryNodes; | ||
import org.opensearch.cluster.routing.ShardRouting; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.Nullable; | ||
|
@@ -37,7 +39,9 @@ | |
import org.opensearch.transport.TransportService; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
|
@@ -170,6 +174,33 @@ public void clusterChanged(ClusterChangedEvent event) { | |
} | ||
} | ||
} | ||
if (event.clusterUpgraded()) { | ||
List<IndexShard> indexShardList = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: final ? |
||
DiscoveryNodes nodes = event.state().nodes(); | ||
for (IndexService indexService : indicesService) { | ||
if (indexService.getIndexSettings().isSegRepEnabled() && (indexService.getIndexSettings().getNumberOfReplicas() > 0)) { | ||
for (IndexShard indexShard : indexService) { | ||
try { | ||
if (indexShard.routingEntry().primary() | ||
&& (indexShard.getEngine().config().getClusterMinVersion() != nodes.getMaxNodeVersion())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
indexShardList.add(indexShard); | ||
} | ||
} catch (AlreadyClosedException e) { | ||
logger.warn("Index shard [{}] engine is already closed.", indexShard.shardId()); | ||
} | ||
} | ||
} | ||
} | ||
try { | ||
if (indexShardList.isEmpty() == false) { | ||
for (IndexShard indexShard : indexShardList) { | ||
indexShard.resetEngine(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Engine reset is not required when there is no codec change. This change will unnecessarily impact end users post upgrade (delay operations) when it is not really needed. |
||
} | ||
} | ||
} catch (Exception e) { | ||
logger.error("Received unexpected exception: [{}]", e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ | |||||||||||||||||||
import org.apache.logging.log4j.Logger; | ||||||||||||||||||||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||||||||||||||||||||
import org.opensearch.BaseExceptionsHelper; | ||||||||||||||||||||
import org.opensearch.Version; | ||||||||||||||||||||
import org.opensearch.action.ActionListener; | ||||||||||||||||||||
import org.opensearch.cluster.routing.ShardRouting; | ||||||||||||||||||||
import org.opensearch.common.Nullable; | ||||||||||||||||||||
|
@@ -227,6 +228,19 @@ public synchronized void onNewCheckpoint(final ReplicationCheckpoint receivedChe | |||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
final Thread thread = Thread.currentThread(); | ||||||||||||||||||||
Version localNodeVersion = Version.CURRENT; | ||||||||||||||||||||
// if replica's OS version is not on or after primary version, then can ignore checkpoint | ||||||||||||||||||||
if (localNodeVersion.onOrAfter(receivedCheckpoint.getMinVersion()) == false) { | ||||||||||||||||||||
logger.trace( | ||||||||||||||||||||
() -> new ParameterizedMessage( | ||||||||||||||||||||
"Ignoring checkpoint, shard not started {} {}\n Shard does not support the received lucene codec version {}", | ||||||||||||||||||||
receivedCheckpoint, | ||||||||||||||||||||
replicaShard.state(), | ||||||||||||||||||||
receivedCheckpoint.getCodec() | ||||||||||||||||||||
Comment on lines
+235
to
+239
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
) | ||||||||||||||||||||
); | ||||||||||||||||||||
return; | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+231
to
+243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check should go inside |
||||||||||||||||||||
if (replicaShard.shouldProcessCheckpoint(receivedCheckpoint)) { | ||||||||||||||||||||
startReplication(replicaShard, new SegmentReplicationListener() { | ||||||||||||||||||||
@Override | ||||||||||||||||||||
|
@@ -435,7 +449,7 @@ public void onReplicationDone(SegmentReplicationState state) { | |||||||||||||||||||
try { | ||||||||||||||||||||
// Promote engine type for primary target | ||||||||||||||||||||
if (indexShard.recoveryState().getPrimary() == true) { | ||||||||||||||||||||
indexShard.resetToWriteableEngine(); | ||||||||||||||||||||
indexShard.resetEngine(); | ||||||||||||||||||||
} | ||||||||||||||||||||
channel.sendResponse(TransportResponse.Empty.INSTANCE); | ||||||||||||||||||||
} catch (InterruptedException | TimeoutException | IOException e) { | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to something better maybe
hasMixedVersionNodes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using this method to check that cluster upgrade has been completed - it checks if it used to have mixed version nodes and current state does not.
hasMixedVersionNodes
might be misleading in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clusterUpgraded
is equivalent to NOThasMixedVersionNodes
.