| kchashdb.h | | kchashdb.h | |
| | | | |
| skipping to change at line 137 | | skipping to change at line 137 | |
| * the same record are blocked. To avoid deadlock, any explicit databa
se operation must not | | * the same record are blocked. To avoid deadlock, any explicit databa
se operation must not | |
| * be performed in this function. | | * be performed in this function. | |
| */ | | */ | |
| bool accept(Visitor* visitor, bool writable = true, bool step = false)
{ | | bool accept(Visitor* visitor, bool writable = true, bool step = false)
{ | |
| _assert_(visitor); | | _assert_(visitor); | |
| ScopedSpinRWLock lock(&db_->mlock_, true); | | ScopedSpinRWLock lock(&db_->mlock_, true); | |
| if (db_->omode_ == 0) { | | if (db_->omode_ == 0) { | |
| db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | | db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |
| return false; | | return false; | |
| } | | } | |
|
| if (writable && !(db_->writer_)) { | | if (writable) { | |
| db_->set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); | | if (!db_->writer_) { | |
| return false; | | db_->set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); | |
| | | return false; | |
| | | } | |
| | | if (!(db_->flags_ & FOPEN) && !db_->autotran_ && !db_->tran_ && | |
| | | !db_->set_flag(FOPEN, true)) { | |
| | | return false; | |
| | | } | |
| } | | } | |
| if (off_ < 1) { | | if (off_ < 1) { | |
| db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | | db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | |
| return false; | | return false; | |
| } | | } | |
| Record rec; | | Record rec; | |
| char rbuf[HDBRECBUFSIZ]; | | char rbuf[HDBRECBUFSIZ]; | |
| if (!step_impl(&rec, rbuf, 0)) return false; | | if (!step_impl(&rec, rbuf, 0)) return false; | |
| if (!rec.vbuf && !db_->read_record_body(&rec)) { | | if (!rec.vbuf && !db_->read_record_body(&rec)) { | |
| delete[] rec.bbuf; | | delete[] rec.bbuf; | |
| | | | |
| skipping to change at line 525 | | skipping to change at line 531 | |
| * performed in this function. | | * performed in this function. | |
| */ | | */ | |
| bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writabl
e = true) { | | bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writabl
e = true) { | |
| _assert_(kbuf && ksiz <= MEMMAXSIZ && visitor); | | _assert_(kbuf && ksiz <= MEMMAXSIZ && visitor); | |
| mlock_.lock_reader(); | | mlock_.lock_reader(); | |
| if (omode_ == 0) { | | if (omode_ == 0) { | |
| set_error(_KCCODELINE_, Error::INVALID, "not opened"); | | set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |
| mlock_.unlock(); | | mlock_.unlock(); | |
| return false; | | return false; | |
| } | | } | |
|
| if (writable && !writer_) { | | if (writable) { | |
| set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); | | if (!writer_) { | |
| mlock_.unlock(); | | set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); | |
| return false; | | mlock_.unlock(); | |
| | | return false; | |
| | | } | |
| | | if (!(flags_ & FOPEN) && !autotran_ && !tran_ && !set_flag(FOPEN, tru | |
| | | e)) { | |
| | | mlock_.unlock(); | |
| | | return false; | |
| | | } | |
| } | | } | |
| bool err = false; | | bool err = false; | |
| uint64_t hash = hash_record(kbuf, ksiz); | | uint64_t hash = hash_record(kbuf, ksiz); | |
| uint32_t pivot = fold_hash(hash); | | uint32_t pivot = fold_hash(hash); | |
| int64_t bidx = hash % bnum_; | | int64_t bidx = hash % bnum_; | |
| size_t lidx = bidx % HDBRLOCKSLOT; | | size_t lidx = bidx % HDBRLOCKSLOT; | |
| if (writable) { | | if (writable) { | |
| rlock_.lock_writer(lidx); | | rlock_.lock_writer(lidx); | |
| } else { | | } else { | |
| rlock_.lock_reader(lidx); | | rlock_.lock_reader(lidx); | |
| | | | |
| skipping to change at line 574 | | skipping to change at line 586 | |
| bool writable = true) { | | bool writable = true) { | |
| _assert_(visitor); | | _assert_(visitor); | |
| size_t knum = keys.size(); | | size_t knum = keys.size(); | |
| if (knum < 1) return true; | | if (knum < 1) return true; | |
| mlock_.lock_reader(); | | mlock_.lock_reader(); | |
| if (omode_ == 0) { | | if (omode_ == 0) { | |
| set_error(_KCCODELINE_, Error::INVALID, "not opened"); | | set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |
| mlock_.unlock(); | | mlock_.unlock(); | |
| return false; | | return false; | |
| } | | } | |
|
| if (writable && !writer_) { | | if (writable) { | |
| set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); | | if (!writer_) { | |
| mlock_.unlock(); | | set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); | |
| return false; | | mlock_.unlock(); | |
| | | return false; | |
| | | } | |
| | | if (!(flags_ & FOPEN) && !autotran_ && !tran_ && !set_flag(FOPEN, tru | |
| | | e)) { | |
| | | mlock_.unlock(); | |
| | | return false; | |
| | | } | |
| } | | } | |
| bool err = false; | | bool err = false; | |
| struct RecordKey { | | struct RecordKey { | |
| const char* kbuf; | | const char* kbuf; | |
| size_t ksiz; | | size_t ksiz; | |
| uint32_t pivot; | | uint32_t pivot; | |
| uint64_t bidx; | | uint64_t bidx; | |
| }; | | }; | |
| RecordKey* rkeys = new RecordKey[knum]; | | RecordKey* rkeys = new RecordKey[knum]; | |
| std::set<size_t> lidxs; | | std::set<size_t> lidxs; | |
| | | | |
| skipping to change at line 649 | | skipping to change at line 667 | |
| * @note The whole iteration is performed atomically and other threads ar
e blocked. To avoid | | * @note The whole iteration is performed atomically and other threads ar
e blocked. To avoid | |
| * deadlock, any explicit database operation must not be performed in thi
s function. | | * deadlock, any explicit database operation must not be performed in thi
s function. | |
| */ | | */ | |
| bool iterate(Visitor *visitor, bool writable = true, ProgressChecker* che
cker = NULL) { | | bool iterate(Visitor *visitor, bool writable = true, ProgressChecker* che
cker = NULL) { | |
| _assert_(visitor); | | _assert_(visitor); | |
| ScopedSpinRWLock lock(&mlock_, true); | | ScopedSpinRWLock lock(&mlock_, true); | |
| if (omode_ == 0) { | | if (omode_ == 0) { | |
| set_error(_KCCODELINE_, Error::INVALID, "not opened"); | | set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |
| return false; | | return false; | |
| } | | } | |
|
| if (writable && !writer_) { | | if (writable) { | |
| set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); | | if (!writer_) { | |
| return false; | | set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); | |
| | | return false; | |
| | | } | |
| | | if (!(flags_ & FOPEN) && !autotran_ && !tran_ && !set_flag(FOPEN, tru | |
| | | e)) { | |
| | | mlock_.unlock(); | |
| | | return false; | |
| | | } | |
| } | | } | |
| bool err = false; | | bool err = false; | |
| if (!iterate_impl(visitor, checker)) err = true; | | if (!iterate_impl(visitor, checker)) err = true; | |
| trigger_meta(MetaTrigger::ITERATE, "iterate"); | | trigger_meta(MetaTrigger::ITERATE, "iterate"); | |
| return !err; | | return !err; | |
| } | | } | |
| /** | | /** | |
| * Get the last happened error. | | * Get the last happened error. | |
| * @return the last happened error. | | * @return the last happened error. | |
| */ | | */ | |
| | | | |
| skipping to change at line 2290 | | skipping to change at line 2314 | |
| std::memcpy(head + HDBMOFFLIBVER, &libver_, sizeof(libver_)); | | std::memcpy(head + HDBMOFFLIBVER, &libver_, sizeof(libver_)); | |
| std::memcpy(head + HDBMOFFLIBREV, &librev_, sizeof(librev_)); | | std::memcpy(head + HDBMOFFLIBREV, &librev_, sizeof(librev_)); | |
| std::memcpy(head + HDBMOFFFMTVER, &fmtver_, sizeof(fmtver_)); | | std::memcpy(head + HDBMOFFFMTVER, &fmtver_, sizeof(fmtver_)); | |
| std::memcpy(head + HDBMOFFCHKSUM, &chksum_, sizeof(chksum_)); | | std::memcpy(head + HDBMOFFCHKSUM, &chksum_, sizeof(chksum_)); | |
| std::memcpy(head + HDBMOFFTYPE, &type_, sizeof(type_)); | | std::memcpy(head + HDBMOFFTYPE, &type_, sizeof(type_)); | |
| std::memcpy(head + HDBMOFFAPOW, &apow_, sizeof(apow_)); | | std::memcpy(head + HDBMOFFAPOW, &apow_, sizeof(apow_)); | |
| std::memcpy(head + HDBMOFFFPOW, &fpow_, sizeof(fpow_)); | | std::memcpy(head + HDBMOFFFPOW, &fpow_, sizeof(fpow_)); | |
| std::memcpy(head + HDBMOFFOPTS, &opts_, sizeof(opts_)); | | std::memcpy(head + HDBMOFFOPTS, &opts_, sizeof(opts_)); | |
| uint64_t num = hton64(bnum_); | | uint64_t num = hton64(bnum_); | |
| std::memcpy(head + HDBMOFFBNUM, &num, sizeof(num)); | | std::memcpy(head + HDBMOFFBNUM, &num, sizeof(num)); | |
|
| uint8_t flags = flags_; | | if (!flagopen_) flags_ &= ~FOPEN; | |
| if (!flagopen_) flags &= ~FOPEN; | | std::memcpy(head + HDBMOFFFLAGS, &flags_, sizeof(flags_)); | |
| std::memcpy(head + HDBMOFFFLAGS, &flags, sizeof(flags)); | | | |
| num = hton64(count_); | | num = hton64(count_); | |
| std::memcpy(head + HDBMOFFCOUNT, &num, sizeof(num)); | | std::memcpy(head + HDBMOFFCOUNT, &num, sizeof(num)); | |
| num = hton64(lsiz_); | | num = hton64(lsiz_); | |
| std::memcpy(head + HDBMOFFSIZE, &num, sizeof(num)); | | std::memcpy(head + HDBMOFFSIZE, &num, sizeof(num)); | |
| std::memcpy(head + HDBMOFFOPAQUE, opaque_, sizeof(opaque_)); | | std::memcpy(head + HDBMOFFOPAQUE, opaque_, sizeof(opaque_)); | |
| if (!file_.write(0, head, sizeof(head))) { | | if (!file_.write(0, head, sizeof(head))) { | |
| set_error(_KCCODELINE_, Error::SYSTEM, file_.error()); | | set_error(_KCCODELINE_, Error::SYSTEM, file_.error()); | |
| return false; | | return false; | |
| } | | } | |
| trcount_ = count_; | | trcount_ = count_; | |
| | | | |
End of changes. 5 change blocks. |
| 17 lines changed or deleted | | 43 lines changed or added | |
|