gpt4 book ai didi

编年史队列大小确定

转载 作者:行者123 更新时间:2023-12-05 06:30:38 25 4
gpt4 key购买 nike

如果我们需要将编年史队列的总大小限制为 1GB 或 10GB。最好的方法是什么?

我们将缓冲区存储为字节,因此我试图通过对缓冲区大小求和来计算总大小,但看起来没有简单的方法将其与队列的实际大小相关联。一种方法是每 5 分钟左右使用文件实用程序计算总目录大小,但如果间隔中有大量数据并且可能溢出,这将容易出错

最佳答案

您必须将每个 cq4 文件的大小相加

writePosition 以字节为单位为您提供每个 cq4 文件的长度

public class Example {

public static void main(String[] args) throws FileNotFoundException {
SingleChronicleQueue q = SingleChronicleQueueBuilder.builder().path("tmp").build();

ExcerptAppender appender = q.createAppender();

try (DocumentContext dc = appender.writingDocument()) {
long l = dc.wire().bytes().writePosition();
dc.wire().write().text("lastx");
}

DumpQueueMain.dump(q.fileAbsolutePath());

}
}

输出如下

--- !!meta-data #binary
header: !SCQStore {
writePosition: [
131328,
564049465049088
],
indexing: !SCQSIndexing {
indexCount: !short 8192,
indexSpacing: 64,
index2Index: 184,
lastIndex: 64
}
}

# position: 184, header: -1
--- !!meta-data #binary
index2index: [
# length: 8192, used: 1
65760 # truncated trailing zeros
]
# position: 65760, header: -1
--- !!meta-data #binary
index: [
# length: 8192, used: 1
131328 # truncated trailing zeros
]
# position: 131328, header: 0
--- !!data #binary
"": lastx

...
# 83754737 bytes remaining

--- !!meta-data #binary
header: !STStore {
wireType: !WireType BINARY_LIGHT,
recovery: !TimedStoreRecovery {
timeStamp: 0
},
metadata: !SCQMeta {
roll: !SCQSRoll { length: !int 86400000, format: yyyyMMdd, epoch: 0 },
deltaCheckpointInterval: 64,
sourceId: 0
}
}

# position: 225, header: 0
--- !!data #binary
listing.highestCycle: 17780

# position: 264, header: 1
--- !!data #binary
listing.lowestCycle: 17780

# position: 304, header: 2
--- !!data #binary
listing.modCount: 1

# position: 336, header: 3
--- !!data #binary
chronicle.write.lock: -9223372036854775808

# position: 376, header: 4
--- !!data #binary
chronicle.lastIndexReplicated: -1

# position: 432, header: 5
--- !!data #binary
chronicle.lastAcknowledgedIndexReplicated: -1

...
# 65044 bytes remaining

当.cq4文件的长度定义为

writePosition: [
131328,
....
],

换句话说,131328 字节

关于编年史队列大小确定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52193744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com