h.b.furuseth@usit.uio.no wrote:
- Add field MDB_dbx.md_dbiseq = DBI usage sequence number,
incremented when dbi_open creates (not reuses) a DBI and in dbi_close. Copy it to a new malloced array txn->mt_dbiseqs[] in write txns, verify it in at least commit and drop. This means close()-open(same DB) will also be caught, which seems a good thing since with (4) it will work unreliably: Only if open() reuses the same DBI for the same DB.
This is now fixed in mdb.master, using basically this approach. There is a master array of DBI sequence numbers in the environment and another array in each write transaction. It is verified anywhere the dbx->md_name would get used. The sequence number is incremented in dbi_open and when a handle is closed.
Note - it is only checked in write txns, and only a few places (drop, commit, cursor_touch, page_search) ever check. There is a new error code MDB_BAD_DBI as well.