Skip to content
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

Fix translog bwc serialization #36676

Merged
merged 4 commits into from
Dec 19, 2018
Merged

Fix translog bwc serialization #36676

merged 4 commits into from
Dec 19, 2018

Conversation

dnhatn
Copy link
Member

@dnhatn dnhatn commented Dec 15, 2018

@martijnvg found that translog is not serialized correctly while working an upgrade test for CCR. Serializing of a Translog#Index from v7.0.0 to 6.x is broken since #29224 where we removed the _parent field. Our tests do not uncover this issue because NodeVersionAllocationDecider prevents allocating a replica on an old version if the primary is on a new version. However, this issue can happen in the following scenarios:

  1. A replica on 7.0 gets promoted, and there's another replica on 6.x. Primary-replica resync will ship translog operations from 7.0 to 6.x.
  2. A leader cluster is on 7.0, and a follower cluster is on 6.x.
  3. ShardFollowTask is running on 7.0, and follower shard copies are on 6.x.

This change fixes the serialization issue and adds a test for the first scenario. The last two situations should be covered in #36648.

Relates #29224

I marked this non-issue for it is an unreleased bug.

@dnhatn dnhatn added >non-issue v7.0.0 :Distributed Indexing/Engine Anything around managing Lucene and the Translog in an open shard. labels Dec 15, 2018
@dnhatn dnhatn requested review from bleskes and ywelsch December 15, 2018 19:30
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

Copy link
Contributor

@bleskes bleskes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code change LGTM. I'm wondering about the extra complexity of the test.

@@ -275,6 +279,81 @@ public void testUpdateSnapshotStatus() throws Exception {
request.setJsonEntity("{\"indices\": \"" + index + "\"}");
}

public void testResyncFromNewNodeToOldNode() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(why) Isn't this potentially covered but the 3 node rolling upgrade tests where you upgrade one node, then the second and if that has a primary it will promote the first shard which will cause a resync with the replica. If that's true, do we really need this test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote a rolling upgrade test but was unable to make it fail. I'll give it another shot today.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bleskes The reason that the rolling-upgrade did not fail because (1) primary-replica resync only operations after the global checkpoint, (2) we sync the global checkpoint for every 30 seconds. These make the resync a noop.
Since the newly added test is complicated, should we remove it and let the CCR upgrade-tests verify this BWC issue? WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking. I think it's good to have a rolling upgrade test that properly tests all aspects of primary promotions. Maybe we should slow down the GCP sync through a settings (and add concurrent indexing). This may get tricky too but I think we should explore it. @ywelsch any thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing these tests is tricky, and the REST tests might not provide the best place for doing so. I'm not sure if the 30 second global-checkpoint sync is what's making this difficult to test with a rolling-upgrade (we send the updated global checkpoint to the replicas as soon as an indexing operation completes, and don't wait for 30 seconds). I think the difficult bit is rather the need for continuous indexing while the node with the primary is shutting down, so that the resync will actually have something meaningful to sync. There is currently no way to do this using the REST tests (i.e. index stuff while a node is shutting down).

In this particular instance, I wonder if a unit test would suffice, namely one that follows the likes of ClusterSerializationTests.testSnapshotDeletionsInProgressSerialization which serializes a cluster state with a certain stream version, and then decodes again using that same version. This could be done for the translog operations as a minor extension of testTranslogOpSerialization:

diff --git a/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java
index 7e73f9ef517..ac07a226a25 100644
--- a/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java
+++ b/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java
@@ -35,6 +35,7 @@ import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.util.LineFileDocs;
 import org.apache.lucene.util.LuceneTestCase;
 import org.elasticsearch.Assertions;
+import org.elasticsearch.Version;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.elasticsearch.common.Randomness;
 import org.elasticsearch.common.Strings;
@@ -72,6 +73,7 @@ import org.elasticsearch.index.shard.ShardId;
 import org.elasticsearch.index.translog.Translog.Location;
 import org.elasticsearch.test.ESTestCase;
 import org.elasticsearch.test.IndexSettingsModule;
+import org.elasticsearch.test.VersionUtils;
 import org.hamcrest.Matchers;
 import org.junit.After;
 import org.junit.Before;
@@ -2815,8 +2817,11 @@ public class TranslogTests extends ESTestCase {
         Translog.Index index = new Translog.Index(eIndex, eIndexResult);
 
         BytesStreamOutput out = new BytesStreamOutput();
+        Version version = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
+        out.setVersion(version);
         Translog.Operation.writeOperation(out, index);
         StreamInput in = out.bytes().streamInput();
+        in.setVersion(version);
         Translog.Index serializedIndex = (Translog.Index) Translog.Operation.readOperation(in);
         assertEquals(index, serializedIndex);
 
@@ -2826,8 +2831,10 @@ public class TranslogTests extends ESTestCase {
         Translog.Delete delete = new Translog.Delete(eDelete, eDeleteResult);
 
         out = new BytesStreamOutput();
+        out.setVersion(version);
         Translog.Operation.writeOperation(out, delete);
         in = out.bytes().streamInput();
+        in.setVersion(version);
         Translog.Delete serializedDelete = (Translog.Delete) Translog.Operation.readOperation(in);
         assertEquals(delete, serializedDelete);
     }

Combined with the test that Martijn will add for CCR, this will hopefully give us enough coverage.

@dnhatn
Copy link
Member Author

dnhatn commented Dec 17, 2018

@bleskes and @ywelsch I think we should be good with a unit test and the tests that @martijnvg will add for CCR. I replaced the mixed-cluster test with the unit test. Would you please have another look? Thank you!

@dnhatn dnhatn requested a review from bleskes December 17, 2018 20:24
Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dnhatn
Copy link
Member Author

dnhatn commented Dec 19, 2018

Thanks @bleskes and @ywelsch.

@dnhatn dnhatn merged commit b63f9b9 into elastic:master Dec 19, 2018
@dnhatn dnhatn deleted the translog-bwc branch December 19, 2018 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Indexing/Engine Anything around managing Lucene and the Translog in an open shard. >non-issue v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants