<commit_before>/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2007-2012 Tokutek Inc.  All rights reserved."
#ident "$Id$"

#include <db.h>
#include <portability/toku_atomic.h>

#include "test.h"
#include "threaded_stress_test_helpers.h"

//
// This test tries to emulate iibench at the ydb layer.
//
// The schema is simple:
// 8 byte primary key
// 8 byte key A
// 8 byte key B
// 8 byte key C
//
// There's one primary DB for the pk and three secondary DBs.
//
// The primary key stores the other columns as the value.
// The secondary keys have the primary key appended to them.
//

static const int iibench_num_dbs = 4;
static const size_t iibench_secondary_key_size = sizeof(uint64_t) * 2;

struct iibench_row {
    int64_t pk;
    int64_t a;
    int64_t b;
    int64_t c;
};

static int64_t hash(int64_t key) {
    int64_t hash = 0;
    char *buf = (char *) &key;
    for (int i = 0; i < 8; i++) {
        hash += (((buf[i] + 1) * 17) & 0xFF) << (i * 8);
    }
    return hash;
}

static void iibench_generate_secondary_keys(int64_t pk, struct iibench_row *row) {
    row->a = hash(pk);
    row->b = hash(pk * 2);
    row->c = hash(pk * 3);
}

static void iibench_verify_row(struct iibench_row *row) {
    (void) iibench_verify_row;
    
    struct iibench_row expected_row;
    iibench_generate_secondary_keys(row->pk, &expected_row);
    invariant(row->a == expected_row.a);
    invariant(row->b == expected_row.b);
    invariant(row->c == expected_row.c);
}

static void iibench_fill_key_buf(int64_t pk, int64_t *buf) {
    memcpy(&buf[0], &pk, sizeof(int64_t));
}

static void iibench_fill_val_buf(int64_t pk, int64_t *buf) {
    struct iibench_row row;
    iibench_generate_secondary_keys(pk, &row);
    memcpy(&buf[0], &row.a, sizeof(row.a));
    memcpy(&buf[1], &row.b, sizeof(row.b));
    memcpy(&buf[2], &row.c, sizeof(row.c));
}

struct iibench_op_extra {
    uint64_t autoincrement;
};

static int UU() iibench_put_op(DB_TXN *txn, ARG arg, void *operation_extra, void *stats_extra) {
    DB **dbs = arg->dbp;
    DB_ENV *env = arg->env;
    DBT mult_key_dbt[iibench_num_dbs];
    DBT mult_val_dbt[iibench_num_dbs];
    uint32_t mult_put_flags[iibench_num_dbs];
    memset(mult_key_dbt, 0, sizeof(mult_key_dbt));
    memset(mult_val_dbt, 0, sizeof(mult_val_dbt));<commit_msg>refs #5702 add unused() to verify row, for now<commit_after>/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2007-2012 Tokutek Inc.  All rights reserved."
#ident "$Id$"

#include <db.h>
#include <portability/toku_atomic.h>

#include "test.h"
#include "threaded_stress_test_helpers.h"

//
// This test tries to emulate iibench at the ydb layer.
//
// The schema is simple:
// 8 byte primary key
// 8 byte key A
// 8 byte key B
// 8 byte key C
//
// There's one primary DB for the pk and three secondary DBs.
//
// The primary key stores the other columns as the value.
// The secondary keys have the primary key appended to them.
//

static const int iibench_num_dbs = 4;
static const size_t iibench_secondary_key_size = sizeof(uint64_t) * 2;

struct iibench_row {
    int64_t pk;
    int64_t a;
    int64_t b;
    int64_t c;
};

static int64_t hash(int64_t key) {
    int64_t hash = 0;
    char *buf = (char *) &key;
    for (int i = 0; i < 8; i++) {
        hash += (((buf[i] + 1) * 17) & 0xFF) << (i * 8);
    }
    return hash;
}

static void iibench_generate_secondary_keys(int64_t pk, struct iibench_row *row) {
    row->a = hash(pk);
    row->b = hash(pk * 2);
    row->c = hash(pk * 3);
}

static void UU() iibench_verify_row(struct iibench_row *row) {
    struct iibench_row expected_row;
    iibench_generate_secondary_keys(row->pk, &expected_row);
    invariant(row->a == expected_row.a);
    invariant(row->b == expected_row.b);
    invariant(row->c == expected_row.c);
}

static void iibench_fill_key_buf(int64_t pk, int64_t *buf) {
    memcpy(&buf[0], &pk, sizeof(int64_t));
}

static void iibench_fill_val_buf(int64_t pk, int64_t *buf) {
    struct iibench_row row;
    iibench_generate_secondary_keys(pk, &row);
    memcpy(&buf[0], &row.a, sizeof(row.a));
    memcpy(&buf[1], &row.b, sizeof(row.b));
    memcpy(&buf[2], &row.c, sizeof(row.c));
}

struct iibench_op_extra {
    uint64_t autoincrement;
};

static int UU() iibench_put_op(DB_TXN *txn, ARG arg, void *operation_extra, void *stats_extra) {
    DB **dbs = arg->dbp;
    DB_ENV *env = arg->env;
    DBT mult_key_dbt[iibench_num_dbs];
    DBT mult_val_dbt[iibench_num_dbs];
    uint32_t mult_put_flags[iibench_num_dbs];
    memset(mult_key_dbt, 0, sizeof(mult_key_dbt));
    memset(mult_val_dbt, 0, sizeof(mult_val_dbt));
{'fraction_non_alphanumeric': 0.14330675618967686, 'fraction_numerical': 0.02853545950482585, 'mean_word_length': 3.641674780915287, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1650865', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1898, 'n_words': 470}