我使用的是Chronicle v4.5.15。我创建了一个方法来告诉我队列中元素的数量:
public long getQueueSize() {
long index = getQueueIndex(); // I store the index in a persistent map so this method simply retrieves the current index from the map.
ExcerptTailer tailer = queue.createTailer();
long lastIndex = tailer.toEnd().index(); // Get the last index in our queue.
long count = queue.countExcerpts(queueIndex, lastIndex);
return count
}我连夜运行了一个测试,我的组件有一个为12月22日编写的cq4队列文件。这是一个每日的周期。我今天尝试向队列中添加一些元素,但出现了抛出'IllegalStateException: 'file not found' for the upperCycle, file ../path_to_queue/20161314.cq4的异常。
堆栈跟踪:
Caused by java.lang.IllegalStateException: java.lang.IllegalStateException: 'file not found' for the upperCycle, file=/var/tmp/app/20161224.cq4
at net.openhft.chronicle.queue.impl.single.SingleChronicleQueue.countExcertps(SingleChronicleQueue.java:359(
at ...既然今天是12月23日,为什么编年史要在未来寻找文件呢?
会不会与我获取最后一个索引的方式有关?
谢谢
发布于 2016-12-24 01:43:16
你能用最新的版本重新测试一下吗--我已经添加了下面的测试用例,它通过了。
@Test
public void testCountExcerptsWhenTheCycleIsRolled() throws Exception {
final AtomicLong time = new AtomicLong();
final SingleChronicleQueue q = binary(getTmpDir())
.timeProvider(time::get)
.rollCycle(TEST_SECONDLY)
.build();
final ExcerptAppender appender = q.acquireAppender();
time.set(0);
appender.writeText("1. some text");
long start = appender.lastIndexAppended();
appender.writeText("2. some more text");
time.set(1000);
appender.writeText("3. some text - first cycle");
time.set(2000);
time.set(3000); // large gap to miss a cycle file
time.set(4000);
appender.writeText("4. some text - second cycle");
appender.writeText("some more text");
long end = appender.lastIndexAppended();
Assert.assertEquals(4, q.countExcerpts(start, end));
}https://stackoverflow.com/questions/41299998
复制相似问题