Commit c855db10 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

closes[t:2616] fix the file open fail path in the loader_do_i function

git-svn-id: file:///svn/toku/tokudb@20308 c7de825b-a66e-492c-adef-691d508d4ae1
parent b76f1d2a
...@@ -204,13 +204,15 @@ int brtloader_fi_reopen (struct file_infos *fi, FIDX idx, const char *mode) { ...@@ -204,13 +204,15 @@ int brtloader_fi_reopen (struct file_infos *fi, FIDX idx, const char *mode) {
invariant(!fi->file_infos[i].is_open); invariant(!fi->file_infos[i].is_open);
invariant(fi->file_infos[i].is_extant); invariant(fi->file_infos[i].is_extant);
fi->file_infos[i].file = fopen(fi->file_infos[i].fname, mode); fi->file_infos[i].file = fopen(fi->file_infos[i].fname, mode);
if (fi->file_infos[i].file==NULL) { result = errno; goto error; } if (fi->file_infos[i].file == NULL) {
result = errno;
} else {
fi->file_infos[i].is_open = TRUE; fi->file_infos[i].is_open = TRUE;
// No longer need the big buffer for reopened files. Don't allocate the space, we need it elsewhere. // No longer need the big buffer for reopened files. Don't allocate the space, we need it elsewhere.
//add_big_buffer(&fi->file_infos[i]); //add_big_buffer(&fi->file_infos[i]);
fi->n_files_open++; fi->n_files_open++;
}
r = toku_pthread_mutex_unlock(&fi->lock); resource_assert(r==0); r = toku_pthread_mutex_unlock(&fi->lock); resource_assert(r==0);
error:
return result; return result;
} }
...@@ -265,8 +267,10 @@ int brtloader_open_temp_file (BRTLOADER bl, FIDX *file_idx) ...@@ -265,8 +267,10 @@ int brtloader_open_temp_file (BRTLOADER bl, FIDX *file_idx)
result = open_file_add(&bl->file_infos, f, fname, file_idx); result = open_file_add(&bl->file_infos, f, fname, file_idx);
} }
if (result != 0) { if (result != 0) {
if (fd >= 0) if (fd >= 0) {
close(fd); close(fd);
unlink(fname);
}
if (f != NULL) if (f != NULL)
fclose(f); fclose(f);
if (fname != NULL) if (fname != NULL)
...@@ -331,7 +335,7 @@ static uint64_t memory_per_rowset (BRTLOADER bl) { ...@@ -331,7 +335,7 @@ static uint64_t memory_per_rowset (BRTLOADER bl) {
} }
// RFP 2535 error recovery in the loader open needs to be replaced // LAZY cleanup on error paths, ticket #2591
int toku_brt_loader_open (/* out */ BRTLOADER *blp, int toku_brt_loader_open (/* out */ BRTLOADER *blp,
CACHETABLE cachetable, CACHETABLE cachetable,
generate_row_for_put_func g, generate_row_for_put_func g,
...@@ -817,7 +821,7 @@ static int finish_extractor (BRTLOADER bl) { ...@@ -817,7 +821,7 @@ static int finish_extractor (BRTLOADER bl) {
//printf("%s:%d please finish extraction\n", __FILE__, __LINE__); //printf("%s:%d please finish extraction\n", __FILE__, __LINE__);
{ {
int r = queue_eof(bl->primary_rowset_queue); int r = queue_eof(bl->primary_rowset_queue);
assert(r==0); invariant(r==0);
} }
//printf("%s:%d joining\n", __FILE__, __LINE__); //printf("%s:%d joining\n", __FILE__, __LINE__);
{ {
...@@ -829,7 +833,7 @@ static int finish_extractor (BRTLOADER bl) { ...@@ -829,7 +833,7 @@ static int finish_extractor (BRTLOADER bl) {
} }
{ {
int r = queue_destroy(bl->primary_rowset_queue); int r = queue_destroy(bl->primary_rowset_queue);
assert(r==0); invariant(r==0);
} }
//printf("%s:%d joined\n", __FILE__, __LINE__); //printf("%s:%d joined\n", __FILE__, __LINE__);
return 0; return 0;
...@@ -2188,7 +2192,9 @@ static int loader_do_i (BRTLOADER bl, ...@@ -2188,7 +2192,9 @@ static int loader_do_i (BRTLOADER bl,
{ {
mode_t mode = S_IRWXU|S_IRWXG|S_IRWXO; mode_t mode = S_IRWXU|S_IRWXG|S_IRWXO;
int fd = open(new_fname, O_RDWR| O_CREAT | O_BINARY, mode); int fd = open(new_fname, O_RDWR| O_CREAT | O_BINARY, mode);
lazy_assert(fd>=0); if (fd < 0) {
r = errno; goto error;
}
// This structure must stay live until the join below. // This structure must stay live until the join below.
struct fractal_thread_args fta = {bl, struct fractal_thread_args fta = {bl,
...@@ -2294,7 +2300,7 @@ int toku_brt_loader_close (BRTLOADER bl, ...@@ -2294,7 +2300,7 @@ int toku_brt_loader_close (BRTLOADER bl,
if (bl->extractor_live) { if (bl->extractor_live) {
r = finish_extractor(bl); r = finish_extractor(bl);
lazy_assert(r == 0); // LAZY !!! should check this error code and cleanup if needed. lazy_assert(r == 0); // LAZY !!! should check this error code and cleanup if needed.
lazy_assert(!bl->extractor_live); invariant(!bl->extractor_live);
} }
// check for an error during extraction // check for an error during extraction
......
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