Berkeley DB JE Base API 辅助数据库和序列出现问题

发布于 2024-08-18 06:45:17 字数 1726 浏览 11 评论 0原文

我有一个由 Id (int)Url (String) 组成的类 Document。我希望在 Id 上有一个主索引,在 Url 上有一个辅助索引。我还想要一个 Id 自动递增的序列。因此,我创建了一个辅助数据库,然后创建了一个序列。在序列初始化期间,我遇到异常:

Exception in thread "main" java.lang.IllegalArgumentException
 at com.sleepycat.util.UtfOps.getCharLength(UtfOps.java:137)
 at com.sleepycat.util.UtfOps.bytesToString(UtfOps.java:259)
 at com.sleepycat.bind.tuple.TupleInput.readString(TupleInput.java:152)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.MyDocumentBiding.entryToObject(MyDocumentBiding.java:12)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.MyDocumentBiding.entryToObject(MyDocumentBiding.java:1)
 at com.sleepycat.bind.tuple.TupleBinding.entryToObject(TupleBinding.java:76)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.UrlKeyCreator.createSecondaryKey(UrlKeyCreator.java:20)
 at com.sleepycat.je.SecondaryDatabase.updateSecondary(SecondaryDatabase.java:835)
 at com.sleepycat.je.SecondaryTrigger.databaseUpdated(SecondaryTrigger.java:42)
 at com.sleepycat.je.Database.notifyTriggers(Database.java:2004)
 at com.sleepycat.je.Cursor.putNotify(Cursor.java:1692)
 at com.sleepycat.je.Cursor.putInternal(Cursor.java:1616)
 at com.sleepycat.je.Cursor.putNoOverwrite(Cursor.java:663)
 at com.sleepycat.je.Sequence.<init>(Sequence.java:188)
 at com.sleepycat.je.Database.openSequence(Database.java:546)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.MyFullTextSearchEngine.init(MyFullTextSearchEngine.java:131)
 at pl.edu.mimuw.zbd.berkeley.zadanie.testy.MyFullTextSearchEngineTest.main(MyFullTextSearchEngineTest.java:18)

似乎在序列初始化期间,辅助数据库被迫更新。当我调试 MyDocumentBiding 的 entryToObject 方法时,它尝试转换为对象的字节似乎是随机的。

我做错了什么?

I have a class Document which consists of Id (int) and Url (String). I would like to have a primary index on Id and secondary index on Url. I would also like to have a sequence for Id auto-incrementation. So I create a SecondaryDatabase and then I create a Sequence. During initialisation of the Sequence I get an exception:

Exception in thread "main" java.lang.IllegalArgumentException
 at com.sleepycat.util.UtfOps.getCharLength(UtfOps.java:137)
 at com.sleepycat.util.UtfOps.bytesToString(UtfOps.java:259)
 at com.sleepycat.bind.tuple.TupleInput.readString(TupleInput.java:152)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.MyDocumentBiding.entryToObject(MyDocumentBiding.java:12)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.MyDocumentBiding.entryToObject(MyDocumentBiding.java:1)
 at com.sleepycat.bind.tuple.TupleBinding.entryToObject(TupleBinding.java:76)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.UrlKeyCreator.createSecondaryKey(UrlKeyCreator.java:20)
 at com.sleepycat.je.SecondaryDatabase.updateSecondary(SecondaryDatabase.java:835)
 at com.sleepycat.je.SecondaryTrigger.databaseUpdated(SecondaryTrigger.java:42)
 at com.sleepycat.je.Database.notifyTriggers(Database.java:2004)
 at com.sleepycat.je.Cursor.putNotify(Cursor.java:1692)
 at com.sleepycat.je.Cursor.putInternal(Cursor.java:1616)
 at com.sleepycat.je.Cursor.putNoOverwrite(Cursor.java:663)
 at com.sleepycat.je.Sequence.<init>(Sequence.java:188)
 at com.sleepycat.je.Database.openSequence(Database.java:546)
 at pl.edu.mimuw.zbd.berkeley.zadanie.rozwiazanie.MyFullTextSearchEngine.init(MyFullTextSearchEngine.java:131)
 at pl.edu.mimuw.zbd.berkeley.zadanie.testy.MyFullTextSearchEngineTest.main(MyFullTextSearchEngineTest.java:18)

It seems that during the initialisation of the sequence the secondary database is forced to update. When I debug the entryToObject method of MyDocumentBiding the bytes that it tries to convert to object seem random.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心意如水 2024-08-25 06:45:17

我发现解决方案是为序列创建一个单独的数据库,或者让 secondaryKeyCreator 检测何时添加序列数据并在这种情况下返回 false。

I found out that the solution is to either create a separate db for the sequence or to make the SecondaryKeyCreator detect when it is adding a sequence data and return false in such situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文