Add new index to existing databases
518667Mar 21 2011 — edited Mar 22 2011Hello everybody!
Got again some question to the BDB experts here :)
I've got a primary database with keys representing an auto increment integer and values representing serialized Google protocol buffer messages. A secondary key is created from an attribute of the protobuf message. What I want to achieve now is to add additional indices after restarting the database. Let's say at the beginning the protobuf message has three attributes and in future there will be one or more attributes added.
My current tests return at the moment an error (Db::put: DB_SECONDARY_BAD: Secondary index inconsistent with primary). In the first iteration I add some values into the database using only X indices. After stopping I recompile the code and add a new index with an key extractor( the protobuf value already has the new attribute) After restarting the database and adding some new values I got the previous mentioned error. I don't understand why the new index is inconsistent. The primary database has some values and after restarting there is one more index which should be filled with new data. The primary should be updated as usual.
Maybe someone could explain this to me please.
I am configuring the environment with those values:
DB_INIT_TXN|DB_INIT_LOG|DB_INIT_LOCK|DB_CREATE | DB_THREAD | DB_INIT_MPOOL
and
TXN_NO_SYNC, DB_LOG_IN_MEMORY
For the auto increment key of the primary database I am using a DbSequence with DB_SEQ_WRAP and DB_SEQ_INC.
When shuting down the database I am resetting the LSN with lsn_reset() to prevent from errors when restarting the database (logs are kept only in memory)
Thanks in advance.
Martin