2019-09-09 18:40:24 +08:00
|
|
|
|
/*
|
2019-02-04 03:37:57 +08:00
|
|
|
|
* Copyright 2017-2019 Leonid Yuriev <leo@yuriev.ru>
|
|
|
|
|
* and other libmdbx authors: please see AUTHORS file.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
|
* Public License.
|
|
|
|
|
*
|
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
|
|
bool testcase_append::run() {
|
2019-06-23 20:55:13 +08:00
|
|
|
|
MDBX_dbi dbi;
|
|
|
|
|
int err = db_open__begin__table_create_open_clean(dbi);
|
|
|
|
|
if (unlikely(err != MDBX_SUCCESS)) {
|
|
|
|
|
log_notice("append: bailout-prepare due '%s'", mdbx_strerror(err));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-02-04 03:37:57 +08:00
|
|
|
|
|
|
|
|
|
keyvalue_maker.setup(config.params, config.actor_id, 0 /* thread_number */);
|
|
|
|
|
/* LY: тест наполнения таблиц в append-режиме,
|
|
|
|
|
* при котором записи добавляются строго в конец (в порядке сортировки) */
|
|
|
|
|
const unsigned flags = (config.params.table_flags & MDBX_DUPSORT)
|
|
|
|
|
? MDBX_APPEND | MDBX_APPENDDUP
|
|
|
|
|
: MDBX_APPEND;
|
|
|
|
|
keyvalue_maker.make_ordered();
|
|
|
|
|
|
|
|
|
|
key = keygen::alloc(config.params.keylen_max);
|
|
|
|
|
data = keygen::alloc(config.params.datalen_max);
|
|
|
|
|
keygen::buffer last_key = keygen::alloc(config.params.keylen_max);
|
|
|
|
|
keygen::buffer last_data = keygen::alloc(config.params.datalen_max);
|
|
|
|
|
last_key->value.iov_base = last_key->bytes;
|
|
|
|
|
last_key->value.iov_len = 0;
|
|
|
|
|
last_data->value.iov_base = last_data->bytes;
|
|
|
|
|
last_data->value.iov_len = 0;
|
|
|
|
|
|
|
|
|
|
simple_checksum inserted_checksum;
|
|
|
|
|
uint64_t inserted_number = 0;
|
|
|
|
|
uint64_t serial_count = 0;
|
2019-06-23 20:55:13 +08:00
|
|
|
|
|
2019-02-04 03:37:57 +08:00
|
|
|
|
unsigned txn_nops = 0;
|
2019-06-23 20:55:13 +08:00
|
|
|
|
uint64_t commited_inserted_number = inserted_number;
|
|
|
|
|
simple_checksum commited_inserted_checksum = inserted_checksum;
|
2019-02-04 03:37:57 +08:00
|
|
|
|
while (should_continue()) {
|
|
|
|
|
const keygen::serial_t serial = serial_count;
|
|
|
|
|
if (!keyvalue_maker.increment(serial_count, 1)) {
|
|
|
|
|
// дошли до границы пространства ключей
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log_trace("append: append-a %" PRIu64, serial);
|
|
|
|
|
generate_pair(serial, key, data);
|
|
|
|
|
int cmp = inserted_number ? mdbx_cmp(txn_guard.get(), dbi, &key->value,
|
|
|
|
|
&last_key->value)
|
|
|
|
|
: 1;
|
|
|
|
|
if (cmp == 0 && (config.params.table_flags & MDBX_DUPSORT))
|
|
|
|
|
cmp = mdbx_dcmp(txn_guard.get(), dbi, &data->value, &last_data->value);
|
|
|
|
|
|
2019-06-23 20:55:13 +08:00
|
|
|
|
err = mdbx_put(txn_guard.get(), dbi, &key->value, &data->value, flags);
|
|
|
|
|
if (err == MDBX_MAP_FULL && config.params.ignore_dbfull) {
|
|
|
|
|
log_notice("append: bailout-insert due '%s'", mdbx_strerror(err));
|
|
|
|
|
txn_end(true);
|
|
|
|
|
inserted_number = commited_inserted_number;
|
|
|
|
|
inserted_checksum = commited_inserted_checksum;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-04 03:37:57 +08:00
|
|
|
|
if (cmp > 0) {
|
2019-06-22 18:13:15 +08:00
|
|
|
|
if (unlikely(err != MDBX_SUCCESS))
|
|
|
|
|
failure_perror("mdbx_put(appenda-a)", err);
|
2019-06-23 20:55:13 +08:00
|
|
|
|
|
2019-02-04 03:37:57 +08:00
|
|
|
|
memcpy(last_key->value.iov_base, key->value.iov_base,
|
|
|
|
|
last_key->value.iov_len = key->value.iov_len);
|
|
|
|
|
memcpy(last_data->value.iov_base, data->value.iov_base,
|
|
|
|
|
last_data->value.iov_len = data->value.iov_len);
|
|
|
|
|
++inserted_number;
|
|
|
|
|
inserted_checksum.push((uint32_t)inserted_number, key->value);
|
|
|
|
|
inserted_checksum.push(10639, data->value);
|
|
|
|
|
} else {
|
2019-06-22 18:13:15 +08:00
|
|
|
|
if (unlikely(err != MDBX_EKEYMISMATCH))
|
|
|
|
|
failure_perror("mdbx_put(appenda-a) != MDBX_EKEYMISMATCH", err);
|
2019-02-04 03:37:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (++txn_nops >= config.params.batch_write) {
|
2019-06-23 20:55:13 +08:00
|
|
|
|
err = breakable_restart();
|
|
|
|
|
if (unlikely(err != MDBX_SUCCESS)) {
|
|
|
|
|
log_notice("append: bailout-commit due '%s'", mdbx_strerror(err));
|
|
|
|
|
inserted_number = commited_inserted_number;
|
|
|
|
|
inserted_checksum = commited_inserted_checksum;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
commited_inserted_number = inserted_number;
|
|
|
|
|
commited_inserted_checksum = inserted_checksum;
|
2019-02-04 03:37:57 +08:00
|
|
|
|
txn_nops = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report(1);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-23 20:55:13 +08:00
|
|
|
|
if (txn_guard) {
|
|
|
|
|
err = breakable_commit();
|
|
|
|
|
if (unlikely(err != MDBX_SUCCESS)) {
|
|
|
|
|
log_notice("append: bailout-commit due '%s'", mdbx_strerror(err));
|
|
|
|
|
inserted_number = commited_inserted_number;
|
|
|
|
|
inserted_checksum = commited_inserted_checksum;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-04 03:37:57 +08:00
|
|
|
|
//----------------------------------------------------------------------------
|
2019-06-23 20:55:13 +08:00
|
|
|
|
txn_begin(true);
|
2019-02-04 03:37:57 +08:00
|
|
|
|
cursor_open(dbi);
|
|
|
|
|
|
|
|
|
|
MDBX_val check_key, check_data;
|
2019-06-23 20:55:13 +08:00
|
|
|
|
err =
|
2019-06-22 18:13:15 +08:00
|
|
|
|
mdbx_cursor_get(cursor_guard.get(), &check_key, &check_data, MDBX_FIRST);
|
2019-06-23 20:55:13 +08:00
|
|
|
|
if (likely(inserted_number)) {
|
|
|
|
|
if (unlikely(err != MDBX_SUCCESS))
|
|
|
|
|
failure_perror("mdbx_cursor_get(MDBX_FIRST)", err);
|
|
|
|
|
}
|
2019-02-04 03:37:57 +08:00
|
|
|
|
|
|
|
|
|
simple_checksum read_checksum;
|
|
|
|
|
uint64_t read_count = 0;
|
2019-06-22 18:13:15 +08:00
|
|
|
|
while (err == MDBX_SUCCESS) {
|
2019-02-04 03:37:57 +08:00
|
|
|
|
++read_count;
|
|
|
|
|
read_checksum.push((uint32_t)read_count, check_key);
|
|
|
|
|
read_checksum.push(10639, check_data);
|
|
|
|
|
|
2019-06-22 18:13:15 +08:00
|
|
|
|
err =
|
2019-02-04 03:37:57 +08:00
|
|
|
|
mdbx_cursor_get(cursor_guard.get(), &check_key, &check_data, MDBX_NEXT);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-22 18:13:15 +08:00
|
|
|
|
if (unlikely(err != MDBX_NOTFOUND))
|
|
|
|
|
failure_perror("mdbx_cursor_get(MDBX_NEXT) != EOF", err);
|
2019-02-04 03:37:57 +08:00
|
|
|
|
|
|
|
|
|
if (unlikely(read_count != inserted_number))
|
|
|
|
|
failure("read_count(%" PRIu64 ") != inserted_number(%" PRIu64 ")",
|
|
|
|
|
read_count, inserted_number);
|
|
|
|
|
|
|
|
|
|
if (unlikely(read_checksum.value != inserted_checksum.value))
|
|
|
|
|
failure("read_checksum(0x%016" PRIu64 ") "
|
|
|
|
|
"!= inserted_checksum(0x%016" PRIu64 ")",
|
|
|
|
|
read_checksum.value, inserted_checksum.value);
|
|
|
|
|
|
|
|
|
|
cursor_close();
|
2019-06-23 20:55:13 +08:00
|
|
|
|
txn_end(true);
|
2019-02-04 03:37:57 +08:00
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
if (dbi) {
|
|
|
|
|
if (config.params.drop_table && !mode_readonly()) {
|
|
|
|
|
txn_begin(false);
|
|
|
|
|
db_table_drop(dbi);
|
2019-06-23 20:55:13 +08:00
|
|
|
|
err = breakable_commit();
|
|
|
|
|
if (unlikely(err != MDBX_SUCCESS)) {
|
|
|
|
|
log_notice("append: bailout-clean due '%s'", mdbx_strerror(err));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-02-04 03:37:57 +08:00
|
|
|
|
} else
|
|
|
|
|
db_table_close(dbi);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|