0

我正在使用 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为什么还要找档案呢?

这可能与我获得最后一个索引的方式有关吗?

谢谢

4

2 回答 2

0

你能用上一个版本重新测试吗?我添加了以下测试用例,它通过了。

参见:RollingChronicleQueueTest

@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));
}
于 2016-12-23T17:43:16.140 回答
0

也许这都是关于日计数器变量的,我的意思是当您添加一些元素时,代码可以将其计算为日周期并将日期更改为后一天。您是否尝试多次添加元素?如果你做了发生了什么?

于 2016-12-23T11:31:08.183 回答