diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2014-08-07 19:12:45 +0200 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2014-08-07 19:12:45 +0200 |
commit | f835588cc2e32da97269cc58e97ee77b5927498a (patch) | |
tree | 8e5c53593e7e3a9db0892afefb118fd0d581e23a /storage/tokudb/ft-index/ft/cachetable.cc | |
parent | 0219ac1e98cc53250a8e165c4b37e83529932256 (diff) | |
parent | b81b6d3f836feb682b963c9489f00ca1ee6a6a95 (diff) | |
download | mariadb-git-f835588cc2e32da97269cc58e97ee77b5927498a.tar.gz |
- Commiting merge files
Diffstat (limited to 'storage/tokudb/ft-index/ft/cachetable.cc')
-rw-r--r-- | storage/tokudb/ft-index/ft/cachetable.cc | 156 |
1 files changed, 69 insertions, 87 deletions
diff --git a/storage/tokudb/ft-index/ft/cachetable.cc b/storage/tokudb/ft-index/ft/cachetable.cc index fb427c5349b..d7c734cc5fd 100644 --- a/storage/tokudb/ft-index/ft/cachetable.cc +++ b/storage/tokudb/ft-index/ft/cachetable.cc @@ -370,7 +370,7 @@ toku_cachetable_set_env_dir(CACHETABLE ct, const char *env_dir) { // What cachefile goes with particular iname (iname relative to env)? // The transaction that is adding the reference might not have a reference -// to the brt, therefore the cachefile might be closing. +// to the ft, therefore the cachefile might be closing. // If closing, we want to return that it is not there, but must wait till after // the close has finished. // Once the close has finished, there must not be a cachefile with that name @@ -380,7 +380,7 @@ int toku_cachefile_of_iname_in_env (CACHETABLE ct, const char *iname_in_env, CAC } // What cachefile goes with particular fd? -// This function can only be called if the brt is still open, so file must +// This function can only be called if the ft is still open, so file must // still be open int toku_cachefile_of_filenum (CACHETABLE ct, FILENUM filenum, CACHEFILE *cf) { return ct->cf_list.cachefile_of_filenum(filenum, cf); @@ -564,10 +564,10 @@ void toku_cachefile_close(CACHEFILE *cfp, bool oplsn_valid, LSN oplsn) { // that do not persist across opens/closes bjm_destroy(cf->bjm); cf->bjm = NULL; - cf->filenum = FILENUM_NONE; // remove the cf from the list of active cachefiles ct->cf_list.remove_cf(cf); + cf->filenum = FILENUM_NONE; // Unlink the file if the bit was set if (cf->unlink_on_close) { @@ -642,7 +642,7 @@ static void cachetable_free_pair(PAIR p) { cachetable_evictions++; PAIR_ATTR new_attr = p->attr; // Note that flush_callback is called with write_me false, so the only purpose of this - // call is to tell the brt layer to evict the node (keep_me is false). + // call is to tell the ft layer to evict the node (keep_me is false). // Also, because we have already removed the PAIR from the cachetable in // cachetable_remove_pair, we cannot pass in p->cachefile and p->cachefile->fd // for the first two parameters, as these may be invalid (#5171), so, we @@ -1302,8 +1302,6 @@ void toku_cachetable_pf_pinned_pair( pair_unlock(p); } - -// NOW A TEST ONLY FUNCTION!!! int toku_cachetable_get_and_pin ( CACHEFILE cachefile, CACHEKEY key, @@ -1573,7 +1571,7 @@ exit: return try_again; } -int toku_cachetable_get_and_pin_with_dep_pairs_batched ( +int toku_cachetable_get_and_pin_with_dep_pairs ( CACHEFILE cachefile, CACHEKEY key, uint32_t fullhash, @@ -1766,43 +1764,6 @@ got_value: return 0; } -int toku_cachetable_get_and_pin_with_dep_pairs ( - CACHEFILE cachefile, - CACHEKEY key, - uint32_t fullhash, - void**value, - long *sizep, - CACHETABLE_WRITE_CALLBACK write_callback, - CACHETABLE_FETCH_CALLBACK fetch_callback, - CACHETABLE_PARTIAL_FETCH_REQUIRED_CALLBACK pf_req_callback, - CACHETABLE_PARTIAL_FETCH_CALLBACK pf_callback, - pair_lock_type lock_type, - void* read_extraargs, // parameter for fetch_callback, pf_req_callback, and pf_callback - uint32_t num_dependent_pairs, // number of dependent pairs that we may need to checkpoint - PAIR* dependent_pairs, - enum cachetable_dirty* dependent_dirty // array stating dirty/cleanness of dependent pairs - ) -// See cachetable.h -{ - int r = toku_cachetable_get_and_pin_with_dep_pairs_batched( - cachefile, - key, - fullhash, - value, - sizep, - write_callback, - fetch_callback, - pf_req_callback, - pf_callback, - lock_type, - read_extraargs, - num_dependent_pairs, - dependent_pairs, - dependent_dirty - ); - return r; -} - // Lookup a key in the cachetable. If it is found and it is not being written, then // acquire a read lock on the pair, update the LRU list, and return sucess. // @@ -2048,7 +2009,7 @@ maybe_pin_pair( return retval; } -int toku_cachetable_get_and_pin_nonblocking_batched( +int toku_cachetable_get_and_pin_nonblocking( CACHEFILE cf, CACHEKEY key, uint32_t fullhash, @@ -2200,40 +2161,6 @@ try_again: abort(); } -int toku_cachetable_get_and_pin_nonblocking ( - CACHEFILE cf, - CACHEKEY key, - uint32_t fullhash, - void**value, - long* sizep, - CACHETABLE_WRITE_CALLBACK write_callback, - CACHETABLE_FETCH_CALLBACK fetch_callback, - CACHETABLE_PARTIAL_FETCH_REQUIRED_CALLBACK pf_req_callback, - CACHETABLE_PARTIAL_FETCH_CALLBACK pf_callback, - pair_lock_type lock_type, - void *read_extraargs, - UNLOCKERS unlockers - ) -// See cachetable.h. -{ - int r = 0; - r = toku_cachetable_get_and_pin_nonblocking_batched( - cf, - key, - fullhash, - value, - sizep, - write_callback, - fetch_callback, - pf_req_callback, - pf_callback, - lock_type, - read_extraargs, - unlockers - ); - return r; -} - struct cachefile_prefetch_args { PAIR p; CACHETABLE_FETCH_CALLBACK fetch_callback; @@ -4750,9 +4677,13 @@ void cachefile_list::init() { m_next_filenum_to_use.fileid = 0; m_next_hash_id_to_use = 0; toku_pthread_rwlock_init(&m_lock, NULL); + m_active_filenum.create(); + m_active_fileid.create(); } void cachefile_list::destroy() { + m_active_filenum.destroy(); + m_active_fileid.destroy(); toku_pthread_rwlock_destroy(&m_lock); } @@ -4804,6 +4735,21 @@ int cachefile_list::cachefile_of_filenum(FILENUM filenum, CACHEFILE *cf) { return r; } +static int cachefile_find_by_filenum(const CACHEFILE &a_cf, const FILENUM &b) { + const FILENUM a = a_cf->filenum; + if (a.fileid < b.fileid) { + return -1; + } else if (a.fileid == b.fileid) { + return 0; + } else { + return 1; + } +} + +static int cachefile_find_by_fileid(const CACHEFILE &a_cf, const struct fileid &b) { + return toku_fileid_cmp(a_cf->fileid, b); +} + void cachefile_list::add_cf_unlocked(CACHEFILE cf) { invariant(cf->next == NULL); invariant(cf->prev == NULL); @@ -4813,6 +4759,12 @@ void cachefile_list::add_cf_unlocked(CACHEFILE cf) { m_active_head->prev = cf; } m_active_head = cf; + + int r; + r = m_active_filenum.insert<FILENUM, cachefile_find_by_filenum>(cf, cf->filenum, nullptr); + assert_zero(r); + r = m_active_fileid.insert<struct fileid, cachefile_find_by_fileid>(cf, cf->fileid, nullptr); + assert_zero(r); } void cachefile_list::add_stale_cf(CACHEFILE cf) { @@ -4847,6 +4799,19 @@ void cachefile_list::remove_cf(CACHEFILE cf) { } cf->prev = NULL; cf->next = NULL; + + uint32_t idx; + int r; + r = m_active_filenum.find_zero<FILENUM, cachefile_find_by_filenum>(cf->filenum, nullptr, &idx); + assert_zero(r); + r = m_active_filenum.delete_at(idx); + assert_zero(r); + + r = m_active_fileid.find_zero<struct fileid, cachefile_find_by_fileid>(cf->fileid, nullptr, &idx); + assert_zero(r); + r = m_active_fileid.delete_at(idx); + assert_zero(r); + write_unlock(); } @@ -4872,18 +4837,23 @@ void cachefile_list::remove_stale_cf_unlocked(CACHEFILE cf) { } FILENUM cachefile_list::reserve_filenum() { - CACHEFILE extant; - FILENUM filenum; // taking a write lock because we are modifying next_filenum_to_use write_lock(); -try_again: - for (extant = m_active_head; extant; extant = extant->next) { - if (m_next_filenum_to_use.fileid==extant->filenum.fileid) { + while (1) { + int r = m_active_filenum.find_zero<FILENUM, cachefile_find_by_filenum>(m_next_filenum_to_use, nullptr, nullptr); + if (r == 0) { m_next_filenum_to_use.fileid++; - goto try_again; + continue; } + assert(r == DB_NOTFOUND); + break; + } + FILENUM filenum = m_next_filenum_to_use; +#if TOKU_DEBUG_PARANOID + for (CACHEFILE extant = m_active_head; extant; extant = extant->next) { + assert(filenum.fileid != extant->filenum.fileid); } - filenum = m_next_filenum_to_use; +#endif m_next_filenum_to_use.fileid++; write_unlock(); return filenum; @@ -4916,7 +4886,15 @@ exit: } CACHEFILE cachefile_list::find_cachefile_unlocked(struct fileid* fileid) { - return find_cachefile_in_list_unlocked(m_active_head, fileid); + CACHEFILE cf = nullptr; + int r = m_active_fileid.find_zero<struct fileid, cachefile_find_by_fileid>(*fileid, &cf, nullptr); + if (r == 0) { + assert(!cf->unlink_on_close); + } +#if TOKU_DEBUG_PARANOID + assert(cf == find_cachefile_in_list_unlocked(m_active_head, fileid)); +#endif + return cf; } CACHEFILE cachefile_list::find_stale_cachefile_unlocked(struct fileid* fileid) { @@ -4924,9 +4902,13 @@ CACHEFILE cachefile_list::find_stale_cachefile_unlocked(struct fileid* fileid) { } void cachefile_list::verify_unused_filenum(FILENUM filenum) { + int r = m_active_filenum.find_zero<FILENUM, cachefile_find_by_filenum>(filenum, nullptr, nullptr); + assert(r == DB_NOTFOUND); +#if TOKU_DEBUG_PARANOID for (CACHEFILE extant = m_active_head; extant; extant = extant->next) { invariant(extant->filenum.fileid != filenum.fileid); } +#endif } // returns true if some eviction ran, false otherwise |