Commit d605f812 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

refs #5730, make cachefiles list a doubly linked list for more efficient close, helps shutdown

git-svn-id: file:///svn/toku/tokudb@50881 c7de825b-a66e-492c-adef-691d508d4ae1
parent 5a953880
...@@ -94,6 +94,7 @@ class pair_list; ...@@ -94,6 +94,7 @@ class pair_list;
// //
struct cachefile { struct cachefile {
CACHEFILE next; CACHEFILE next;
CACHEFILE prev;
bool for_checkpoint; //True if part of the in-progress checkpoint bool for_checkpoint; //True if part of the in-progress checkpoint
// If set and the cachefile closes, the file will be removed. // If set and the cachefile closes, the file will be removed.
......
...@@ -353,6 +353,10 @@ int toku_cachetable_openfd_with_filenum (CACHEFILE *cfptr, CACHETABLE ct, int fd ...@@ -353,6 +353,10 @@ int toku_cachetable_openfd_with_filenum (CACHEFILE *cfptr, CACHETABLE ct, int fd
newcf->filenum = filenum; newcf->filenum = filenum;
cachefile_init_filenum(newcf, fd, fname_in_env, fileid); cachefile_init_filenum(newcf, fd, fname_in_env, fileid);
newcf->next = ct->cf_list.m_head; 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; ct->cf_list.m_head = newcf;
bjm_init(&newcf->bjm); bjm_init(&newcf->bjm);
...@@ -425,17 +429,16 @@ static void remove_cf_from_cachefiles_list (CACHEFILE cf) { ...@@ -425,17 +429,16 @@ static void remove_cf_from_cachefiles_list (CACHEFILE cf) {
CACHETABLE ct = cf->cachetable; CACHETABLE ct = cf->cachetable;
ct->cf_list.write_lock(); ct->cf_list.write_lock();
invariant(ct->cf_list.m_head != NULL); invariant(ct->cf_list.m_head != NULL);
if (cf->next) {
cf->next->prev = cf->prev;
}
if (cf->prev) {
cf->prev->next = cf->next;
}
if (cf == ct->cf_list.m_head) { if (cf == ct->cf_list.m_head) {
invariant(cf->prev == NULL);
ct->cf_list.m_head = cf->next; ct->cf_list.m_head = cf->next;
} }
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;
}
ct->cf_list.write_unlock(); ct->cf_list.write_unlock();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment