Fsync translog without writeLock before rolling (#45765)

Today, when rolling a new translog generation, we block all write
threads until a new generation is created. This choice is perfectly 
fine except in a highly concurrent environment with the translog 
async setting. We can reduce the blocking time by pre-sync the 
current generation without writeLock before rolling. The new step 
would fsync most of the data of the current generation without 
blocking write threads.

Close #45371
This commit is contained in:
dengweisysu 2019-08-23 04:16:13 +08:00 committed by Nhat Nguyen
parent 8e3c54fff7
commit 72c6302d12
1 changed files with 3 additions and 0 deletions

View File

@ -1649,6 +1649,9 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
* @throws IOException if an I/O exception occurred during any file operations * @throws IOException if an I/O exception occurred during any file operations
*/ */
public void rollGeneration() throws IOException { public void rollGeneration() throws IOException {
// make sure we move most of the data to disk outside of the writeLock
// in order to reduce the time the lock is held since it's blocking all threads
sync();
try (Releasable ignored = writeLock.acquire()) { try (Releasable ignored = writeLock.acquire()) {
try { try {
final TranslogReader reader = current.closeIntoReader(); final TranslogReader reader = current.closeIntoReader();