Separate translog from index deletion conditions (#52556)
Separates the translog from the index deletion conditions (allowing the translog to be cleaned up more eagerly), and avoids taking the write lock on the translog if no clean-up is actually necessary.
This commit is contained in:
parent
db6b9c21c7
commit
82ab1bc1ff
|
@ -585,8 +585,8 @@ public class InternalEngine extends Engine {
|
||||||
private void revisitIndexDeletionPolicyOnTranslogSynced() throws IOException {
|
private void revisitIndexDeletionPolicyOnTranslogSynced() throws IOException {
|
||||||
if (combinedDeletionPolicy.hasUnreferencedCommits()) {
|
if (combinedDeletionPolicy.hasUnreferencedCommits()) {
|
||||||
indexWriter.deleteUnusedFiles();
|
indexWriter.deleteUnusedFiles();
|
||||||
translog.trimUnreferencedReaders();
|
|
||||||
}
|
}
|
||||||
|
translog.trimUnreferencedReaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1646,23 +1646,25 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
||||||
* required generation
|
* required generation
|
||||||
*/
|
*/
|
||||||
public void trimUnreferencedReaders() throws IOException {
|
public void trimUnreferencedReaders() throws IOException {
|
||||||
// move most of the data to disk to reduce the time the lock is held
|
// first check under read lock if any readers can be trimmed
|
||||||
|
try (ReleasableLock ignored = readLock.acquire()) {
|
||||||
|
if (closed.get()) {
|
||||||
|
// we're shutdown potentially on some tragic event, don't delete anything
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (getMinReferencedGen() == getMinFileGeneration()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// move most of the data to disk to reduce the time the write lock is held
|
||||||
sync();
|
sync();
|
||||||
try (ReleasableLock ignored = writeLock.acquire()) {
|
try (ReleasableLock ignored = writeLock.acquire()) {
|
||||||
if (closed.get()) {
|
if (closed.get()) {
|
||||||
// we're shutdown potentially on some tragic event, don't delete anything
|
// we're shutdown potentially on some tragic event, don't delete anything
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long minReferencedGen = Math.min(deletionPolicy.minTranslogGenRequired(readers, current),
|
final long minReferencedGen = getMinReferencedGen();
|
||||||
minGenerationForSeqNo(deletionPolicy.getLocalCheckpointOfSafeCommit() + 1, current, readers));
|
|
||||||
assert minReferencedGen >= getMinFileGeneration() :
|
|
||||||
"deletion policy requires a minReferenceGen of [" + minReferencedGen + "] but the lowest gen available is ["
|
|
||||||
+ getMinFileGeneration() + "]";
|
|
||||||
assert minReferencedGen <= currentFileGeneration() :
|
|
||||||
"deletion policy requires a minReferenceGen of [" + minReferencedGen + "] which is higher than the current generation ["
|
|
||||||
+ currentFileGeneration() + "]";
|
|
||||||
|
|
||||||
|
|
||||||
for (Iterator<TranslogReader> iterator = readers.iterator(); iterator.hasNext(); ) {
|
for (Iterator<TranslogReader> iterator = readers.iterator(); iterator.hasNext(); ) {
|
||||||
TranslogReader reader = iterator.next();
|
TranslogReader reader = iterator.next();
|
||||||
if (reader.getGeneration() >= minReferencedGen) {
|
if (reader.getGeneration() >= minReferencedGen) {
|
||||||
|
@ -1689,6 +1691,20 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long getMinReferencedGen() throws IOException {
|
||||||
|
assert readLock.isHeldByCurrentThread() || writeLock.isHeldByCurrentThread();
|
||||||
|
long minReferencedGen = Math.min(
|
||||||
|
deletionPolicy.minTranslogGenRequired(readers, current),
|
||||||
|
minGenerationForSeqNo(deletionPolicy.getLocalCheckpointOfSafeCommit() + 1, current, readers));
|
||||||
|
assert minReferencedGen >= getMinFileGeneration() :
|
||||||
|
"deletion policy requires a minReferenceGen of [" + minReferencedGen + "] but the lowest gen available is ["
|
||||||
|
+ getMinFileGeneration() + "]";
|
||||||
|
assert minReferencedGen <= currentFileGeneration() :
|
||||||
|
"deletion policy requires a minReferenceGen of [" + minReferencedGen + "] which is higher than the current generation ["
|
||||||
|
+ currentFileGeneration() + "]";
|
||||||
|
return minReferencedGen;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deletes all files associated with a reader. package-private to be able to simulate node failures at this point
|
* deletes all files associated with a reader. package-private to be able to simulate node failures at this point
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue