We ran into the following problem in a project that's under development, and I'm not sure if it's an NDatabase bug or something we're doing wrong.
We're using the following process on application startup:
- Defragment the database. Load the newly-defragmented database.
- Check each index we need (db.IndexManagerFor<T>().ExistIndex).
- If it does not exist, create the index (AddUniqueIndex).
- If it does exist, rebuild it (RebuildIndex)
One of our developers' databases started crashing on startup. It contained no data at the time, but had been used before.
When I checked the database, I found ExistIndex was returning false in step 2, but AddUniqueIndex in step 3 was causing a StackOverflowException trying to write the new index.
If I called db.QueryAndExecute<object>(), all the ClassInfoIndex objects still existed. Deleting these objects fixed the problem and allowed me to re-create the indexes.
Class names haven't changed. We have added a few new properties but (since it's still in the early stages of development) haven't defined any of these changes with RefactorManager.
Do you know why an index would become "orphaned" from its class info? Is there a way we can avoid this case or (worst case scenario) detect it and delete any indexes like this?