From b5a18e2338f8aa300a827989995b23a1f4e2caa8 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 16 Apr 2013 23:12:06 +0700 Subject: [PATCH] #12 All BDB tests passed! --- tcejdb/Makefile.in | 2 +- tcejdb/tcbdb.c | 8 ++++---- tcejdb/tchdb.c | 20 ++++++++++++++------ tcejdb/tcutil.c | 12 ++++++------ 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/tcejdb/Makefile.in b/tcejdb/Makefile.in index 60cbe64..c215968 100644 --- a/tcejdb/Makefile.in +++ b/tcejdb/Makefile.in @@ -295,7 +295,7 @@ check-hdb : $(RUNENV) $(RUNCMD) ./tchmgr get casket four > check.out $(RUNENV) $(RUNCMD) ./tchmgr get casket five > check.out $(RUNENV) $(RUNCMD) ./tchmgr list -pv casket > check.out -# rm -rf casket* + rm -rf casket* check-bdb : diff --git a/tcejdb/tcbdb.c b/tcejdb/tcbdb.c index b725057..c19a542 100644 --- a/tcejdb/tcbdb.c +++ b/tcejdb/tcbdb.c @@ -874,7 +874,7 @@ bool tcbdbtrancommit(TCBDB *bdb){ bool tcbdbtranabort(TCBDB *bdb){ assert(bdb); if(!BDBLOCKMETHOD(bdb, true)) return false; - if(!bdb->open || !bdb->wmode || !bdb->tran){ + if(!bdb->open || !bdb->wmode || !bdb->tran || !bdb->rbopaque){ tcbdbsetecode(bdb, TCEINVALID, __FILE__, __LINE__, __func__); BDBUNLOCKMETHOD(bdb); return false; @@ -3506,17 +3506,17 @@ static bool tcbdboptimizeimpl(TCBDB *bdb, int32_t lmemb, int32_t nmemb, TCFREE(opath); return false; } - if(unlink(opath)){ + if(!tcunlinkfile(opath)){ tcbdbsetecode(bdb, TCEUNLINK, __FILE__, __LINE__, __func__); err = true; } - if(rename(tpath, opath)){ + if(!tcrenamefile(tpath, opath)){ tcbdbsetecode(bdb, TCERENAME, __FILE__, __LINE__, __func__); err = true; } TCFREE(tpath); if(err){ - TCFREE(opath); + TCFREE(opath); return false; } bool rv = tcbdbopenimpl(bdb, opath, omode); diff --git a/tcejdb/tchdb.c b/tcejdb/tchdb.c index 6645dac..070f386 100644 --- a/tcejdb/tchdb.c +++ b/tcejdb/tchdb.c @@ -2087,7 +2087,7 @@ static bool tchdbseekwrite2(TCHDB *hdb, off_t off, const void *buf, size_t size, if(hdb->tran && !(opts & HDBWRITENOWALL) && !tchdbwalwrite(hdb, off, size)) return false; off_t end = off + size; if(end >= hdb->xfsiz){ - if(!tchdbftruncate2(hdb, end + HDBXFSIZINC, opts)){ + if(!tchdbftruncate2(hdb, end, opts)){ tchdbsetecode(hdb, TCETRUNC, __FILE__, __LINE__, __func__); return false; } @@ -5038,7 +5038,7 @@ static bool tchdboptimizeimpl(TCHDB *hdb, int64_t bnum, int8_t apow, int8_t fpow err = true; } } - + if(!tcrenamefile(tpath, opath)){ tchdbsetecode(hdb, TCERENAME, __FILE__, __LINE__, __func__); err = true; @@ -5485,10 +5485,14 @@ static bool tchdbftruncate(TCHDB *hdb, off_t length) { static bool tchdbftruncate2(TCHDB *hdb, off_t length, int opts) { #ifndef _WIN32 length = length ? tcpagealign(length) : 0; - if (!(hdb->omode & HDBOWRITER) || - ((length <= hdb->xfsiz || length <= hdb->fsiz) && !(opts & HDBTRUNCSHRINKFILE))) { + if (!(hdb->omode & HDBOWRITER) || (length <= hdb->xfsiz && !(opts & HDBTRUNCSHRINKFILE))) { return true; } + if (length > hdb->xfsiz && !(opts & HDBTRUNCSHRINKFILE)) { + off_t o1 = tcpagealign((_maxof(off_t) - length < HDBXFSIZINC) ? length : length + HDBXFSIZINC); + off_t o2 = tcpagealign(((long double) 1.5) * length); + length = MAX(o1, o2); + } if (ftruncate(hdb->fd, length) == 0) { hdb->xfsiz = length; return true; @@ -5502,13 +5506,17 @@ static bool tchdbftruncate2(TCHDB *hdb, off_t length, int opts) { size.QuadPart = (hdb->omode & HDBOWRITER) ? tcpagealign((length == 0) ? 1 : length) : length; if (hdb->map && length > 0 && - (!(hdb->omode & HDBOWRITER) || - ((size.QuadPart <= hdb->xfsiz || size.QuadPart <= hdb->fsiz) && !(opts & HDBTRUNCSHRINKFILE)))) { + (!(hdb->omode & HDBOWRITER) || (size.QuadPart <= hdb->xfsiz && !(opts & HDBTRUNCSHRINKFILE)))) { return true; } if (!(opts & HDBWRITENOLOCK) && !HDBLOCKSMEM(hdb, true)) { return false; } + if ((hdb->omode & HDBOWRITER) && size.QuadPart > hdb->xfsiz && !(opts & HDBTRUNCSHRINKFILE)) { + off_t o1 = tcpagealign((_maxof(off_t) - size.QuadPart < HDBXFSIZINC) ? size.QuadPart : size.QuadPart + HDBXFSIZINC); + off_t o2 = tcpagealign(((long double) 1.5) * size.QuadPart); + size.QuadPart = MAX(o1, o2); + } if (hdb->map) { FlushViewOfFile((PCVOID) hdb->map, 0); if (!UnmapViewOfFile((LPCVOID) hdb->map) || !CloseHandle(hdb->w32hmap)) { diff --git a/tcejdb/tcutil.c b/tcejdb/tcutil.c index 3332115..0e98f56 100644 --- a/tcejdb/tcutil.c +++ b/tcejdb/tcutil.c @@ -7209,7 +7209,7 @@ bool tcunlinkfile(const char *path) { } else { return true; } - if (wsec > 10.0) { + if (wsec > 8.0) { break; } tcsleep(wsec); @@ -7233,7 +7233,7 @@ bool tcrenamefile(const char *from, const char* to) { } else { return true; } - if (wsec > 10.0) { + if (wsec > 8.0) { break; } tcsleep(wsec); @@ -10567,17 +10567,17 @@ double tclog2d(double num){ } off_t tcpagsize(void) { -#ifdef _WIN32 static off_t g_pagesize = 0; if (!g_pagesize) { +#ifdef _WIN32 SYSTEM_INFO system_info; GetSystemInfo(&system_info); g_pagesize = system_info.dwPageSize; - } - return g_pagesize; #else - return sysconf(_SC_PAGESIZE); + g_pagesize = sysconf(_SC_PAGESIZE); #endif + } + return g_pagesize; } /* Get the aligned offset of a file offset. */ -- 2.7.4