1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
#ifndef INCLUDES_TARANTOOL_TEST_VY_ITERATORS_HELPER_H
#define INCLUDES_TARANTOOL_TEST_VY_ITERATORS_HELPER_H
/*
* Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/uio.h>
#include "unit.h"
#include "vy_stmt.h"
#include "small/rlist.h"
#include "small/lsregion.h"
#include "vy_mem.h"
#include "vy_cache.h"
#include "vy_read_view.h"
#define vyend 99999999
#define MAX_FIELDS_COUNT 100
#define STMT_TEMPLATE(lsn, type, ...) \
{ { __VA_ARGS__, vyend }, IPROTO_##type, lsn, 0, 0, 0 }
#define STMT_TEMPLATE_FLAGS(lsn, type, flags, ...) \
{ { __VA_ARGS__, vyend }, IPROTO_##type, lsn, flags, 0, 0 }
#define STMT_TEMPLATE_DEFERRED_DELETE(lsn, type, ...) \
STMT_TEMPLATE_FLAGS(lsn, type, VY_STMT_DEFERRED_DELETE, __VA_ARGS__)
extern struct vy_stmt_env stmt_env;
extern struct vy_mem_env mem_env;
extern struct vy_cache_env cache_env;
#if defined(__cplusplus)
extern "C" {
#endif
/**
* Initialize subsystems neccessary for correct vinyl iterators
* working.
* @param cache_size Vinyl cache quota limit.
*/
void
vy_iterator_C_test_init(size_t cache_size);
/** Close subsystems, opened in vy_iterator_C_test_init(). */
void
vy_iterator_C_test_finish();
/** Template for creation a vinyl statement. */
struct vy_stmt_template {
/** Array of statement fields, ended with 'vyend'. */
const int fields[MAX_FIELDS_COUNT];
/** Statement type: REPLACE/UPSERT/DELETE/UPSERT. */
enum iproto_type type;
/** Statement lsn. */
int64_t lsn;
/** Statement flags. */
uint8_t flags;
/*
* In case of upsert it is possible to use only one 'add' operation.
* This is the column number of the operation.
*/
uint32_t upsert_field;
/** And that is the value to add. */
int32_t upsert_value;
};
/**
* Create a new vinyl statement using the specified template.
*
* @param format
* @param key_def Key definition (for computing hint).
* @param templ Statement template.
*
* @return Created statement.
*/
struct vy_entry
vy_new_simple_stmt(struct tuple_format *format, struct key_def *key_def,
const struct vy_stmt_template *templ);
/**
* Insert into the mem the statement, created by the specified
* template.
*
* @param vy_mem Mem to insert into.
* @param templ Statement template to insert.
*
* @retval Lsregion allocated statement.
*/
struct vy_entry
vy_mem_insert_template(struct vy_mem *mem,
const struct vy_stmt_template *templ);
/**
* Insert into the cache the statement template chain, got from
* the read iterator.
* @param cache Cache to insert into.
* @param format Statements format.
* @param chain Statement template array.
* @param length Length of @a chain.
* @param key_templ Key template.
* @param order Iteration order.
*/
void
vy_cache_insert_templates_chain(struct vy_cache *cache,
struct tuple_format *format,
const struct vy_stmt_template *chain,
uint length,
const struct vy_stmt_template *key_templ,
enum iterator_type order);
/**
* Vy_cache_on_write wrapper for statement templates.
* @param cache Cache to update to.
* @param templ Written statement template.
*/
void
vy_cache_on_write_template(struct vy_cache *cache, struct tuple_format *format,
const struct vy_stmt_template *templ);
/**
* Create a list of read views using the specified vlsns.
*
* @param rlist[out] Result list of read views.
* @param rvs[out] Read views array.
* @param vlsns Array of read view lsns, sorted in ascending
* order.
* @param count Size of the @vlsns.
*/
void
init_read_views_list(struct rlist *rlist, struct vy_read_view *rvs,
const int *vlsns, int count);
/**
* Create vy_mem with the specified key_def, using the @region as
* allocator.
*
* @param def Key definition.
*
* @return New vy_mem.
*/
struct vy_mem *
create_test_mem(struct key_def *def);
/**
* Create vy_cache, key_def and tuple_format, using a specified
* array of key fields.
* @param fields Array of key field numbers.
* @param types Array of key field types.
* @param key_cnt Length of @a fields and @a types.
* @param[out] cache Cache to create.
* @param[out] def Key def to create.
* @param[out] format Tuple format to create.
*/
void
create_test_cache(uint32_t *fields, uint32_t *types,
int key_cnt, struct vy_cache *cache, struct key_def **def,
struct tuple_format **format);
/**
* Destroy cache and its resources.
* @param vy_cache Cache to destroy.
* @param key_def Key def to delete.
* @param format Tuple format to unref.
*/
void
destroy_test_cache(struct vy_cache *cache, struct key_def *def,
struct tuple_format *format);
/**
* Check that the template specifies completely the same statement
* as @stmt.
*
* @param actual Actual value.
* @param templ Expected value.
* @param format Template statement format.
* @param key_def Key definition (for computing hint).
*
* @retval stmt === template.
*/
bool
vy_stmt_are_same(struct vy_entry actual,
const struct vy_stmt_template *expected,
struct tuple_format *format, struct key_def *key_def);
#if defined(__cplusplus)
}
#endif
#endif
|