DeletedTerms#clear should reset ByteBlockPool (#12630)

This commit is contained in:
gf2121 2023-10-10 00:42:17 -05:00 committed by GitHub
parent 33a3af4260
commit e20e245f47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -230,6 +230,7 @@ class BufferedUpdates implements Accountable {
}
void clear() {
pool.reset(false, false);
bytesUsed.addAndGet(-bytesUsed.get());
deleteTerms.clear();
termsSize = 0;
@ -280,10 +281,23 @@ class BufferedUpdates implements Accountable {
}
}
/** Visible for testing. */
ByteBlockPool getPool() {
return pool;
}
@Override
public long ramBytesUsed() {
return bytesUsed.get();
}
/** Used for {@link BufferedUpdates#VERBOSE_DELETES}. */
@Override
public String toString() {
return keySet().stream()
.map(t -> t + "=" + get(t))
.collect(Collectors.joining(", ", "{", "}"));
}
}
private static class BytesRefIntMap {

View File

@ -61,10 +61,10 @@ public class TestBufferedUpdates extends LuceneTestCase {
public void testDeletedTerms() {
int iters = atLeast(10);
String[] fields = new String[] {"a", "b", "c"};
BufferedUpdates.DeletedTerms actual = new BufferedUpdates.DeletedTerms();
for (int iter = 0; iter < iters; iter++) {
Map<Term, Integer> expected = new HashMap<>();
BufferedUpdates.DeletedTerms actual = new BufferedUpdates.DeletedTerms();
assertTrue(actual.isEmpty());
int termCount = atLeast(5000);
@ -95,6 +95,11 @@ public class TestBufferedUpdates extends LuceneTestCase {
}));
assertEquals(expectedSorted, actualSorted);
actual.clear();
assertEquals(0, actual.size());
assertEquals(0, actual.ramBytesUsed());
assertNull(actual.getPool().buffer);
}
}
}