java 重新打开历史记录队列会导致异常

jgovgodb  于 12个月前  发布在  Java
关注(0)|答案(1)|浏览(136)

我使用ChronicleQueue.close()和强制运行GarbageCollector来确保旧的cq文件被我的进程释放:

var oldQueue = queue;
  this.queue = SingleChronicleQueueBuilder.binary(logDir)
            .rollCycle(RollCycles.DAILY)
            .build();
  // make sure all appenders are update
  logHandlerSet.forEach(logHandler -> logHandler.updateAppender(queue));
  oldQueue.close();
   ... after some delay ...
    LOGGER.debug("Running gc");
    System.gc();
    LOGGER.debug("gc done");

字符串
我也对finalizer做了同样的操作。然而,当finalizer运行时,我得到了这个异常:

Dec 27 03:31:11 r-114 r[3810067]: 03:31:11.992 [Finalizer] WARN  n.o.c.b.i.ChunkedMappedBytes [on:50] -
Dec 27 03:31:11 r-114 r[3810067]: net.openhft.chronicle.core.io.ClosedIllegalStateException: net.openhft.chronicle.bytes.internal.ChunkedMappedFile released
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.VanillaReferenceCounted.newReleasedClosedIllegalStateException(VanillaReferenceCounted.java:249)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.VanillaReferenceCounted.release(VanillaReferenceCounted.java:142)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.AbstractReferenceCounted.release(AbstractReferenceCounted.java:195)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.AbstractCloseableReferenceCounted.release(AbstractCloseableReferenceCounted.java:97)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.bytes.internal.CommonMappedBytes.performRelease(CommonMappedBytes.java:232)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.AbstractReferenceCounted.inThreadPerformRelease(AbstractReferenceCounted.java:147)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.VanillaReferenceCounted.callOnRelease(VanillaReferenceCounted.java:160)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.VanillaReferenceCounted.release(VanillaReferenceCounted.java:148)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.AbstractReferenceCounted.release(AbstractReferenceCounted.java:195)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.bytes.internal.CommonMappedBytes.release(CommonMappedBytes.java:412)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.queue.impl.single.StoreTailer$StoreTailerContext.wire(StoreTailer.java:1454)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.queue.impl.single.StoreTailer.performClose(StoreTailer.java:156)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.AbstractCloseable.callPerformClose(AbstractCloseable.java:327)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.AbstractCloseable.close(AbstractCloseable.java:205)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.internal.CloseableUtils.closeQuietly(CloseableUtils.java:323)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.internal.CloseableUtils.closeQuietly(CloseableUtils.java:286)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.Closeable.closeQuietly(Closeable.java:73)
Dec 27 03:31:11 r-114 r[3810067]: #011at java.base/java.lang.Iterable.forEach(Iterable.java:75)
Dec 27 03:31:11 r-114 r[3810067]: #011at java.base/java.util.Collections$SetFromMap.forEach(Collections.java:5700)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.queue.impl.single.SingleChronicleQueue.performClose(SingleChronicleQueue.java:729)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.AbstractCloseable.callPerformClose(AbstractCloseable.java:327)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.AbstractCloseable.close(AbstractCloseable.java:205)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.core.io.AbstractCloseable.warnAndCloseIfNotClosed(AbstractCloseable.java:309)
Dec 27 03:31:11 r-114 r[3810067]: #011at net.openhft.chronicle.queue.impl.single.SingleChronicleQueue.finalize(SingleChronicleQueue.java:754)
Dec 27 03:31:11 r-114 r[3810067]: #011at java.base/java.lang.System$2.invokeFinalize(System.java:2297)
Dec 27 03:31:11 r-114 r[3810067]: #011at java.base/java.lang.ref.Finalizer.runFinalizer(Finalizer.java:88)
Dec 27 03:31:11 r-114 r[3810067]: #011at java.base/java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:173)


这种情况发生了几百次,我在Chronicle Queue 5.23.37和5.25ea3中遇到过。我做错了什么吗?有没有更好的方法来释放CQ文件?

zwghvu4y

zwghvu4y1#

我发现了我的问题:我创建了一个没有关闭的ExcerptTailer。将其 Package 在try-with-resources中解决了这个问题。

相关问题