xref: /4.0.0/forestdb/tests/e2e/e2espec.h (revision 6270ab5a)
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2010 Couchbase, Inc
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17
18#include "libforestdb/forestdb.h"
19
20//#define __DEBUG_E2E
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26static const char E2EDB_MAIN[] = "e2edb_main";
27static const char E2EDB_RECORDS[] = "e2edb_records";
28static const char E2EKV_ALLDOCS[] = "e2ekv_alldocs";
29static const char E2EKV_INDEX1[] = "e2ekv_index1";
30static const char E2EKV_INDEX2[] = "e2ekv_index2";
31static const char E2EKV_RECORDS[] = "e2ekv_rtx";
32static const char E2EKV_CHECKPOINTS[] = "e2ekv_chk";
33static const char RECORD_DOCKEY[] = "e2edoc_records";
34static const int KEYSPACE_LEN = 6;
35static const int MAXKEY_LEN = 1024;
36static const int MAXITR_LEN = 12;
37
38static const int LOAD_FACTOR = 1;
39
40typedef uint16_t tx_type_t;
41enum {
42    SET_PERSON = 0x01,
43    DEL_PERSON = 0x02,
44    ACC_DEPOSIT = 0x03,
45    ACC_WITHDRAW = 0x04,
46    START_CHECKPOINT = 0x05,
47    END_CHECKPOINT = 0x06
48};
49
50typedef struct {
51    char key[MAXKEY_LEN];
52    char name[MAXKEY_LEN];
53    char city[256];
54    char state[256];
55    char desc[1024];
56    char keyspace[KEYSPACE_LEN];
57    int age;
58}person_t;
59
60typedef struct {
61    char min[MAXITR_LEN];
62    char max[MAXITR_LEN];
63}idx_prams_t;
64
65typedef struct {
66    int amount;
67    char refkey[MAXKEY_LEN];
68    size_t refkey_len;
69    tx_type_t type;
70}transaction_t;
71
72typedef struct {
73    char key[MAXKEY_LEN];
74    int ndocs;
75    int num_indexed;
76    int sum_age_indexed;
77    uint16_t balance;
78    fdb_seqnum_t seqnum_all;
79    fdb_seqnum_t seqnum_idx1;
80    fdb_seqnum_t seqnum_idx2;
81    tx_type_t type;
82}checkpoint_t;
83
84
85typedef struct {
86
87    fdb_file_handle *main;
88    fdb_kvs_handle *all_docs;
89    fdb_kvs_handle *index1;
90    fdb_kvs_handle *index2;
91
92    fdb_file_handle *records;
93    fdb_kvs_handle *rtx;
94    fdb_kvs_handle *chk;
95    checkpoint_t *v_chk;
96    idx_prams_t *index_params;
97
98    char keyspace[KEYSPACE_LEN];
99    bool walflush;
100    bool verify_set;
101}storage_t;
102
103// generators
104void gen_random(char *s, const int len);
105void gen_index_params(idx_prams_t *params);
106void gen_person(person_t *p);
107
108// fdb wrappers
109void e2e_fdb_set_person(storage_t *st, person_t *p);
110void e2e_fdb_del_person(storage_t *st, person_t *p);
111void e2e_fdb_cancel_checkpoint(storage_t *st);
112void e2e_fdb_commit(fdb_file_handle* fhandle, bool walflush);
113void e2e_fdb_close(storage_t *st);
114void e2e_fdb_shutdown(storage_t *st);
115
116// checkpointing
117void start_checkpoint(storage_t *st);
118void end_checkpoint(storage_t *st);
119checkpoint_t* create_checkpoint(storage_t *st, tx_type_t type);
120
121// storage
122storage_t *init_storage(fdb_config *m_fconfig, fdb_config *r_fconfig,
123        fdb_kvs_config *kvs_config, idx_prams_t *idxp,
124        checkpoint_t *v_chk, bool walflush);
125
126void reset_storage_index(storage_t *st);
127void rm_storage_fs();
128
129// utility
130bool is_indexed(idx_prams_t *idxp, person_t *p);
131void save_tx(storage_t *st, void *key, size_t keylen, tx_type_t type);
132fdb_kvs_handle *scan(storage_t *st, fdb_kvs_handle *reuse_kv);
133
134#ifdef __cplusplus
135}
136#endif
137