vmware / splinterdb

High Performance Embedded Key-Value Store
https://splinterdb.org
Apache License 2.0
673 stars 56 forks source link

A segmentation fault during closing database #581

Closed deukyeon closed 1 year ago

deukyeon commented 1 year ago

I got a segmentation fault error in trunk_unmount(). https://github.com/vmware/splinterdb/blob/6a2348c0eb9887cdafee3dad674a96e41edddb28/src/trunk.c#L7725-L7746 This function calls trunk_prepare_for_shutdown(spl);, followed by trunk_set_super_block(spl, FALSE, TRUE, FALSE);.

In the trunk_prepare_for_shutdown(), spl->log is freed and then becomes NULL by platform_free(). https://github.com/vmware/splinterdb/blob/6a2348c0eb9887cdafee3dad674a96e41edddb28/src/trunk.c#L7646 However, the spl->log is referenced by trunk_set_super_block(), which causes a segmentation fault. https://github.com/vmware/splinterdb/blob/6a2348c0eb9887cdafee3dad674a96e41edddb28/src/trunk.c#L934

It seems that the trunk_set_super_block() function is based on the assumption, "init means destroying the current super block". So, it is used in both creating and destroying the database. One way to resolve this is setting the addresses of log and log metadata to 0 if spl->log is NULL, which can indicate that the database is being unmounted.