Commit e136453c authored by Barry Perlman's avatar Barry Perlman Committed by Yoni Fogel

[t:3102] Change brtloader_fi_close() to ignore files that are already closed...

[t:3102] Change brtloader_fi_close() to ignore files that are already closed when called from brtloader_fi_close_all().

git-svn-id: file:///svn/toku/tokudb@26361 c7de825b-a66e-492c-adef-691d508d4ae1
parent ce01ca80
...@@ -226,7 +226,7 @@ int brt_loader_write_file_to_dbfile (int outfile, FIDX infile, BRTLOADER bl, con ...@@ -226,7 +226,7 @@ int brt_loader_write_file_to_dbfile (int outfile, FIDX infile, BRTLOADER bl, con
int brtloader_init_file_infos (struct file_infos *fi); int brtloader_init_file_infos (struct file_infos *fi);
void brtloader_fi_destroy (struct file_infos *fi, BOOL is_error); void brtloader_fi_destroy (struct file_infos *fi, BOOL is_error);
int brtloader_fi_close (struct file_infos *fi, FIDX idx); int brtloader_fi_close (struct file_infos *fi, FIDX idx, BOOL require_open);
int brtloader_fi_close_all (struct file_infos *fi); int brtloader_fi_close_all (struct file_infos *fi);
int brtloader_fi_reopen (struct file_infos *fi, FIDX idx, const char *mode); int brtloader_fi_reopen (struct file_infos *fi, FIDX idx, const char *mode);
int brtloader_fi_unlink (struct file_infos *fi, FIDX idx); int brtloader_fi_unlink (struct file_infos *fi, FIDX idx);
......
...@@ -245,7 +245,7 @@ int brtloader_fi_reopen (struct file_infos *fi, FIDX idx, const char *mode) { ...@@ -245,7 +245,7 @@ int brtloader_fi_reopen (struct file_infos *fi, FIDX idx, const char *mode) {
return result; return result;
} }
int brtloader_fi_close (struct file_infos *fi, FIDX idx) int brtloader_fi_close (struct file_infos *fi, FIDX idx, BOOL require_open)
{ {
int result = 0; int result = 0;
{ {
...@@ -261,7 +261,7 @@ int brtloader_fi_close (struct file_infos *fi, FIDX idx) ...@@ -261,7 +261,7 @@ int brtloader_fi_close (struct file_infos *fi, FIDX idx)
if (r) if (r)
result = errno; result = errno;
cleanup_big_buffer(&fi->file_infos[idx.idx]); cleanup_big_buffer(&fi->file_infos[idx.idx]);
} else } else if (require_open)
result = EINVAL; result = EINVAL;
{ {
int r = toku_pthread_mutex_unlock(&fi->lock); int r = toku_pthread_mutex_unlock(&fi->lock);
...@@ -297,7 +297,7 @@ brtloader_fi_close_all(struct file_infos *fi) { ...@@ -297,7 +297,7 @@ brtloader_fi_close_all(struct file_infos *fi) {
for (int i = 0; i < fi->n_files; i++) { for (int i = 0; i < fi->n_files; i++) {
int r; int r;
FIDX idx = { i }; FIDX idx = { i };
r = brtloader_fi_close(fi, idx); r = brtloader_fi_close(fi, idx, FALSE); // ignore files that are already closed
if (rval == 0 && r) if (rval == 0 && r)
rval = r; // capture first error rval = r; // capture first error
} }
...@@ -1576,7 +1576,7 @@ int sort_and_write_rows (struct rowset rows, struct merge_fileset *fs, BRTLOADER ...@@ -1576,7 +1576,7 @@ int sort_and_write_rows (struct rowset rows, struct merge_fileset *fs, BRTLOADER
// write the sorted rowset into a new temp file // write the sorted rowset into a new temp file
if (fs->have_sorted_output) { if (fs->have_sorted_output) {
fs->have_sorted_output = FALSE; fs->have_sorted_output = FALSE;
result = brtloader_fi_close(&bl->file_infos, fs->sorted_output); result = brtloader_fi_close(&bl->file_infos, fs->sorted_output, TRUE);
} }
if (result == 0) { if (result == 0) {
FIDX sfile = FIDX_NULL; FIDX sfile = FIDX_NULL;
...@@ -1940,7 +1940,7 @@ int merge_files (struct merge_fileset *fs, ...@@ -1940,7 +1940,7 @@ int merge_files (struct merge_fileset *fs,
for (int i=0; i<n_to_merge; i++) { for (int i=0; i<n_to_merge; i++) {
if (!fidx_is_null(data_fidxs[i])) { if (!fidx_is_null(data_fidxs[i])) {
{ {
int r = brtloader_fi_close(&bl->file_infos, data_fidxs[i]); int r = brtloader_fi_close(&bl->file_infos, data_fidxs[i], TRUE);
if (r!=0 && result==0) result = r; if (r!=0 && result==0) result = r;
} }
{ {
...@@ -1953,7 +1953,7 @@ int merge_files (struct merge_fileset *fs, ...@@ -1953,7 +1953,7 @@ int merge_files (struct merge_fileset *fs,
fs->n_temp_files -= n_to_merge; fs->n_temp_files -= n_to_merge;
if (!to_queue && !fidx_is_null(merged_data)) { if (!to_queue && !fidx_is_null(merged_data)) {
int r = brtloader_fi_close(&bl->file_infos, merged_data); int r = brtloader_fi_close(&bl->file_infos, merged_data, TRUE);
if (r!=0 && result==0) result = r; if (r!=0 && result==0) result = r;
} }
toku_free(data_fidxs); toku_free(data_fidxs);
...@@ -3277,7 +3277,7 @@ static int write_nonleaves (BRTLOADER bl, FIDX pivots_fidx, struct dbout *out, s ...@@ -3277,7 +3277,7 @@ static int write_nonleaves (BRTLOADER bl, FIDX pivots_fidx, struct dbout *out, s
result = brt_loader_get_error(&bl->error_callback); result = brt_loader_get_error(&bl->error_callback);
// Now set things up for the next iteration. // Now set things up for the next iteration.
int r = brtloader_fi_close(&bl->file_infos, pivots_fidx); if (r != 0 && result == 0) result = r; int r = brtloader_fi_close(&bl->file_infos, pivots_fidx, TRUE); if (r != 0 && result == 0) result = r;
r = brtloader_fi_unlink(&bl->file_infos, pivots_fidx); if (r != 0 && result == 0) result = r; r = brtloader_fi_unlink(&bl->file_infos, pivots_fidx); if (r != 0 && result == 0) result = r;
pivots_fidx = next_pivots_file; pivots_fidx = next_pivots_file;
toku_free(sts->subtrees); sts->subtrees = NULL; toku_free(sts->subtrees); sts->subtrees = NULL;
...@@ -3287,7 +3287,7 @@ static int write_nonleaves (BRTLOADER bl, FIDX pivots_fidx, struct dbout *out, s ...@@ -3287,7 +3287,7 @@ static int write_nonleaves (BRTLOADER bl, FIDX pivots_fidx, struct dbout *out, s
if (result) if (result)
break; break;
} }
{ int r = brtloader_fi_close (&bl->file_infos, pivots_fidx); if (r != 0 && result == 0) result = r; } { int r = brtloader_fi_close (&bl->file_infos, pivots_fidx, TRUE); if (r != 0 && result == 0) result = r; }
{ int r = brtloader_fi_unlink(&bl->file_infos, pivots_fidx); if (r != 0 && result == 0) result = r; } { int r = brtloader_fi_unlink(&bl->file_infos, pivots_fidx); if (r != 0 && result == 0) result = r; }
return result; return result;
} }
......
...@@ -191,7 +191,7 @@ static void test_read_write_rows (char *template) { ...@@ -191,7 +191,7 @@ static void test_read_write_rows (char *template) {
if (actual_size != dataoff) fprintf(stderr, "actual_size=%"PRIu64", dataoff=%"PRIu64"\n", actual_size, dataoff); if (actual_size != dataoff) fprintf(stderr, "actual_size=%"PRIu64", dataoff=%"PRIu64"\n", actual_size, dataoff);
assert(actual_size == dataoff); assert(actual_size == dataoff);
r = brtloader_fi_close(&bl.file_infos, file); r = brtloader_fi_close(&bl.file_infos, file, TRUE);
CKERR(r); CKERR(r);
r = brtloader_fi_reopen(&bl.file_infos, file, "r"); r = brtloader_fi_reopen(&bl.file_infos, file, "r");
...@@ -213,7 +213,7 @@ static void test_read_write_rows (char *template) { ...@@ -213,7 +213,7 @@ static void test_read_write_rows (char *template) {
toku_free(key.data); toku_free(key.data);
toku_free(val.data); toku_free(val.data);
} }
r = brtloader_fi_close(&bl.file_infos, file); r = brtloader_fi_close(&bl.file_infos, file, TRUE);
CKERR(r); CKERR(r);
r = brtloader_fi_unlink(&bl.file_infos, file); r = brtloader_fi_unlink(&bl.file_infos, file);
......
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