diff options
author | Anton Adamansky <adamansky@gmail.com> | 2015-04-27 22:11:00 +0600 |
---|---|---|
committer | Anton Adamansky <adamansky@gmail.com> | 2015-04-27 22:11:00 +0600 |
commit | 3ee3c44cac0896a9c042658f44f5cc6c92b00690 (patch) | |
tree | 307ed6efb1e6133f76092574a224826459d6a7d3 | |
parent | 639eabfa667e8a9f6b3286bbd973cb2ca21822c7 (diff) | |
download | ejdb-3ee3c44cac0896a9c042658f44f5cc6c92b00690.tar.gz ejdb-3ee3c44cac0896a9c042658f44f5cc6c92b00690.tar.bz2 ejdb-3ee3c44cac0896a9c042658f44f5cc6c92b00690.zip |
minor refactoring
-rw-r--r-- | ejdb.project | 4 | ||||
-rw-r--r-- | src/ejdb/tests/ejdbtest1.c | 2 | ||||
-rw-r--r-- | src/ejdb/tests/ejdbtest2.c | 2 | ||||
-rw-r--r-- | src/ejdb/tests/ejdbtest3.c | 2 | ||||
-rw-r--r-- | src/tchdb/tchdb.c | 46 | ||||
-rw-r--r-- | src/tcutil/tcutil.c | 5 | ||||
-rw-r--r-- | src/tcutil/tcutil.h | 2 |
7 files changed, 37 insertions, 26 deletions
diff --git a/ejdb.project b/ejdb.project index 94b8a87..b16105c 100644 --- a/ejdb.project +++ b/ejdb.project @@ -17,7 +17,7 @@ }, { "name": "nix-dbg", "enabled": true, - "buildDirectory": "build-nix-dbg", + "buildDirectory": "build", "sourceDirectory": "$(ProjectPath)", "generator": "Unix Makefiles", "buildType": "Debug", @@ -206,7 +206,7 @@ <LibraryPath Value="Debug"/> </Linker> <ResourceCompiler Options="" Required="no"/> - <General OutputFile="" IntermediateDirectory="./Debug" Command="$(ProjectPath)/build-nix-dbg/src/ejdb/tests/ejdbtest2" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(ProjectPath)/build-nix-dbg/src/ejdb/tests" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/> + <General OutputFile="" IntermediateDirectory="./Debug" Command="$(ProjectPath)/build/src/ejdb/tests/ejdbtest4" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(ProjectPath)/build/src/ejdb/tests" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/> <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"> <![CDATA[]]> </Environment> diff --git a/src/ejdb/tests/ejdbtest1.c b/src/ejdb/tests/ejdbtest1.c index 1d9e6f1..77da154 100644 --- a/src/ejdb/tests/ejdbtest1.c +++ b/src/ejdb/tests/ejdbtest1.c @@ -274,7 +274,7 @@ int main() { return CU_get_error(); /* Add a suite to the registry */ - pSuite = CU_add_suite("t1", init_suite, clean_suite); + pSuite = CU_add_suite("ejdbtest1", init_suite, clean_suite); if (NULL == pSuite) { CU_cleanup_registry(); return CU_get_error(); diff --git a/src/ejdb/tests/ejdbtest2.c b/src/ejdb/tests/ejdbtest2.c index 9e221ea..42c480c 100644 --- a/src/ejdb/tests/ejdbtest2.c +++ b/src/ejdb/tests/ejdbtest2.c @@ -5842,7 +5842,7 @@ int main() { return CU_get_error(); /* Add a suite to the registry */ - pSuite = CU_add_suite("t2", init_suite, clean_suite); + pSuite = CU_add_suite("ejdbtest2", init_suite, clean_suite); if (NULL == pSuite) { CU_cleanup_registry(); return CU_get_error(); diff --git a/src/ejdb/tests/ejdbtest3.c b/src/ejdb/tests/ejdbtest3.c index 222cc6f..7511c9a 100644 --- a/src/ejdb/tests/ejdbtest3.c +++ b/src/ejdb/tests/ejdbtest3.c @@ -398,7 +398,7 @@ int main() { return CU_get_error(); /* Add a suite to the registry */ - pSuite = CU_add_suite("t3", init_suite, clean_suite); + pSuite = CU_add_suite("ejdbtest3", init_suite, clean_suite); if (NULL == pSuite) { CU_cleanup_registry(); return CU_get_error(); diff --git a/src/tchdb/tchdb.c b/src/tchdb/tchdb.c index c2986aa..c63c125 100644 --- a/src/tchdb/tchdb.c +++ b/src/tchdb/tchdb.c @@ -448,14 +448,16 @@ bool tchdbclose(TCHDB *hdb) { bool tchdbput(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz) { assert(hdb && kbuf && ksiz >= 0 && vbuf && vsiz >= 0); if (!HDBLOCKMETHOD(hdb, false)) return false; - uint8_t hash; - char *zbuf = NULL; - uint64_t bidx = tchdbbidx(hdb, kbuf, ksiz, &hash); if (INVALIDHANDLE(hdb->fd) || !(hdb->omode & HDBOWRITER)) { tchdbsetecode(hdb, TCEINVALID, __FILE__, __LINE__, __func__); HDBUNLOCKMETHOD(hdb); return false; } + + uint8_t hash; + char *zbuf = NULL; + uint64_t bidx = tchdbbidx(hdb, kbuf, ksiz, &hash); + if (hdb->async && !tchdbflushdrp(hdb)) { HDBUNLOCKMETHOD(hdb); return false; @@ -475,7 +477,7 @@ bool tchdbput(TCHDB *hdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz zbuf = hdb->enc(vbuf, vsiz, &vsiz, hdb->encop); } if (!zbuf) { - tchdbsetecode(hdb, TCEMISC, __FILE__, __LINE__, __func__); + tchdbsetecode(hdb, TCEDATACOMPRESS, __FILE__, __LINE__, __func__); HDBUNLOCKRECORD(hdb, bidx); HDBUNLOCKMETHOD(hdb); return false; @@ -1435,6 +1437,7 @@ void tchdbsetecode2(TCHDB *hdb, int ecode, const char *filename, int line, const case TCERENAME: case TCEMKDIR: case TCERMDIR: + case TCEICOMPRESS: { if (!notfatal) { hdb->fatal = true; @@ -2197,8 +2200,6 @@ static bool tchdbseekread2(TCHDB *hdb, off_t off, void *buf, size_t size, int op return false; } } - uint64_t xfsiz = __atomic_load_n64(&hdb->xfsiz, __ATOMIC_ACQUIRE); - uint64_t xmsiz = hdb->xmsiz; if (opts & HDBSEEKTRY) { uint64_t fsiz = hdb->fsiz; if (end > fsiz) { @@ -2206,6 +2207,8 @@ static bool tchdbseekread2(TCHDB *hdb, off_t off, void *buf, size_t size, int op goto finish; } } + uint64_t xfsiz = __atomic_load_n64(&hdb->xfsiz, __ATOMIC_ACQUIRE); + uint64_t xmsiz = hdb->xmsiz; if (end <= xmsiz && end <= xfsiz) { memcpy(buf, (void *) (hdb->map + off), size); goto finish; @@ -2746,7 +2749,8 @@ static void tchdbfbpinsert(TCHDB *hdb, uint64_t off, uint32_t rsiz) { /* Search the free block pool for the minimum region. `hdb' specifies the hash database object. `rec' specifies the record object to be stored. - The return value is true if successful, else, it is false. */ + The return value is true if successful, else, it is false. + #DB LOCK */ static bool tchdbfbpsearch(TCHDB *hdb, TCHREC *rec) { assert(hdb && rec); TCDODEBUG(hdb->cnt_searchfbp++); @@ -3826,18 +3830,18 @@ static bool tchdbopenimpl(TCHDB *hdb, const char *path, int omode) { } int besiz = (hdb->opts & HDBTLARGE) ? sizeof (int64_t) : sizeof (int32_t); size_t msiz = HDBHEADSIZ + hdb->bnum * besiz; - if (!(omode & HDBONOLCK)) { - if (memcmp(hbuf, HDBMAGICDATA, strlen(HDBMAGICDATA)) || hdb->type != type || - hdb->frec < msiz + HDBFBPBSIZ || hdb->frec > hdb->fsiz || sbuf.st_size < hdb->fsiz) { - tchdbsetecode(hdb, TCEMETA, __FILE__, __LINE__, __func__); - CLOSEFH2(hdb->fd); - return false; - } + + if (memcmp(hbuf, HDBMAGICDATA, strlen(HDBMAGICDATA)) || hdb->type != type || + hdb->frec < msiz + HDBFBPBSIZ || hdb->frec > hdb->fsiz || sbuf.st_size < hdb->fsiz) { + tchdbsetecode(hdb, TCEMETA, __FILE__, __LINE__, __func__); + CLOSEFH2(hdb->fd); + return false; } + if (((hdb->opts & HDBTDEFLATE) && !_tc_deflate) || ((hdb->opts & HDBTBZIP) && !_tc_bzcompress) || ((hdb->opts & HDBTEXCODEC) && !hdb->enc)) { - tchdbsetecode(hdb, TCEINVALID, __FILE__, __LINE__, __func__); + tchdbsetecode(hdb, TCEICOMPRESS, __FILE__, __LINE__, __func__); CLOSEFH2(hdb->fd); return false; } @@ -4018,10 +4022,10 @@ static bool tchdbputimpl(TCHDB *hdb, const char *kbuf, int ksiz, uint64_t bidx, if (!tchdbreadrec(hdb, &rec, rbuf)) return false; if (hash > rec.hash) { off = rec.left; - entoff = rec.off + (sizeof (uint8_t) + sizeof (uint8_t)); + entoff = rec.off + (sizeof (uint8_t) + sizeof (uint8_t)); //magic + hash } else if (hash < rec.hash) { off = rec.right; - entoff = rec.off + (sizeof (uint8_t) + sizeof (uint8_t)) + + entoff = rec.off + (sizeof (uint8_t) + sizeof (uint8_t)) + //magic + hash + sizeof(left) (hdb->ba64 ? sizeof (uint64_t) : sizeof (uint32_t)); } else { if (!rec.kbuf && !tchdbreadrecbody(hdb, &rec)) return false; @@ -4031,13 +4035,13 @@ static bool tchdbputimpl(TCHDB *hdb, const char *kbuf, int ksiz, uint64_t bidx, TCFREE(rec.bbuf); rec.kbuf = NULL; rec.bbuf = NULL; - entoff = rec.off + (sizeof (uint8_t) + sizeof (uint8_t)); + entoff = rec.off + (sizeof (uint8_t) + sizeof (uint8_t)); //magic + hash } else if (kcmp < 0) { off = rec.right; TCFREE(rec.bbuf); rec.kbuf = NULL; rec.bbuf = NULL; - entoff = rec.off + (sizeof (uint8_t) + sizeof (uint8_t)) + + entoff = rec.off + (sizeof (uint8_t) + sizeof (uint8_t)) + //magic + hash + sizeof(left) (hdb->ba64 ? sizeof (uint64_t) : sizeof (uint32_t)); } else { bool rv; @@ -4158,7 +4162,8 @@ static bool tchdbputimpl(TCHDB *hdb, const char *kbuf, int ksiz, uint64_t bidx, tchdbsetecode(hdb, TCENOREC, __FILE__, __LINE__, __func__); return false; } - rec.rsiz = hdb->ba64 ? sizeof (uint8_t) * 2 + sizeof (uint64_t) * 2 + sizeof (uint16_t) : + rec.rsiz = hdb->ba64 ? + sizeof (uint8_t) * 2 + sizeof (uint64_t) * 2 + sizeof (uint16_t) : sizeof (uint8_t) * 2 + sizeof (uint32_t) * 2 + sizeof (uint16_t); if (ksiz < (1U << 7)) { rec.rsiz += 1; @@ -4182,6 +4187,7 @@ static bool tchdbputimpl(TCHDB *hdb, const char *kbuf, int ksiz, uint64_t bidx, } else { rec.rsiz += 5; } + if (!HDBLOCKDB(hdb)) { return false; } diff --git a/src/tcutil/tcutil.c b/src/tcutil/tcutil.c index 748ed5c..377555a 100644 --- a/src/tcutil/tcutil.c +++ b/src/tcutil/tcutil.c @@ -275,7 +275,8 @@ static void tcvxstrprintf(TCXSTR *xstr, const char *format, va_list ap) { case 'e': case 'E': case 'f': case 'g': case 'G': if (lnum >= 1) { //tlen = snprintf(tbuf, sizeof(tbuf), cbuf, va_arg(ap, long double)); - tlen = tcftoa(va_arg(ap, long double), tbuf, sizeof (tbuf), 6); + //tlen = tcftoa(va_arg(ap, long double), tbuf, sizeof (tbuf), 6); + tlen = tcftoa(va_arg(ap, double), tbuf, sizeof (tbuf), 6); } else { //tlen = snprintf(tbuf, sizeof(tbuf), cbuf, va_arg(ap, double)); tlen = tcftoa(va_arg(ap, double), tbuf, sizeof (tbuf), 6); @@ -9793,6 +9794,8 @@ const char *tcerrmsg(int ecode) { case TCENOREC: return "no record found"; case TCETR: return "illegal transaction state"; case TCEMISC: return "miscellaneous error"; + case TCEICOMPRESS: return "unsupported database compression format"; + case TCEDATACOMPRESS: return "data compression error"; } return "unknown error"; } diff --git a/src/tcutil/tcutil.h b/src/tcutil/tcutil.h index 3709262..8965289 100644 --- a/src/tcutil/tcutil.h +++ b/src/tcutil/tcutil.h @@ -3748,6 +3748,8 @@ enum { /* enumeration for error codes */ TCEKEEP, /* existing record */ TCENOREC, /* no record found */ TCETR, /* illegal transaction state */ + TCEICOMPRESS, /* unsupported database compression format, check the release options. */ + TCEDATACOMPRESS, /* error during record data compression */ TCEMISC = 9999 /* miscellaneous error */ }; |