Commit cdda8bfa authored by John Esmet's avatar John Esmet Committed by Yoni Fogel

close[t:5109] address some comments from code review concerning the naming of...

close[t:5109] address some comments from code review concerning the naming of functions that remove an ft from memory vs removing a ft from the filesystem.


git-svn-id: file:///svn/toku/tokudb@44741 c7de825b-a66e-492c-adef-691d508d4ae1
parent a9264b96
...@@ -3283,7 +3283,7 @@ ft_handle_open(FT_HANDLE ft_h, const char *fname_in_env, int is_create, int only ...@@ -3283,7 +3283,7 @@ ft_handle_open(FT_HANDLE ft_h, const char *fname_in_env, int is_create, int only
if (!needed) { if (!needed) {
//Close immediately. //Close immediately.
char *error_string = NULL; char *error_string = NULL;
r = toku_remove_ft(ft, &error_string, false, ZERO_LSN); r = toku_ft_evict_from_memory(ft, &error_string, false, ZERO_LSN);
lazy_assert_zero(r); lazy_assert_zero(r);
} }
} }
...@@ -5488,7 +5488,7 @@ int toku_ft_handle_set_panic(FT_HANDLE brt, int panic, char *panic_string) { ...@@ -5488,7 +5488,7 @@ int toku_ft_handle_set_panic(FT_HANDLE brt, int panic, char *panic_string) {
// synchronize with begin checkpoint. // synchronize with begin checkpoint.
// Contract: the iname of the ft should never be reused. // Contract: the iname of the ft should never be reused.
int int
toku_ft_remove_on_commit(FT_HANDLE handle, TOKUTXN txn) { toku_ft_unlink_on_commit(FT_HANDLE handle, TOKUTXN txn) {
int r; int r;
CACHEFILE cf; CACHEFILE cf;
...@@ -5516,7 +5516,7 @@ toku_ft_remove_on_commit(FT_HANDLE handle, TOKUTXN txn) { ...@@ -5516,7 +5516,7 @@ toku_ft_remove_on_commit(FT_HANDLE handle, TOKUTXN txn) {
// close works in toku_cachefile_close(); // close works in toku_cachefile_close();
// Requires: serialized with begin checkpoint // Requires: serialized with begin checkpoint
void void
toku_ft_remove(FT_HANDLE handle) { toku_ft_unlink(FT_HANDLE handle) {
CACHEFILE cf; CACHEFILE cf;
cf = handle->ft->cf; cf = handle->ft->cf;
toku_cachefile_unlink_on_close(cf); toku_cachefile_unlink_on_close(cf);
......
...@@ -544,34 +544,40 @@ toku_ft_note_ft_handle_open(FT ft, FT_HANDLE live) { ...@@ -544,34 +544,40 @@ toku_ft_note_ft_handle_open(FT ft, FT_HANDLE live) {
toku_ft_release_reflock(ft); toku_ft_release_reflock(ft);
} }
bool // the reference count for a ft is the number of txn's that
toku_ft_needed_unlocked(FT h) // touched it plus the number of open handles plus one if
// Effect: Return true iff the reference count is positive. // pinned by a checkpoint.
{ static int
return !toku_list_empty(&h->live_ft_handles) || toku_omt_size(h->txns) != 0 || h->pinned_by_checkpoint; ft_get_reference_count(FT ft) {
}
BOOL
toku_ft_has_one_reference_unlocked(FT ft) {
u_int32_t pinned_by_checkpoint = ft->pinned_by_checkpoint ? 1 : 0; u_int32_t pinned_by_checkpoint = ft->pinned_by_checkpoint ? 1 : 0;
u_int32_t num_txns = toku_omt_size(ft->txns); u_int32_t num_txns = toku_omt_size(ft->txns);
int num_handles = toku_list_num_elements_est(&ft->live_ft_handles); int num_handles = toku_list_num_elements_est(&ft->live_ft_handles);
return ((pinned_by_checkpoint + num_txns + num_handles) == 1); return pinned_by_checkpoint + num_txns + num_handles;
}
// a ft is needed in memory iff its reference count is non-zero
bool
toku_ft_needed_unlocked(FT ft) {
return ft_get_reference_count(ft) != 0;
} }
// get the reference count and return true if it was 1
bool
toku_ft_has_one_reference_unlocked(FT ft) {
return ft_get_reference_count(ft) == 1;
}
// Close brt. If opsln_valid, use given oplsn as lsn in brt header instead of logging // evict a ft from memory by closing its cachefile. any future work
// the close and using the lsn provided by logging the close. (Subject to constraint // will have to read in the ft in a new cachefile and new FT object.
// that if a newer lsn is already in the dictionary, don't overwrite the dictionary.) int toku_ft_evict_from_memory(FT ft, char **error_string, BOOL oplsn_valid, LSN oplsn) {
int toku_remove_ft (FT h, char **error_string, BOOL oplsn_valid, LSN oplsn)
// Requires: we hold the open_close lock (because we are closing) and the multi_operation lock (to prevent checkpoints).
{
int r = 0; int r = 0;
// Must do this work before closing the cf assert(ft->cf);
if (h->cf) { if (error_string) {
if (error_string) assert(*error_string == 0); assert(*error_string == 0);
r = toku_cachefile_close(&h->cf, error_string, oplsn_valid, oplsn); }
if (r==0 && error_string) assert(*error_string == 0); r = toku_cachefile_close(&ft->cf, error_string, oplsn_valid, oplsn);
if (r == 0 && error_string) {
assert(*error_string == 0);
} }
return r; return r;
} }
...@@ -989,13 +995,13 @@ toku_ft_remove_reference(FT ft, bool oplsn_valid, LSN oplsn, remove_ft_ref_callb ...@@ -989,13 +995,13 @@ toku_ft_remove_reference(FT ft, bool oplsn_valid, LSN oplsn, remove_ft_ref_callb
toku_ft_grab_reflock(ft); toku_ft_grab_reflock(ft);
remove_ref(ft, extra); remove_ref(ft, extra);
BOOL needed = toku_ft_needed_unlocked(ft); bool needed = toku_ft_needed_unlocked(ft);
toku_ft_release_reflock(ft); toku_ft_release_reflock(ft);
if (!needed) { if (!needed) {
// close header // close header
char *error_string = NULL; char *error_string = NULL;
int r; int r;
r = toku_remove_ft(ft, &error_string, oplsn_valid, oplsn); r = toku_ft_evict_from_memory(ft, &error_string, oplsn_valid, oplsn);
assert_zero(r); assert_zero(r);
assert(error_string == NULL); assert(error_string == NULL);
} }
......
...@@ -15,13 +15,11 @@ ...@@ -15,13 +15,11 @@
#include "ft-ops.h" #include "ft-ops.h"
#include "compress.h" #include "compress.h"
// remove a ft, transactionless. // unlink a ft from the filesystem, without a txn.
// if the ft is being checkpointed, it will be removed after checkpoint. void toku_ft_unlink(FT_HANDLE handle);
void toku_ft_remove(FT_HANDLE handle);
// remove a ft using the given txn. when the txn commits, the ft is removed. // unlink a ft from the filesystem when the given txn commits.
// if the ft is being checkpointed, it will be removed after checkpoint. int toku_ft_unlink_on_commit(FT_HANDLE handle, TOKUTXN txn) __attribute__((__warn_unused_result__));
int toku_ft_remove_on_commit(FT_HANDLE handle, TOKUTXN txn) __attribute__((__warn_unused_result__));
//Effect: suppresses rollback logs //Effect: suppresses rollback logs
void toku_ft_suppress_rollbacks(FT h, TOKUTXN txn); void toku_ft_suppress_rollbacks(FT h, TOKUTXN txn);
...@@ -42,9 +40,12 @@ void toku_ft_free (FT h); ...@@ -42,9 +40,12 @@ void toku_ft_free (FT h);
int toku_read_ft_and_store_in_cachefile (FT_HANDLE brt, CACHEFILE cf, LSN max_acceptable_lsn, FT *header, BOOL* was_open); int toku_read_ft_and_store_in_cachefile (FT_HANDLE brt, CACHEFILE cf, LSN max_acceptable_lsn, FT *header, BOOL* was_open);
void toku_ft_note_ft_handle_open(FT ft, FT_HANDLE live); void toku_ft_note_ft_handle_open(FT ft, FT_HANDLE live);
int toku_ft_needed_unlocked(FT h); bool toku_ft_needed_unlocked(FT ft);
BOOL toku_ft_has_one_reference_unlocked(FT ft); bool toku_ft_has_one_reference_unlocked(FT ft);
int toku_remove_ft (FT h, char **error_string, BOOL oplsn_valid, LSN oplsn) __attribute__ ((warn_unused_result));
// evict a ft from memory by closing its cachefile. any future work
// will have to read in the ft in a new cachefile and new FT object.
int toku_ft_evict_from_memory(FT ft, char **error_string, BOOL oplsn_valid, LSN oplsn) __attribute__ ((warn_unused_result));
FT_HANDLE toku_ft_get_only_existing_ft_handle(FT h); FT_HANDLE toku_ft_get_only_existing_ft_handle(FT h);
......
...@@ -876,7 +876,7 @@ static int toku_recover_fdelete (struct logtype_fdelete *l, RECOVER_ENV renv) { ...@@ -876,7 +876,7 @@ static int toku_recover_fdelete (struct logtype_fdelete *l, RECOVER_ENV renv) {
struct file_map_tuple *tuple; struct file_map_tuple *tuple;
r = file_map_find(&renv->fmap, l->filenum, &tuple); r = file_map_find(&renv->fmap, l->filenum, &tuple);
if (r == 0) { if (r == 0) {
r = toku_ft_remove_on_commit(tuple->ft_handle, txn); r = toku_ft_unlink_on_commit(tuple->ft_handle, txn);
} }
return 0; return 0;
} }
......
...@@ -2473,14 +2473,14 @@ toku_env_dbremove(DB_ENV * env, DB_TXN *txn, const char *fname, const char *dbna ...@@ -2473,14 +2473,14 @@ toku_env_dbremove(DB_ENV * env, DB_TXN *txn, const char *fname, const char *dbna
if (toku_db_pre_acquire_table_lock(db, txn) != 0) { if (toku_db_pre_acquire_table_lock(db, txn) != 0) {
r = DB_LOCK_NOTGRANTED; r = DB_LOCK_NOTGRANTED;
} else { } else {
// The ft will be removed when the txn commits // The ft will be unlinked when the txn commits
r = toku_ft_remove_on_commit(db->i->ft_handle, db_txn_struct_i(txn)->tokutxn); r = toku_ft_unlink_on_commit(db->i->ft_handle, db_txn_struct_i(txn)->tokutxn);
assert_zero(r); assert_zero(r);
} }
} }
else { else {
// Remove the ft without a txn // unlink the ft without a txn
toku_ft_remove(db->i->ft_handle); toku_ft_unlink(db->i->ft_handle);
} }
} }
......
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