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

时间:2010-01-16 21:51:38

标签: java sequence berkeley-db berkeley-db-je

我有一个由Id (int)Url (String)组成的班级文档。我希望在Id上有一个主索引,在Url上有二级索引。我还想有一个Id自动增量序列。所以我创建了一个SecondaryDatabase,然后创建了一个Sequence。在序列初始化期间,我得到一个例外:

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方法时,它尝试转换为对象的字节似乎是随机的。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

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