Commit db5c1b9a 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 6713f53d
......@@ -3283,7 +3283,7 @@ exit:
if (!needed) {
//Close immediately.
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);
}
}
......@@ -5488,7 +5488,7 @@ int toku_ft_handle_set_panic(FT_HANDLE brt, int panic, char *panic_string) {
// synchronize with begin checkpoint.
// Contract: the iname of the ft should never be reused.
int
toku_ft_remove_on_commit(FT_HANDLE handle, TOKUTXN txn) {
toku_ft_unlink_on_commit(FT_HANDLE handle, TOKUTXN txn) {
int r;
CACHEFILE cf;
......@@ -5516,7 +5516,7 @@ toku_ft_remove_on_commit(FT_HANDLE handle, TOKUTXN txn) {
// close works in toku_cachefile_close();
// Requires: serialized with begin checkpoint
void
toku_ft_remove(FT_HANDLE handle) {
toku_ft_unlink(FT_HANDLE handle) {
CACHEFILE cf;
cf = handle->ft->cf;
toku_cachefile_unlink_on_close(cf);
......
......@@ -544,34 +544,40 @@ toku_ft_note_ft_handle_open(FT ft, FT_HANDLE live) {
toku_ft_release_reflock(ft);
}
bool
toku_ft_needed_unlocked(FT h)
// Effect: Return true iff the reference count is positive.
{
return !toku_list_empty(&h->live_ft_handles) || toku_omt_size(h->txns) != 0 || h->pinned_by_checkpoint;
}
BOOL
toku_ft_has_one_reference_unlocked(FT ft) {
// the reference count for a ft is the number of txn's that
// touched it plus the number of open handles plus one if
// pinned by a checkpoint.
static int
ft_get_reference_count(FT ft) {
u_int32_t pinned_by_checkpoint = ft->pinned_by_checkpoint ? 1 : 0;
u_int32_t num_txns = toku_omt_size(ft->txns);
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
// the close and using the lsn provided by logging the close. (Subject to constraint
// that if a newer lsn is already in the dictionary, don't overwrite the dictionary.)
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).
{
// 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) {
int r = 0;
// Must do this work before closing the cf
if (h->cf) {
if (error_string) assert(*error_string == 0);
r = toku_cachefile_close(&h->cf, error_string, oplsn_valid, oplsn);
if (r==0 && error_string) assert(*error_string == 0);
assert(ft->cf);
if (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;
}
......@@ -989,13 +995,13 @@ toku_ft_remove_reference(FT ft, bool oplsn_valid, LSN oplsn, remove_ft_ref_callb
toku_ft_grab_reflock(ft);
remove_ref(ft, extra);
BOOL needed = toku_ft_needed_unlocked(ft);
bool needed = toku_ft_needed_unlocked(ft);
toku_ft_release_reflock(ft);
if (!needed) {
// close header
char *error_string = NULL;
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(error_string == NULL);
}
......
......@@ -15,13 +15,11 @@
#include "ft-ops.h"
#include "compress.h"
// remove a ft, transactionless.
// if the ft is being checkpointed, it will be removed after checkpoint.
void toku_ft_remove(FT_HANDLE handle);
// unlink a ft from the filesystem, without a txn.
void toku_ft_unlink(FT_HANDLE handle);
// remove a ft using the given txn. when the txn commits, the ft is removed.
// if the ft is being checkpointed, it will be removed after checkpoint.
int toku_ft_remove_on_commit(FT_HANDLE handle, TOKUTXN txn) __attribute__((__warn_unused_result__));
// unlink a ft from the filesystem when the given txn commits.
int toku_ft_unlink_on_commit(FT_HANDLE handle, TOKUTXN txn) __attribute__((__warn_unused_result__));
//Effect: suppresses rollback logs
void toku_ft_suppress_rollbacks(FT h, TOKUTXN txn);
......@@ -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);
void toku_ft_note_ft_handle_open(FT ft, FT_HANDLE live);
int toku_ft_needed_unlocked(FT h);
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));
bool toku_ft_needed_unlocked(FT ft);
bool toku_ft_has_one_reference_unlocked(FT ft);
// 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);
......
......@@ -876,7 +876,7 @@ static int toku_recover_fdelete (struct logtype_fdelete *l, RECOVER_ENV renv) {
struct file_map_tuple *tuple;
r = file_map_find(&renv->fmap, l->filenum, &tuple);
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;
}
......
......@@ -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) {
r = DB_LOCK_NOTGRANTED;
} else {
// The ft will be removed when the txn commits
r = toku_ft_remove_on_commit(db->i->ft_handle, db_txn_struct_i(txn)->tokutxn);
// The ft will be unlinked when the txn commits
r = toku_ft_unlink_on_commit(db->i->ft_handle, db_txn_struct_i(txn)->tokutxn);
assert_zero(r);
}
}
else {
// Remove the ft without a txn
toku_ft_remove(db->i->ft_handle);
// unlink the ft without a txn
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