Add a reference count to LSM chunks

The reference count is used to ensure that chunks can't be freed while worker threads are accessing them.

References issue #693