我正在使用Chronicle Queue 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日,为什么Chronicle将来会寻找档案?
这可能与我获取最后一个索引的方式有关吗?
由于
答案 0 :(得分:0)
也许这一切都与日计数器变量有关,我的意思是当你添加一些元素时,代码可以计算一天的周期,并将日期改为一天。您是否尝试多次添加元素?如果你做了怎么回事?
答案 1 :(得分:0)
你可以用最后一个版本重新测试 - 我已经添加了以下测试用例,该测试用例通过了。
@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));
}