Skip to content

Commit d9787aa

Browse files
committed
5.6.33-79.0
1 parent e312e2e commit d9787aa

40 files changed

+1105
-160
lines changed

storage/tokudb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SET(TOKUDB_VERSION 5.6.32-78.1)
1+
SET(TOKUDB_VERSION 5.6.33-79.0)
22
# PerconaFT only supports x86-64 and cmake-2.8.9+
33
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND
44
NOT CMAKE_VERSION VERSION_LESS "2.8.9")

storage/tokudb/PerconaFT/buildheader/make_tdb.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ static void print_db_env_struct (void) {
422422
"int (*set_checkpoint_pool_threads)(DB_ENV *, uint32_t)",
423423
"void (*set_check_thp)(DB_ENV *, bool new_val)",
424424
"bool (*get_check_thp)(DB_ENV *)",
425+
"bool (*set_dir_per_db)(DB_ENV *, bool new_val)",
426+
"bool (*get_dir_per_db)(DB_ENV *)",
427+
"const char *(*get_data_dir)(DB_ENV *env)",
425428
NULL};
426429

427430
sort_and_dump_fields("db_env", true, extra);

storage/tokudb/PerconaFT/ft/cachetable/cachetable-internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ struct cachefile {
138138
// nor attempt to open any cachefile with the same fname (dname)
139139
// until this cachefile has been fully closed and unlinked.
140140
bool unlink_on_close;
141+
// If set then fclose will not be logged in recovery log.
142+
bool skip_log_recover_on_close;
141143
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. */
142144
CACHETABLE cachetable;
143145
struct fileid fileid;

storage/tokudb/PerconaFT/ft/cachetable/cachetable.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ toku_cachefile_fname_in_env (CACHEFILE cf) {
467467
return cf->fname_in_env;
468468
}
469469

470+
void toku_cachefile_set_fname_in_env(CACHEFILE cf, char *new_fname_in_env) {
471+
cf->fname_in_env = new_fname_in_env;
472+
}
473+
470474
int
471475
toku_cachefile_get_fd (CACHEFILE cf) {
472476
return cf->fd;
@@ -2903,6 +2907,18 @@ bool toku_cachefile_is_unlink_on_close(CACHEFILE cf) {
29032907
return cf->unlink_on_close;
29042908
}
29052909

2910+
void toku_cachefile_skip_log_recover_on_close(CACHEFILE cf) {
2911+
cf->skip_log_recover_on_close = true;
2912+
}
2913+
2914+
void toku_cachefile_do_log_recover_on_close(CACHEFILE cf) {
2915+
cf->skip_log_recover_on_close = false;
2916+
}
2917+
2918+
bool toku_cachefile_is_skip_log_recover_on_close(CACHEFILE cf) {
2919+
return cf->skip_log_recover_on_close;
2920+
}
2921+
29062922
uint64_t toku_cachefile_size(CACHEFILE cf) {
29072923
int64_t file_size;
29082924
int fd = toku_cachefile_get_fd(cf);

storage/tokudb/PerconaFT/ft/cachetable/cachetable.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,18 @@ int toku_cachefile_get_fd (CACHEFILE);
500500
// Return the filename
501501
char * toku_cachefile_fname_in_env (CACHEFILE cf);
502502

503+
void toku_cachefile_set_fname_in_env(CACHEFILE cf, char *new_fname_in_env);
504+
503505
// Make it so when the cachefile closes, the underlying file is unlinked
504506
void toku_cachefile_unlink_on_close(CACHEFILE cf);
505507

506508
// is this cachefile marked as unlink on close?
507509
bool toku_cachefile_is_unlink_on_close(CACHEFILE cf);
508510

511+
void toku_cachefile_skip_log_recover_on_close(CACHEFILE cf);
512+
void toku_cachefile_do_log_recover_on_close(CACHEFILE cf);
513+
bool toku_cachefile_is_skip_log_recover_on_close(CACHEFILE cf);
514+
509515
// Return the logger associated with the cachefile
510516
struct tokulogger *toku_cachefile_logger(CACHEFILE cf);
511517

storage/tokudb/PerconaFT/ft/ft-ops.cc

Lines changed: 147 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,23 @@ basement nodes, bulk fetch, and partial fetch:
149149

150150
#include "ft/cachetable/checkpoint.h"
151151
#include "ft/cursor.h"
152-
#include "ft/ft.h"
153152
#include "ft/ft-cachetable-wrappers.h"
154153
#include "ft/ft-flusher.h"
155154
#include "ft/ft-internal.h"
156-
#include "ft/msg.h"
155+
#include "ft/ft.h"
157156
#include "ft/leafentry.h"
158157
#include "ft/logger/log-internal.h"
158+
#include "ft/msg.h"
159159
#include "ft/node.h"
160160
#include "ft/serialize/block_table.h"
161-
#include "ft/serialize/sub_block.h"
162161
#include "ft/serialize/ft-serialize.h"
163162
#include "ft/serialize/ft_layout_version.h"
164163
#include "ft/serialize/ft_node-serialize.h"
164+
#include "ft/serialize/sub_block.h"
165165
#include "ft/txn/txn_manager.h"
166-
#include "ft/ule.h"
167166
#include "ft/txn/xids.h"
167+
#include "ft/ule.h"
168+
#include "src/ydb-internal.h"
168169

169170
#include <toku_race_tools.h>
170171

@@ -179,6 +180,7 @@ basement nodes, bulk fetch, and partial fetch:
179180

180181
#include <stdint.h>
181182

183+
#include <memory>
182184
/* Status is intended for display to humans to help understand system behavior.
183185
* It does not need to be perfectly thread-safe.
184186
*/
@@ -2593,12 +2595,104 @@ static inline int ft_open_maybe_direct(const char *filename, int oflag, int mode
25932595

25942596
static const mode_t file_mode = S_IRUSR+S_IWUSR+S_IRGRP+S_IWGRP+S_IROTH+S_IWOTH;
25952597

2598+
inline bool toku_file_is_root(const char *path, const char *last_slash) {
2599+
return last_slash == path;
2600+
}
2601+
2602+
static std::unique_ptr<char[], decltype(&toku_free)> toku_file_get_parent_dir(
2603+
const char *path) {
2604+
std::unique_ptr<char[], decltype(&toku_free)> result(nullptr, &toku_free);
2605+
2606+
bool has_trailing_slash = false;
2607+
2608+
/* Find the offset of the last slash */
2609+
const char *last_slash = strrchr(path, OS_PATH_SEPARATOR);
2610+
2611+
if (!last_slash) {
2612+
/* No slash in the path, return NULL */
2613+
return result;
2614+
}
2615+
2616+
/* Ok, there is a slash. Is there anything after it? */
2617+
if (static_cast<size_t>(last_slash - path + 1) == strlen(path)) {
2618+
has_trailing_slash = true;
2619+
}
2620+
2621+
/* Reduce repetative slashes. */
2622+
while (last_slash > path && last_slash[-1] == OS_PATH_SEPARATOR) {
2623+
last_slash--;
2624+
}
2625+
2626+
/* Check for the root of a drive. */
2627+
if (toku_file_is_root(path, last_slash)) {
2628+
return result;
2629+
}
2630+
2631+
/* If a trailing slash prevented the first strrchr() from trimming
2632+
the last component of the path, trim that component now. */
2633+
if (has_trailing_slash) {
2634+
/* Back up to the previous slash. */
2635+
last_slash--;
2636+
while (last_slash > path && last_slash[0] != OS_PATH_SEPARATOR) {
2637+
last_slash--;
2638+
}
2639+
2640+
/* Reduce repetative slashes. */
2641+
while (last_slash > path && last_slash[-1] == OS_PATH_SEPARATOR) {
2642+
last_slash--;
2643+
}
2644+
}
2645+
2646+
/* Check for the root of a drive. */
2647+
if (toku_file_is_root(path, last_slash)) {
2648+
return result;
2649+
}
2650+
2651+
result.reset(toku_strndup(path, last_slash - path));
2652+
return result;
2653+
}
2654+
2655+
static bool toku_create_subdirs_if_needed(const char *path) {
2656+
static const mode_t dir_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
2657+
S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH;
2658+
2659+
toku_struct_stat stat;
2660+
bool subdir_exists = true;
2661+
auto subdir = toku_file_get_parent_dir(path);
2662+
2663+
if (!subdir.get())
2664+
return true;
2665+
2666+
if (toku_stat(subdir.get(), &stat) == -1) {
2667+
if (ENOENT == get_error_errno())
2668+
subdir_exists = false;
2669+
else
2670+
return false;
2671+
}
2672+
2673+
if (subdir_exists) {
2674+
if (!S_ISDIR(stat.st_mode))
2675+
return false;
2676+
return true;
2677+
}
2678+
2679+
if (!toku_create_subdirs_if_needed(subdir.get()))
2680+
return false;
2681+
2682+
if (toku_os_mkdir(subdir.get(), dir_mode))
2683+
return false;
2684+
2685+
return true;
2686+
}
2687+
25962688
// open a file for use by the ft
25972689
// Requires: File does not exist.
25982690
static int ft_create_file(FT_HANDLE UU(ft_handle), const char *fname, int *fdp) {
25992691
int r;
26002692
int fd;
26012693
int er;
2694+
if (!toku_create_subdirs_if_needed(fname))
2695+
return get_error_errno();
26022696
fd = ft_open_maybe_direct(fname, O_RDWR | O_BINARY, file_mode);
26032697
assert(fd==-1);
26042698
if ((er = get_maybe_error_errno()) != ENOENT) {
@@ -4427,6 +4521,55 @@ void toku_ft_unlink(FT_HANDLE handle) {
44274521
toku_cachefile_unlink_on_close(cf);
44284522
}
44294523

4524+
int toku_ft_rename_iname(DB_TXN *txn,
4525+
const char *data_dir,
4526+
const char *old_iname,
4527+
const char *new_iname,
4528+
CACHETABLE ct) {
4529+
int r = 0;
4530+
4531+
std::unique_ptr<char[], decltype(&toku_free)> new_iname_full(nullptr,
4532+
&toku_free);
4533+
std::unique_ptr<char[], decltype(&toku_free)> old_iname_full(nullptr,
4534+
&toku_free);
4535+
4536+
new_iname_full.reset(toku_construct_full_name(2, data_dir, new_iname));
4537+
old_iname_full.reset(toku_construct_full_name(2, data_dir, old_iname));
4538+
4539+
if (txn) {
4540+
BYTESTRING bs_old_name = {static_cast<uint32_t>(strlen(old_iname) + 1),
4541+
const_cast<char *>(old_iname)};
4542+
BYTESTRING bs_new_name = {static_cast<uint32_t>(strlen(new_iname) + 1),
4543+
const_cast<char *>(new_iname)};
4544+
FILENUM filenum = FILENUM_NONE;
4545+
{
4546+
CACHEFILE cf;
4547+
r = toku_cachefile_of_iname_in_env(ct, old_iname, &cf);
4548+
if (r != ENOENT) {
4549+
char *old_fname_in_cf = toku_cachefile_fname_in_env(cf);
4550+
toku_cachefile_set_fname_in_env(cf, toku_xstrdup(new_iname));
4551+
toku_free(old_fname_in_cf);
4552+
filenum = toku_cachefile_filenum(cf);
4553+
}
4554+
}
4555+
toku_logger_save_rollback_frename(
4556+
db_txn_struct_i(txn)->tokutxn, &bs_old_name, &bs_new_name);
4557+
toku_log_frename(db_txn_struct_i(txn)->tokutxn->logger,
4558+
(LSN *)0,
4559+
0,
4560+
toku_txn_get_txnid(db_txn_struct_i(txn)->tokutxn),
4561+
bs_old_name,
4562+
filenum,
4563+
bs_new_name);
4564+
}
4565+
4566+
r = toku_os_rename(old_iname_full.get(), new_iname_full.get());
4567+
if (r != 0)
4568+
return r;
4569+
r = toku_fsync_directory(new_iname_full.get());
4570+
return r;
4571+
}
4572+
44304573
int toku_ft_get_fragmentation(FT_HANDLE ft_handle, TOKU_DB_FRAGMENTATION report) {
44314574
int fd = toku_cachefile_get_fd(ft_handle->ft->cf);
44324575
toku_ft_lock(ft_handle->ft);

storage/tokudb/PerconaFT/ft/ft-ops.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
4848
#include "ft/msg.h"
4949
#include "util/dbt.h"
5050

51+
#define OS_PATH_SEPARATOR '/'
52+
5153
typedef struct ft_handle *FT_HANDLE;
5254

5355
int toku_open_ft_handle (const char *fname, int is_create, FT_HANDLE *, int nodesize, int basementnodesize, enum toku_compression_method compression_method, CACHETABLE, TOKUTXN, int(*)(DB *,const DBT*,const DBT*)) __attribute__ ((warn_unused_result));

storage/tokudb/PerconaFT/ft/ft.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,19 @@ static void ft_close(CACHEFILE cachefile, int fd, void *header_v, bool oplsn_val
253253
char* fname_in_env = toku_cachefile_fname_in_env(cachefile);
254254
assert(fname_in_env);
255255
BYTESTRING bs = {.len=(uint32_t) strlen(fname_in_env), .data=fname_in_env};
256-
toku_log_fclose(logger, &lsn, ft->h->dirty, bs, toku_cachefile_filenum(cachefile)); // flush the log on close (if new header is being written), otherwise it might not make it out.
256+
if (!toku_cachefile_is_skip_log_recover_on_close(cachefile)) {
257+
toku_log_fclose(
258+
logger,
259+
&lsn,
260+
ft->h->dirty,
261+
bs,
262+
toku_cachefile_filenum(cachefile)); // flush the log on
263+
// close (if new header
264+
// is being written),
265+
// otherwise it might
266+
// not make it out.
267+
toku_cachefile_do_log_recover_on_close(cachefile);
268+
}
257269
}
258270
}
259271
if (ft->h->dirty) { // this is the only place this bit is tested (in currentheader)

storage/tokudb/PerconaFT/ft/ft.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ typedef struct ft_options *FT_OPTIONS;
5353
void toku_ft_unlink(FT_HANDLE handle);
5454
void toku_ft_unlink_on_commit(FT_HANDLE handle, TOKUTXN txn);
5555

56+
int toku_ft_rename_iname(DB_TXN *txn,
57+
const char *data_dir,
58+
const char *old_iname,
59+
const char *new_iname,
60+
CACHETABLE ct);
61+
5662
void toku_ft_init_reflock(FT ft);
5763
void toku_ft_destroy_reflock(FT ft);
5864
void toku_ft_grab_reflock(FT ft);

storage/tokudb/PerconaFT/ft/logger/logformat.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ const struct logtype rollbacks[] = {
9090
{"fcreate", 'F', FA{{"FILENUM", "filenum", 0},
9191
{"BYTESTRING", "iname", 0},
9292
NULLFIELD}, LOG_BEGIN_ACTION_NA},
93+
//rename file
94+
{"frename", 'n', FA{{"BYTESTRING", "old_iname", 0},
95+
{"BYTESTRING", "new_iname", 0},
96+
NULLFIELD}, LOG_BEGIN_ACTION_NA},
9397
// cmdinsert is used to insert a key-value pair into a DB. For rollback we don't need the data.
9498
{"cmdinsert", 'i', FA{
9599
{"FILENUM", "filenum", 0},
@@ -195,6 +199,11 @@ const struct logtype logtypes[] = {
195199
{"fdelete", 'U', FA{{"TXNID_PAIR", "xid", 0},
196200
{"FILENUM", "filenum", 0},
197201
NULLFIELD}, SHOULD_LOG_BEGIN},
202+
{"frename", 'n', FA{{"TXNID_PAIR", "xid", 0},
203+
{"BYTESTRING", "old_iname", 0},
204+
{"FILENUM", "old_filenum", 0},
205+
{"BYTESTRING", "new_iname", 0},
206+
NULLFIELD}, IGNORE_LOG_BEGIN},
198207
{"enq_insert", 'I', FA{{"FILENUM", "filenum", 0},
199208
{"TXNID_PAIR", "xid", 0},
200209
{"BYTESTRING", "key", 0},

0 commit comments

Comments
 (0)