views:

163

answers:

1

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?

A: 

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.

milosz