Commit 5cfc0adf authored by Yoni Fogel's avatar Yoni Fogel

[t:2445] Windows port of functionality

git-svn-id: file:///svn/toku/tokudb@18613 c7de825b-a66e-492c-adef-691d508d4ae1
parent c6510b33
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <dirent.h>
static int toku_assert_on_write_enospc = 0; static int toku_assert_on_write_enospc = 0;
static const int toku_write_enospc_sleep = 1; static const int toku_write_enospc_sleep = 1;
...@@ -193,6 +194,19 @@ toku_file_fsync_without_accounting (int fd) { ...@@ -193,6 +194,19 @@ toku_file_fsync_without_accounting (int fd) {
return r; return r;
} }
int
toku_fsync_dirfd_without_accounting(DIR *dirp) {
int r;
int fd = dirfd(dirp);
if (fd<0) {
r = -1;
}
else {
r = toku_file_fsync_without_accounting(fd);
}
return r;
}
static uint64_t get_tnow(void) { static uint64_t get_tnow(void) {
struct timeval tv; struct timeval tv;
int r = gettimeofday(&tv, NULL); assert(r == 0); int r = gettimeofday(&tv, NULL); assert(r == 0);
......
...@@ -460,7 +460,7 @@ static int lc_fix_bad_logfile(TOKULOGCURSOR lc) { ...@@ -460,7 +460,7 @@ static int lc_fix_bad_logfile(TOKULOGCURSOR lc) {
r = fseek(lc->cur_fp, 0, SEEK_SET); if ( r!=0 ) return r; r = fseek(lc->cur_fp, 0, SEEK_SET); if ( r!=0 ) return r;
r = toku_read_logmagic(lc->cur_fp, &version); if ( r!=0 ) return r; r = toku_read_logmagic(lc->cur_fp, &version); if ( r!=0 ) return r;
off_t last_good_pos; toku_off_t last_good_pos;
last_good_pos = ftello(lc->cur_fp); last_good_pos = ftello(lc->cur_fp);
while (1) { while (1) {
// initialize le // initialize le
......
...@@ -74,7 +74,7 @@ int toku_logger_create (TOKULOGGER *resultp) { ...@@ -74,7 +74,7 @@ int toku_logger_create (TOKULOGGER *resultp) {
} }
static int fsync_logdir(TOKULOGGER logger) { static int fsync_logdir(TOKULOGGER logger) {
return toku_file_fsync_without_accounting( dirfd(logger->dir) ); return toku_fsync_dirfd_without_accounting(logger->dir);
} }
static int open_logdir(TOKULOGGER logger, const char *directory) { static int open_logdir(TOKULOGGER logger, const char *directory) {
......
// Make sure that the pending stuff gets checkpointed, but subsequent changes don't, even with concurrent updates. // Make sure that the pending stuff gets checkpointed, but subsequent changes don't, even with concurrent updates.
#include <stdio.h>
#include <unistd.h>
#include "test.h" #include "test.h"
#include <stdio.h>
#include <unistd.h>
#include "checkpoint.h" #include "checkpoint.h"
#include "toku_atomic.h" #include "toku_atomic.h"
......
/* -*- mode: C; c-basic-offset: 4 -*- */ /* -*- mode: C; c-basic-offset: 4 -*- */
#include "test.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "test.h"
#include "checkpoint.h" #include "checkpoint.h"
static const int item_size = 1; static const int item_size = 1;
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
// verify that the cache table checkpoint with prefetched blocks active works. // verify that the cache table checkpoint with prefetched blocks active works.
// the blocks in the reading state should be ignored. // the blocks in the reading state should be ignored.
#include "test.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "test.h"
#include "checkpoint.h" #include "checkpoint.h"
const int item_size = 1; const int item_size = 1;
......
...@@ -11,7 +11,7 @@ static int ...@@ -11,7 +11,7 @@ static int
run_test(void) { run_test(void) {
int r; int r;
int trim = 1; int trim = 1;
struct stat st; toku_struct_stat st;
while ( 1 ) { while ( 1 ) {
// setup the test dir // setup the test dir
......
...@@ -6,6 +6,7 @@ extern "C" { ...@@ -6,6 +6,7 @@ extern "C" {
#endif #endif
#include "toku_os_types.h" #include "toku_os_types.h"
#include <dirent.h>
// Returns: the current process id // Returns: the current process id
int toku_os_getpid(void) __attribute__((__visibility__("default"))); int toku_os_getpid(void) __attribute__((__visibility__("default")));
...@@ -76,6 +77,8 @@ void toku_set_assert_on_write_enospc(int do_assert) __attribute__((__visibility_ ...@@ -76,6 +77,8 @@ void toku_set_assert_on_write_enospc(int do_assert) __attribute__((__visibility_
// *enospc_total is the number of times ENOSPC was returned by write or pwrite // *enospc_total is the number of times ENOSPC was returned by write or pwrite
void toku_fs_get_write_info(time_t *enospc_last_time, uint64_t *enospc_current, uint64_t *enospc_total); void toku_fs_get_write_info(time_t *enospc_last_time, uint64_t *enospc_current, uint64_t *enospc_total);
int toku_fsync_dirfd_without_accounting(DIR *dirp);
#if TOKU_WINDOWS #if TOKU_WINDOWS
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
......
...@@ -138,3 +138,10 @@ toku_fstat(int fd, toku_struct_stat *statbuf) { ...@@ -138,3 +138,10 @@ toku_fstat(int fd, toku_struct_stat *statbuf) {
return r; return r;
} }
int
toku_fsync_dirfd_without_accounting(DIR *dirp) {
//Not supported in windows.
//Possibly not needed
return 0;
}
...@@ -76,8 +76,38 @@ fsync(int fd) { ...@@ -76,8 +76,38 @@ fsync(int fd) {
} }
int int
ftruncate(int fd, int64_t offset) { ftruncate(int fd, toku_off_t offset) {
int r = _chsize_s(fd, offset); int r = _chsize_s(fd, offset);
if (r!=0) {
r = -1;
assert(errno!=0);
}
return r;
}
int
truncate(const char *path, toku_off_t length) {
int r;
int saved_errno;
int fd = open(path, _O_BINARY|_O_RDWR, _S_IREAD|_S_IWRITE);
if (fd<0) {
r = -1;
goto done;
}
r = ftruncate(fd, length);
saved_errno = errno;
if (r!=0) {
r = -1;
assert(errno!=0);
}
int r2 = close(fd);
if (r==0) {
r = r2;
}
else {
errno = saved_errno;
}
done:
return r; return r;
} }
...@@ -327,3 +357,9 @@ cleanup: ...@@ -327,3 +357,9 @@ cleanup:
return fd; return fd;
} }
toku_off_t
ftello(FILE *stream) {
toku_off_t offset = _ftelli64(stream);
return offset;
}
...@@ -80,6 +80,8 @@ int usleep(unsigned int useconds); ...@@ -80,6 +80,8 @@ int usleep(unsigned int useconds);
int mkstemp(char * ttemplate); int mkstemp(char * ttemplate);
toku_off_t ftello(FILE *stream);
#if defined(__cplusplus) #if defined(__cplusplus)
}; };
#endif #endif
......
...@@ -13,7 +13,10 @@ extern "C" { ...@@ -13,7 +13,10 @@ extern "C" {
int fsync(int fildes); int fsync(int fildes);
int int
ftruncate(int fildes, int64_t offset); ftruncate(int fildes, toku_off_t offset);
int
truncate(const char *path, toku_off_t length);
int64_t int64_t
pwrite(int fildes, const void *buf, size_t nbyte, int64_t offset); pwrite(int fildes, const void *buf, size_t nbyte, int64_t offset);
......
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