Commit 9aec732c authored by Zardosht Kasheff's avatar Zardosht Kasheff

refs #61, clean up code relating to cachefiles, expand the

cachefiles_list class and move some functionality in there.
parent e3e3f40c
...@@ -197,7 +197,13 @@ struct cachefile { ...@@ -197,7 +197,13 @@ struct cachefile {
int fd; /* Bug: If a file is opened read-only, then it is stuck in read-only. If it is opened read-write, then subsequent writers can write to it too. */ int fd; /* Bug: If a file is opened read-only, then it is stuck in read-only. If it is opened read-write, then subsequent writers can write to it too. */
CACHETABLE cachetable; CACHETABLE cachetable;
struct fileid fileid; struct fileid fileid;
// the filenum is used as an identifer of the cachefile
// for logging and recovery
FILENUM filenum; FILENUM filenum;
// number used to generate hashes for blocks in the cachefile
// used in toku_cachetable_hash
// this used to be the filenum.fileid, but now it is separate
uint32_t hash_id;
char *fname_in_env; /* Used for logging */ char *fname_in_env; /* Used for logging */
void *userdata; void *userdata;
...@@ -398,9 +404,10 @@ public: ...@@ -398,9 +404,10 @@ public:
private: private:
void pair_remove (PAIR p); void pair_remove (PAIR p);
void cf_pairs_remove (PAIR p); void cf_pairs_remove (PAIR p);
void remove_from_hash_chain(PAIR p);
void add_to_cf_list (PAIR p); void add_to_cf_list (PAIR p);
void add_to_clock (PAIR p); void add_to_clock (PAIR p);
PAIR remove_from_hash_chain (PAIR remove_me, PAIR list); void add_to_hash_chain(PAIR p);
}; };
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -415,6 +422,13 @@ public: ...@@ -415,6 +422,13 @@ public:
void read_unlock(); void read_unlock();
void write_lock(); void write_lock();
void write_unlock(); void write_unlock();
int cachefile_of_iname_in_env(const char *iname_in_env, CACHEFILE *cf);
int cachefile_of_filenum(FILENUM filenum, CACHEFILE *cf);
void add_cf_unlocked(CACHEFILE newcf);
void remove_cf(CACHEFILE cf);
FILENUM reserve_filenum();
CACHEFILE find_cachefile_unlocked(struct fileid* fileid);
void verify_unused_filenum(FILENUM filenum);
// access to these fields are protected by the lock // access to these fields are protected by the lock
CACHEFILE m_head; CACHEFILE m_head;
FILENUM m_next_filenum_to_use; FILENUM m_next_filenum_to_use;
......
This diff is collapsed.
...@@ -542,12 +542,6 @@ int toku_cachefile_get_fd (CACHEFILE); ...@@ -542,12 +542,6 @@ int toku_cachefile_get_fd (CACHEFILE);
// Return the filename // Return the filename
char * toku_cachefile_fname_in_env (CACHEFILE cf); char * toku_cachefile_fname_in_env (CACHEFILE cf);
// For test programs only.
// Set the cachefile's fd and fname.
// Effect: Bind the cachefile to a new fd and fname. The old fd is closed.
// Returns: 0 if success, otherwise an error number
int toku_cachefile_set_fd (CACHEFILE cf, int fd, const char *fname_relative_to_env);
// Make it so when the cachefile closes, the underlying file is unlinked // Make it so when the cachefile closes, the underlying file is unlinked
void toku_cachefile_unlink_on_close(CACHEFILE cf); void toku_cachefile_unlink_on_close(CACHEFILE cf);
......
...@@ -89,6 +89,7 @@ PATENT RIGHTS GRANT: ...@@ -89,6 +89,7 @@ PATENT RIGHTS GRANT:
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include "test.h" #include "test.h"
#include "toku_os.h"
static void static void
...@@ -110,15 +111,19 @@ cachetable_fd_test (void) { ...@@ -110,15 +111,19 @@ cachetable_fd_test (void) {
// test set to good fd succeeds // test set to good fd succeeds
char fname2[TOKU_PATH_MAX+1]; char fname2[TOKU_PATH_MAX+1];
unlink(toku_path_join(fname2, 2, TOKU_TEST_FILENAME, "test2.dat")); unlink(toku_path_join(fname2, 2, TOKU_TEST_FILENAME, "test2.dat"));
int fd2 = open(fname2, O_RDWR | O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(fd2 >= 0 && fd1 != fd2); int fd2 = open(fname2, O_RDWR | O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
r = toku_cachefile_set_fd(cf, fd2, fname2); assert(r == 0); assert(fd2 >= 0 && fd1 != fd2);
assert(toku_cachefile_get_fd(cf) == fd2); struct fileid id;
r = toku_os_get_unique_file_id(fd2, &id);
assert(r == 0);
close(fd2);
// test set to bogus fd fails // test set to bogus fd fails
int fd3 = open(DEV_NULL_FILE, O_RDWR); assert(fd3 >= 0); int fd3 = open(DEV_NULL_FILE, O_RDWR); assert(fd3 >= 0);
r = close(fd3); assert(r == 0); r = close(fd3);
r = toku_cachefile_set_fd(cf, fd3, DEV_NULL_FILE); assert(r != 0); assert(r == 0);
assert(toku_cachefile_get_fd(cf) == fd2); r = toku_os_get_unique_file_id(fd3, &id);
assert(r < 0);
// test the filenum functions // test the filenum functions
FILENUM fn = toku_cachefile_filenum(cf); FILENUM fn = toku_cachefile_filenum(cf);
......
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