-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Never leave stale delete tombstones in version map #29619
Changes from 2 commits
e50300a
e69b6df
d869bd0
64f415c
75595f2
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 |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class LiveVersionMapTests extends ESTestCase { | ||
|
||
|
@@ -396,6 +397,32 @@ public void testPruneTombstonesWhileLocked() throws InterruptedException, IOExce | |
assertEquals(0, map.getAllTombstones().size()); | ||
} | ||
|
||
public void testNeverLeaveStaleDeleteTombstone() throws Exception { | ||
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. Maybe name the test: "testRandomlyDeletingAndIndexingDoc"? it tests much more, which is good. |
||
LiveVersionMap versionMap = new LiveVersionMap(); | ||
BytesRef uid = uid("1"); | ||
long versions = between(10, 1000); | ||
for (long version = 1; version <= versions; version++) { | ||
if (randomBoolean()) { | ||
versionMap.beforeRefresh(); | ||
versionMap.afterRefresh(randomBoolean()); | ||
} | ||
if (randomBoolean()) { | ||
versionMap.enforceSafeAccess(); | ||
} | ||
try (Releasable ignore = versionMap.acquireLock(uid)) { | ||
if (randomBoolean()) { | ||
versionMap.putDeleteUnderLock(uid, new DeleteVersionValue(version, 1, 1, 1)); | ||
} else { | ||
versionMap.maybePutIndexUnderLock(uid, new IndexVersionValue(randomTranslogLocation(), version, 1, 1)); | ||
} | ||
VersionValue storedValue = versionMap.getUnderLock(uid); | ||
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. can we also check that this return value correlates with what we expect? i.e., if the doc was just deleted it should be deleted, if it was indexed it should never be marked as deleted? (and found if we're in safe mode). Also can you check this property holds also not directly after indexing/deleting? (i.e., after refresh, enforceSafe access etc). Said differently - maybe also randomly do nothing under lock? |
||
if (storedValue != null) { | ||
assertThat("Keeping a stale version value", storedValue.version, equalTo(version)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
IndexVersionValue randomIndexVersionValue() { | ||
return new IndexVersionValue(randomTranslogLocation(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()); | ||
} | ||
|
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.
can you explain why we need concurrency here? (i.e., why a single threaded test is not enough)
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.
A single threaded test is good enough ;)