|
36 | 36 | import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse; |
37 | 37 | import org.elasticsearch.action.admin.indices.flush.FlushResponse; |
38 | 38 | import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; |
| 39 | +import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; |
39 | 40 | import org.elasticsearch.action.admin.indices.stats.ShardStats; |
40 | 41 | import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; |
41 | 42 | import org.elasticsearch.action.index.IndexRequestBuilder; |
|
66 | 67 | import org.elasticsearch.common.unit.TimeValue; |
67 | 68 | import org.elasticsearch.common.xcontent.XContentFactory; |
68 | 69 | import org.elasticsearch.common.xcontent.XContentType; |
| 70 | +import org.elasticsearch.index.Index; |
69 | 71 | import org.elasticsearch.index.IndexService; |
70 | 72 | import org.elasticsearch.index.engine.Engine; |
| 73 | +import org.elasticsearch.index.shard.IndexShard; |
71 | 74 | import org.elasticsearch.index.shard.ShardId; |
72 | 75 | import org.elasticsearch.indices.IndicesService; |
73 | 76 | import org.elasticsearch.indices.InvalidIndexNameException; |
|
104 | 107 | import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; |
105 | 108 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; |
106 | 109 | import static org.elasticsearch.index.IndexSettings.INDEX_REFRESH_INTERVAL_SETTING; |
107 | | -import static org.elasticsearch.index.query.QueryBuilders.boolQuery; |
108 | 110 | import static org.elasticsearch.index.query.QueryBuilders.matchQuery; |
| 111 | +import static org.elasticsearch.index.shard.IndexShardTests.getEngineFromShard; |
109 | 112 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
110 | 113 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAliasesExist; |
111 | 114 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAliasesMissing; |
@@ -2896,6 +2899,73 @@ public void testGetSnapshotsFromIndexBlobOnly() throws Exception { |
2896 | 2899 | } |
2897 | 2900 | } |
2898 | 2901 |
|
| 2902 | + public void testSnapshottingWithMissingSequenceNumbers() { |
| 2903 | + final String repositoryName = "test-repo"; |
| 2904 | + final String snapshotName = "test-snap"; |
| 2905 | + final String indexName = "test-idx"; |
| 2906 | + final Client client = client(); |
| 2907 | + final Path repo = randomRepoPath(); |
| 2908 | + |
| 2909 | + logger.info("--> creating repository at {}", repo.toAbsolutePath()); |
| 2910 | + assertAcked(client.admin().cluster().preparePutRepository(repositoryName) |
| 2911 | + .setType("fs").setSettings(Settings.builder() |
| 2912 | + .put("location", repo) |
| 2913 | + .put("compress", false) |
| 2914 | + .put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES))); |
| 2915 | + logger.info("--> creating an index and indexing documents"); |
| 2916 | + final String dataNode = internalCluster().getDataNodeInstance(ClusterService.class).localNode().getName(); |
| 2917 | + final Settings settings = |
| 2918 | + Settings |
| 2919 | + .builder() |
| 2920 | + .put("index.number_of_shards", 1) |
| 2921 | + .put("index.number_of_replicas", 0) |
| 2922 | + .put("index.routing.allocation.include._name", dataNode) |
| 2923 | + .build(); |
| 2924 | + createIndex(indexName, settings); |
| 2925 | + ensureGreen(); |
| 2926 | + for (int i = 0; i < 5; i++) { |
| 2927 | + index(indexName, "doc", Integer.toString(i), "foo", "bar" + i); |
| 2928 | + } |
| 2929 | + |
| 2930 | + final Index index = resolveIndex(indexName); |
| 2931 | + final IndexShard primary = internalCluster().getInstance(IndicesService.class, dataNode).getShardOrNull(new ShardId(index, 0)); |
| 2932 | + // create a gap in the sequence numbers |
| 2933 | + getEngineFromShard(primary).seqNoService().generateSeqNo(); |
| 2934 | + |
| 2935 | + for (int i = 5; i < 10; i++) { |
| 2936 | + index(indexName, "doc", Integer.toString(i), "foo", "bar" + i); |
| 2937 | + } |
| 2938 | + |
| 2939 | + refresh(); |
| 2940 | + |
| 2941 | + logger.info("--> snapshot"); |
| 2942 | + CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repositoryName, snapshotName) |
| 2943 | + .setWaitForCompletion(true).setIndices(indexName).get(); |
| 2944 | + assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); |
| 2945 | + assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), |
| 2946 | + equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); |
| 2947 | + |
| 2948 | + logger.info("--> delete indices"); |
| 2949 | + assertAcked(client.admin().indices().prepareDelete(indexName)); |
| 2950 | + |
| 2951 | + logger.info("--> restore all indices from the snapshot"); |
| 2952 | + RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap") |
| 2953 | + .setWaitForCompletion(true).execute().actionGet(); |
| 2954 | + assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); |
| 2955 | + |
| 2956 | + logger.info("--> indexing some more"); |
| 2957 | + for (int i = 10; i < 15; i++) { |
| 2958 | + index(indexName, "doc", Integer.toString(i), "foo", "bar" + i); |
| 2959 | + } |
| 2960 | + |
| 2961 | + IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().get(); |
| 2962 | + ShardStats shardStats = stats.getShards()[0]; |
| 2963 | + assertTrue(shardStats.getShardRouting().primary()); |
| 2964 | + assertThat(shardStats.getSeqNoStats().getLocalCheckpoint(), equalTo(15L)); // 15 indexed docs and one "missing" op. |
| 2965 | + assertThat(shardStats.getSeqNoStats().getGlobalCheckpoint(), equalTo(15L)); |
| 2966 | + assertThat(shardStats.getSeqNoStats().getMaxSeqNo(), equalTo(15L)); |
| 2967 | + } |
| 2968 | + |
2899 | 2969 | private void verifySnapshotInfo(final GetSnapshotsResponse response, final Map<String, List<String>> indicesPerSnapshot) { |
2900 | 2970 | for (SnapshotInfo snapshotInfo : response.getSnapshots()) { |
2901 | 2971 | final List<String> expected = snapshotInfo.indices(); |
|
0 commit comments