mdbx-test: add data-check before delete/update.

Change-Id: I5afc1cbd95b5db0b442714229510d6786bf68d43
This commit is contained in:
Leonid Yuriev 2018-09-17 13:06:43 +03:00
parent 68fd9c9908
commit 01ae5bad7d
5 changed files with 23 additions and 1 deletions

View File

@ -114,6 +114,7 @@ bool testcase_hill::run() {
log_trace("uphill: update-a (age %" PRIu64 "->0) %" PRIu64, age_shift,
a_serial);
generate_pair(a_serial, a_key, a_data_0, 0);
checkdata("uphill: update-a", dbi, a_key->value, a_data_1->value);
rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_0->value,
&a_data_1->value, update_flags);
if (unlikely(rc != MDBX_SUCCESS))
@ -126,6 +127,7 @@ bool testcase_hill::run() {
// удаляем вторую запись
log_trace("uphill: delete-b %" PRIu64, b_serial);
checkdata("uphill: delete-b", dbi, b_key->value, b_data->value);
rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value);
if (unlikely(rc != MDBX_SUCCESS))
failure_perror("mdbx_del(b)", rc);
@ -158,6 +160,7 @@ bool testcase_hill::run() {
a_serial);
generate_pair(a_serial, a_key, a_data_0, 0);
generate_pair(a_serial, a_key, a_data_1, age_shift);
checkdata("downhill: update-a", dbi, a_key->value, a_data_0->value);
int rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_1->value,
&a_data_0->value, update_flags);
if (unlikely(rc != MDBX_SUCCESS))
@ -184,6 +187,7 @@ bool testcase_hill::run() {
// удаляем первую запись
log_trace("downhill: delete-a (age %" PRIu64 ") %" PRIu64, age_shift,
a_serial);
checkdata("downhill: delete-a", dbi, a_key->value, a_data_1->value);
rc = mdbx_del(txn_guard.get(), dbi, &a_key->value, &a_data_1->value);
if (unlikely(rc != MDBX_SUCCESS))
failure_perror("mdbx_del(a)", rc);
@ -195,6 +199,7 @@ bool testcase_hill::run() {
// удаляем вторую запись
log_trace("downhill: delete-b %" PRIu64, b_serial);
checkdata("downhill: delete-b", dbi, b_key->value, b_data->value);
rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value);
if (unlikely(rc != MDBX_SUCCESS))
failure_perror("mdbx_del(b)", rc);

View File

@ -410,6 +410,16 @@ void testcase::db_table_close(MDBX_dbi handle) {
log_trace("<< testcase::db_table_close");
}
void testcase::checkdata(const char *step, MDBX_dbi handle, MDBX_val key,
MDBX_val expect) {
MDBX_val data = expect;
int rc = mdbx_get2(txn_guard.get(), handle, &key, &data);
if (unlikely(rc != MDBX_SUCCESS))
failure_perror(step, rc);
if (!is_samedata(&data, &expect))
failure("%s data mismatch", step);
}
//-----------------------------------------------------------------------------
bool test_execute(const actor_config &config) {

View File

@ -112,6 +112,8 @@ protected:
void fetch_canary();
void update_canary(uint64_t increment);
void kick_progress(bool active) const;
void checkdata(const char *step, MDBX_dbi handle, MDBX_val key,
MDBX_val expect);
MDBX_dbi db_table_open(bool create);
void db_table_drop(MDBX_dbi handle);

View File

@ -91,6 +91,11 @@ bool hex2data(const char *hex_begin, const char *hex_end, void *ptr,
return true;
}
bool is_samedata(const MDBX_val *a, const MDBX_val *b) {
return a->iov_len == b->iov_len &&
memcmp(a->iov_base, b->iov_base, a->iov_len) == 0;
}
//-----------------------------------------------------------------------------
/* TODO: replace my 'libmera' from t1ha. */

View File

@ -317,7 +317,7 @@ struct simple_checksum {
std::string data2hex(const void *ptr, size_t bytes, simple_checksum &checksum);
bool hex2data(const char *hex_begin, const char *hex_end, void *ptr,
size_t bytes, simple_checksum &checksum);
bool is_samedata(const MDBX_val *a, const MDBX_val *b);
std::string format(const char *fmt, ...);
uint64_t entropy_ticks(void);