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

Make searchable snapshot indexes read-only but allow deletion #4764

Merged
Next Next commit
Make the index restored by remote snapshot as read only but deletable
Signed-off-by: Vishal Sarda <vsarda@amazon.com>
  • Loading branch information
Vishalks committed Oct 13, 2022
commit 5c7b8d63d575ca54648f7dcdc5a9178c574d5f41
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,16 @@ public boolean isThrottled() {

@Override
public IndexResult index(Index index) {
assert false : "this should not be called";
throw new UnsupportedOperationException("indexing is not supported on a read-only engine");
}

@Override
public DeleteResult delete(Delete delete) {
assert false : "this should not be called";
throw new UnsupportedOperationException("deletes are not supported on a read-only engine");
}

@Override
public NoOpResult noOp(NoOp noOp) {
assert false : "this should not be called";
throw new UnsupportedOperationException("no-ops are not supported on a read-only engine");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ private static IndexMetadata addSnapshotToIndexSettings(IndexMetadata metadata,
.put(IndexSettings.SEARCHABLE_SNAPSHOT_ID_UUID.getKey(), snapshot.getSnapshotId().getUUID())
.put(IndexSettings.SEARCHABLE_SNAPSHOT_ID_NAME.getKey(), snapshot.getSnapshotId().getName())
.put(IndexSettings.SEARCHABLE_SNAPSHOT_INDEX_ID.getKey(), indexId.getId())
.put(IndexMetadata.APIBlock.READ_ONLY_ALLOW_DELETE.settingName(), true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

With DiskThresholdDecider be able to revert this?

.put(metadata.getSettings())
.build();
return IndexMetadata.builder(metadata).settings(newSettings).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.opensearch.Version;
import org.opensearch.common.bytes.BytesArray;
import org.opensearch.common.lucene.index.OpenSearchDirectoryReader;
Expand Down Expand Up @@ -218,9 +217,7 @@ public void testReadOnly() throws IOException {
EngineConfig config = config(defaultSettings, store, createTempDir(), newMergePolicy(), null, null, globalCheckpoint::get);
store.createEmpty(Version.CURRENT.luceneVersion);
try (ReadOnlyEngine readOnlyEngine = new ReadOnlyEngine(config, null, new TranslogStats(), true, Function.identity(), true)) {
Class<? extends Throwable> expectedException = LuceneTestCase.TEST_ASSERTS_ENABLED
? AssertionError.class
: UnsupportedOperationException.class;
Class<? extends Throwable> expectedException = UnsupportedOperationException.class;
expectThrows(expectedException, () -> readOnlyEngine.index(null));
expectThrows(expectedException, () -> readOnlyEngine.delete(null));
expectThrows(expectedException, () -> readOnlyEngine.noOp(null));
Expand Down