diff --git a/ft/cachetable-internal.h b/ft/cachetable-internal.h index 71df2b71455..21f215b29c7 100644 --- a/ft/cachetable-internal.h +++ b/ft/cachetable-internal.h @@ -94,6 +94,7 @@ class pair_list; // struct cachefile { CACHEFILE next; + CACHEFILE prev; bool for_checkpoint; //True if part of the in-progress checkpoint // If set and the cachefile closes, the file will be removed. diff --git a/ft/cachetable.cc b/ft/cachetable.cc index 0d72becfb51..760fa1c78e8 100644 --- a/ft/cachetable.cc +++ b/ft/cachetable.cc @@ -353,6 +353,10 @@ int toku_cachetable_openfd_with_filenum (CACHEFILE *cfptr, CACHETABLE ct, int fd newcf->filenum = filenum; cachefile_init_filenum(newcf, fd, fname_in_env, fileid); newcf->next = ct->cf_list.m_head; + newcf->prev = NULL; + if (ct->cf_list.m_head) { + ct->cf_list.m_head->prev = newcf; + } ct->cf_list.m_head = newcf; bjm_init(&newcf->bjm); @@ -425,16 +429,15 @@ static void remove_cf_from_cachefiles_list (CACHEFILE cf) { CACHETABLE ct = cf->cachetable; ct->cf_list.write_lock(); invariant(ct->cf_list.m_head != NULL); - if (cf == ct->cf_list.m_head) { - ct->cf_list.m_head = cf->next; + if (cf->next) { + cf->next->prev = cf->prev; } - else { - CACHEFILE curr_cf = ct->cf_list.m_head; - while (curr_cf->next != cf) { - curr_cf = curr_cf->next; - } - // at this point, curr_cf->next is pointing to cf - curr_cf->next = cf->next; + if (cf->prev) { + cf->prev->next = cf->next; + } + if (cf == ct->cf_list.m_head) { + invariant(cf->prev == NULL); + ct->cf_list.m_head = cf->next; } ct->cf_list.write_unlock(); }