-
Notifications
You must be signed in to change notification settings - Fork 24.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
Introduce soft-deletes retention policy based on global checkpoint #30335
Changes from 1 commit
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 |
---|---|---|
|
@@ -123,6 +123,7 @@ | |
import org.elasticsearch.index.translog.Translog; | ||
import org.elasticsearch.index.translog.TranslogConfig; | ||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; | ||
import org.elasticsearch.test.IndexSettingsModule; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
|
||
|
@@ -177,6 +178,7 @@ | |
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.hasKey; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.isIn; | ||
import static org.hamcrest.Matchers.lessThanOrEqualTo; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
@@ -250,8 +252,9 @@ public void testVersionMapAfterAutoIDDocument() throws IOException { | |
} | ||
|
||
public void testSegments() throws Exception { | ||
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED); | ||
try (Store store = createStore(); | ||
InternalEngine engine = createEngine(defaultSettings, store, createTempDir(), NoMergePolicy.INSTANCE)) { | ||
InternalEngine engine = createEngine(config(defaultSettings, store, createTempDir(), NoMergePolicy.INSTANCE, null, null, globalCheckpoint::get))) { | ||
List<Segment> segments = engine.segments(false); | ||
assertThat(segments.isEmpty(), equalTo(true)); | ||
assertThat(engine.segmentsStats(false).getCount(), equalTo(0L)); | ||
|
@@ -323,6 +326,8 @@ public void testSegments() throws Exception { | |
|
||
|
||
engine.delete(new Engine.Delete("test", "1", newUid(doc), primaryTerm.get())); | ||
globalCheckpoint.set(engine.getLocalCheckpointTracker().getCheckpoint()); | ||
engine.getTranslog().sync(); | ||
engine.refresh("test"); | ||
|
||
segments = engine.segments(false); | ||
|
@@ -1278,9 +1283,13 @@ public void testVersioningNewIndex() throws IOException { | |
assertThat(indexResult.getVersion(), equalTo(1L)); | ||
} | ||
|
||
public void testForceMerge() throws IOException { | ||
public void testForceMergeWithoutSoftDeletes() throws IOException { | ||
Settings settings = Settings.builder() | ||
.put(defaultSettings.getSettings()) | ||
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false).build(); | ||
IndexMetaData indexMetaData = IndexMetaData.builder(defaultSettings.getIndexMetaData()).settings(settings).build(); | ||
try (Store store = createStore(); | ||
Engine engine = createEngine(config(defaultSettings, store, createTempDir(), | ||
Engine engine = createEngine(config(IndexSettingsModule.newIndexSettings(indexMetaData), store, createTempDir(), | ||
new LogByteSizeMergePolicy(), null))) { // use log MP here we test some behavior in ESMP | ||
int numDocs = randomIntBetween(10, 100); | ||
for (int i = 0; i < numDocs; i++) { | ||
|
@@ -1321,6 +1330,62 @@ public void testForceMerge() throws IOException { | |
} | ||
} | ||
|
||
public void testForceMergeWithSoftDeletesRetention() throws Exception { | ||
final long retainedExtraOps = randomLongBetween(0, 10); | ||
Settings.Builder settings = Settings.builder() | ||
.put(defaultSettings.getSettings()) | ||
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true) | ||
.put(IndexSettings.INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING.getKey(), retainedExtraOps); | ||
final IndexMetaData indexMetaData = IndexMetaData.builder(defaultSettings.getIndexMetaData()).settings(settings).build(); | ||
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexMetaData); | ||
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED); | ||
final MapperService mapperService = createMapperService("test"); | ||
final Set<String> liveDocs = new HashSet<>(); | ||
try (Store store = createStore(); | ||
Engine engine = createEngine(config(indexSettings, store, createTempDir(), newMergePolicy(), null, null, globalCheckpoint::get))) { | ||
int numDocs = scaledRandomIntBetween(10, 100); | ||
for (int i = 0; i < numDocs; i++) { | ||
ParsedDocument doc = testParsedDocument(Integer.toString(i), null, testDocument(), B_1, null); | ||
engine.index(indexForDoc(doc)); | ||
liveDocs.add(doc.id()); | ||
} | ||
for (int i = 0; i < numDocs; i++) { | ||
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. question - do we also want to override documents, rather than just deleting them? 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.
+1. I added updates. |
||
if (randomBoolean()) { | ||
ParsedDocument doc = testParsedDocument(Integer.toString(i), null, testDocument(), B_1, null); | ||
engine.delete(new Engine.Delete(doc.type(), doc.id(), newUid(doc.id()), primaryTerm.get())); | ||
liveDocs.remove(doc.id()); | ||
} | ||
} | ||
long localCheckpoint = engine.getLocalCheckpointTracker().getCheckpoint(); | ||
globalCheckpoint.set(randomLongBetween(0, localCheckpoint)); | ||
engine.getTranslog().sync(); | ||
engine.forceMerge(true, 1, false, false, false); | ||
assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, mapperService); | ||
Map<Long, Translog.Operation> ops = readAllOperationsInLucene(engine, mapperService) | ||
.stream().collect(Collectors.toMap(Translog.Operation::seqNo, Function.identity())); | ||
for (long seqno = 0; seqno <= localCheckpoint; seqno++) { | ||
long keptIndex = globalCheckpoint.get() + 1 - retainedExtraOps; | ||
String msg = "seq# [" + seqno + "], global checkpoint [" + globalCheckpoint + "], retained-ops [" + retainedExtraOps + "]"; | ||
if (seqno < keptIndex) { | ||
Translog.Operation op = ops.get(seqno); | ||
if (op != null) { | ||
assertThat(op, instanceOf(Translog.Index.class)); | ||
assertThat(msg, ((Translog.Index) op).id(), isIn(liveDocs)); | ||
} | ||
} else { | ||
assertThat(msg, ops.get(seqno), notNullValue()); | ||
} | ||
} | ||
settings.put(IndexSettings.INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING.getKey(), 0); | ||
indexSettings.updateIndexMetaData(IndexMetaData.builder(defaultSettings.getIndexMetaData()).settings(settings).build()); | ||
globalCheckpoint.set(localCheckpoint); | ||
engine.getTranslog().sync(); | ||
engine.forceMerge(true, 1, false, false, false); | ||
assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, mapperService); | ||
assertThat(readAllOperationsInLucene(engine, mapperService), hasSize(liveDocs.size())); | ||
} | ||
} | ||
|
||
public void testForceMergeAndClose() throws IOException, InterruptedException { | ||
int numIters = randomIntBetween(2, 10); | ||
for (int j = 0; j < numIters; j++) { | ||
|
@@ -2468,14 +2533,16 @@ public void testSkipTranslogReplay() throws IOException { | |
Engine.IndexResult indexResult = engine.index(firstIndexRequest); | ||
assertThat(indexResult.getVersion(), equalTo(1L)); | ||
} | ||
EngineConfig config = engine.config(); | ||
assertVisibleCount(engine, numDocs); | ||
engine.close(); | ||
trimUnsafeCommits(engine.config()); | ||
engine = new InternalEngine(engine.config()); | ||
engine.skipTranslogRecovery(); | ||
try (Engine.Searcher searcher = engine.acquireSearcher("test")) { | ||
TopDocs topDocs = searcher.searcher().search(new MatchAllDocsQuery(), randomIntBetween(numDocs, numDocs + 10)); | ||
assertThat(topDocs.totalHits, equalTo(0L)); | ||
trimUnsafeCommits(config); | ||
try (InternalEngine engine = new InternalEngine(config)) { | ||
engine.skipTranslogRecovery(); | ||
try (Engine.Searcher searcher = engine.acquireSearcher("test")) { | ||
TopDocs topDocs = searcher.searcher().search(new MatchAllDocsQuery(), randomIntBetween(numDocs, numDocs + 10)); | ||
assertThat(topDocs.totalHits, equalTo(0L)); | ||
} | ||
} | ||
} | ||
|
||
|
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.
nit: java docs please - something like "documents that are soft deleted and match this query should be retained and not cleaned up by merges"