Berkeley DB JE Base API 辅助数据库和序列出现问题
我有一个由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现解决方案是为序列创建一个单独的数据库,或者让 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.