Explorar el Código

Fix illegal access on PIT creation for frozen index (#73517)

Closes #73514
David Turner hace 4 años
padre
commit
2b521e3d9e

+ 5 - 1
server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java

@@ -76,7 +76,7 @@ public class ReadOnlyEngine extends Engine {
     final boolean lazilyLoadSoftDeletes;
 
     protected volatile TranslogStats translogStats;
-    protected final String commitId;
+    private final String commitId;
 
     /**
      * Creates a new ReadOnlyEngine. This ctor can also be used to open a read-only engine on top of an already opened
@@ -583,4 +583,8 @@ public class ReadOnlyEngine extends Engine {
             }
         };
     }
+
+    public final String getCommitId() {
+        return commitId;
+    }
 }

+ 1 - 1
x-pack/plugin/core/src/main/java/org/elasticsearch/index/engine/FrozenEngine.java

@@ -203,7 +203,7 @@ public final class FrozenEngine extends ReadOnlyEngine {
 
             @Override
             public String getSearcherId() {
-                return commitId;
+                return getCommitId();
             }
         };
     }

+ 1 - 1
x-pack/plugin/searchable-snapshots/qa/rest/build.gradle

@@ -10,7 +10,7 @@ final File repoDir = file("$buildDir/testclusters/repo")
 
 restResources {
   restApi {
-    include 'indices', 'search', 'bulk', 'snapshot', 'nodes', '_common', 'searchable_snapshots', 'cluster'
+    include 'indices', 'search', 'bulk', 'snapshot', 'nodes', '_common', 'searchable_snapshots', 'cluster', 'open_point_in_time', 'close_point_in_time'
   }
 }
 

+ 155 - 0
x-pack/plugin/searchable-snapshots/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/pit.yml

@@ -0,0 +1,155 @@
+---
+setup:
+
+  - do:
+      indices.create:
+        index: docs
+        body:
+          settings:
+            number_of_shards:   1
+            number_of_replicas: 0
+
+  - do:
+      bulk:
+        body:
+          - index:
+              _index: docs
+              _id:    1
+          - field: foo
+          - index:
+              _index: docs
+              _id:    2
+          - field: bar
+          - index:
+              _index: docs
+              _id:    3
+          - field: baz
+
+  - do:
+      snapshot.create_repository:
+        repository: repository-fs
+        body:
+          type: fs
+          settings:
+            location: "repository-fs"
+
+  # Remove the snapshot if a previous test failed to delete it.
+  # Useful for third party tests that runs the test against a real external service.
+  - do:
+      snapshot.delete:
+        repository: repository-fs
+        snapshot: snapshot
+        ignore: 404
+
+  - do:
+      snapshot.create:
+        repository: repository-fs
+        snapshot: snapshot
+        wait_for_completion: true
+
+  - do:
+      indices.delete:
+        index: docs
+---
+teardown:
+
+  - do:
+      snapshot.delete:
+        repository: repository-fs
+        snapshot: snapshot
+        ignore: 404
+
+  - do:
+      snapshot.delete_repository:
+        repository: repository-fs
+
+---
+"Tests searches vs default-storage index":
+  - do:
+      searchable_snapshots.mount:
+        repository: repository-fs
+        snapshot: snapshot
+        wait_for_completion: true
+        body:
+          index: docs
+          renamed_index: docs-default-storage
+
+  - match: { snapshot.snapshot: snapshot }
+  - match: { snapshot.shards.failed: 0 }
+  - match: { snapshot.shards.successful: 1 }
+
+  - do:
+      search:
+        index: docs-default-storage
+        body:
+          query:
+            match_all: {}
+
+  - match: { hits.total.value: 3 }
+
+  - do:
+      open_point_in_time:
+        index: docs-default-storage
+        keep_alive: 5m
+  - set: {id: point_in_time_id}
+
+  - do:
+      search:
+        body:
+          pit:
+            id: "$point_in_time_id"
+            keep_alive: 1m
+
+  - match: { hits.total.value: 3 }
+
+  - do:
+      close_point_in_time:
+        body:
+          id: "$point_in_time_id"
+
+
+---
+"Tests searches vs shared-cache index":
+  - do:
+      searchable_snapshots.mount:
+        repository: repository-fs
+        snapshot: snapshot
+        wait_for_completion: true
+        storage: shared_cache
+        body:
+          index: docs
+          renamed_index: docs-shared-cache
+
+  - match: { snapshot.snapshot: snapshot }
+  - match: { snapshot.shards.failed: 0 }
+  - match: { snapshot.shards.successful: 1 }
+
+  - do:
+      search:
+        index: docs-shared-cache
+        body:
+          query:
+            match_all: {}
+
+  - match: { hits.total.value: 3 }
+
+  - do:
+      open_point_in_time:
+        index: docs-shared-cache
+        keep_alive: 5m
+  - set: {id: point_in_time_id}
+
+  - do:
+      search:
+        body:
+          pit:
+            id: "$point_in_time_id"
+            keep_alive: 1m
+
+  - match: { hits.total.value: 3 }
+
+  - do:
+      close_point_in_time:
+        body:
+          id: "$point_in_time_id"
+