ARTEMIS-4773 Performance improvement on page.sync

the sync should be called outside of the lock.
if the file was already closed it should then just be ignored as the data was locked anyway.
This commit is contained in:
Clebert Suconic 2024-05-13 11:57:30 -04:00 committed by clebertsuconic
parent ae5d98337f
commit 22540cc3ab
2 changed files with 22 additions and 4 deletions

View File

@ -16,7 +16,9 @@
*/
package org.apache.activemq.artemis.core.paging.impl;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
@ -196,6 +198,20 @@ public final class Page {
file.sync();
}
public void trySync() throws IOException {
try {
if (file.isOpen()) {
file.sync();
}
} catch (IOException e) {
if (e instanceof ClosedChannelException) {
logger.debug("file.sync on file {} thrown a ClosedChannelException that will just be ignored", file.getFileName());
} else {
throw e;
}
}
}
public boolean isOpen() {
return file != null && file.isOpen();
}

View File

@ -515,16 +515,18 @@ public class PagingStoreImpl implements PagingStore {
@Override
public void ioSync() throws Exception {
if (!fileFactory.supportsIndividualContext()) {
Page page;
lock.readLock().lock();
try {
final Page page = currentPage;
if (page != null) {
page.sync();
}
page = currentPage;
} finally {
lock.readLock().unlock();
}
if (page != null) {
page.trySync();
}
}
}