NO-JIRA: Fixing the testsuite on Page.finalize()

This commit is contained in:
Clebert Suconic 2017-10-06 16:53:55 -04:00
parent e1a87ac830
commit 30ba65a082
5 changed files with 57 additions and 27 deletions

View File

@ -281,10 +281,18 @@ public class JDBCSequentialFile implements SequentialFile {
return readPosition;
}
@Override
public void close() throws Exception {
close(true);
}
@Override
public void close(boolean waitOnSync) throws Exception {
isOpen.set(false);
sync();
if (waitOnSync) {
sync();
}
fileFactory.sequentialFileClosed(this);
}

View File

@ -97,6 +97,14 @@ public interface SequentialFile {
void close() throws Exception;
/** When closing a file from a finalize block, you cant wait on syncs or anything like that.
* otherwise the VM may hung. Especially on the testsuite. */
default void close(boolean waitSync) throws Exception {
// by default most implementations are just using the regular close..
// if the close needs sync, please use this parameter or fianlizations may get stuck
close();
}
void sync() throws IOException;
long size() throws Exception;

View File

@ -97,41 +97,50 @@ public class AIOSequentialFile extends AbstractSequentialFile {
return new AIOSequentialFile(aioFactory, -1, -1, getFile().getParentFile(), getFile().getName(), null);
}
@Override
public synchronized void close() throws IOException, InterruptedException, ActiveMQException {
public void close() throws IOException, InterruptedException, ActiveMQException {
close(true);
}
@Override
public synchronized void close(boolean waitSync) throws IOException, InterruptedException, ActiveMQException {
if (!opened) {
return;
}
super.close();
final String fileName = this.getFileName();
try {
int waitCount = 0;
while (!pendingCallbacks.await(10, TimeUnit.SECONDS)) {
waitCount++;
if (waitCount == 1) {
final ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
for (ThreadInfo threadInfo : threads) {
ActiveMQJournalLogger.LOGGER.warn(threadInfo.toString());
if (waitSync) {
final String fileName = this.getFileName();
try {
int waitCount = 0;
while (!pendingCallbacks.await(10, TimeUnit.SECONDS)) {
waitCount++;
if (waitCount == 1) {
final ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
for (ThreadInfo threadInfo : threads) {
ActiveMQJournalLogger.LOGGER.warn(threadInfo.toString());
}
factory.onIOError(new IOException("Timeout on close"), "Timeout on close", this);
}
factory.onIOError(new IOException("Timeout on close"), "Timeout on close", this);
ActiveMQJournalLogger.LOGGER.warn("waiting pending callbacks on " + fileName + " from " + (waitCount * 10) + " seconds!");
}
ActiveMQJournalLogger.LOGGER.warn("waiting pending callbacks on " + fileName + " from " + (waitCount * 10) + " seconds!");
} catch (InterruptedException e) {
ActiveMQJournalLogger.LOGGER.warn("interrupted while waiting pending callbacks on " + fileName, e);
throw e;
} finally {
opened = false;
timedBuffer = null;
aioFile.close();
aioFile = null;
}
} catch (InterruptedException e) {
ActiveMQJournalLogger.LOGGER.warn("interrupted while waiting pending callbacks on " + fileName, e);
throw e;
} finally {
opened = false;
timedBuffer = null;
aioFile.close();
aioFile = null;
}
}

View File

@ -334,6 +334,11 @@ final class MappedSequentialFile implements SequentialFile {
@Override
public void close() {
close(true);
}
@Override
public void close(boolean waitOnSync) {
if (this.mappedFile != null) {
this.mappedFile.close();
this.mappedFile = null;

View File

@ -349,7 +349,7 @@ public final class Page implements Comparable<Page> {
protected void finalize() {
try {
if (file != null && file.isOpen()) {
file.close();
file.close(false);
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.pageFinaliseError(e);