• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tarantool / tarantool / 9433

pending completion
9433

push

travis-ci

locker
box: implement persistent sequences

This patch implements a new object type, persistent sequences. Sequences
are created with function box.schema.sequence.create(name, options).
Options include min/max, start value, increment, cache size, just like
in Postgresql, although 'cache' is ignored for now. All sequences can be
accessed via box.sequence.<name>, similarly to spaces. To generate a
sequence value, use seq:next() method. To retrieve the last generated
value, use seq:get(). A sequence value can also be reset to the start
value or to any other value using seq:reset() and seq:set() methods.

Needed for #389

268 of 268 new or added lines in 9 files covered. (100.0%)

32846 of 37402 relevant lines covered (87.82%)

1100205.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/box/errcode.h
1
#ifndef TARANTOOL_BOX_ERRCODE_H_INCLUDED
2
#define TARANTOOL_BOX_ERRCODE_H_INCLUDED
3
/*
4
 * Copyright 2010-2016, Tarantool AUTHORS, please see AUTHORS file.
5
 *
6
 * Redistribution and use in source and binary forms, with or
7
 * without modification, are permitted provided that the following
8
 * conditions are met:
9
 *
10
 * 1. Redistributions of source code must retain the above
11
 *    copyright notice, this list of conditions and the
12
 *    following disclaimer.
13
 *
14
 * 2. Redistributions in binary form must reproduce the above
15
 *    copyright notice, this list of conditions and the following
16
 *    disclaimer in the documentation and/or other materials
17
 *    provided with the distribution.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
20
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
 * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31
 * SUCH DAMAGE.
32
 */
33
#include <stdint.h>
34

35
#include "trivia/util.h"
36

37
#ifdef __cplusplus
38
extern "C" {
39
#endif
40

41
struct errcode_record {
42
        const char *errstr;
43
        const char *errdesc;
44
};
45

46
/*
47
 * To add a new error code to Tarantool, extend this array.
48
 *
49
 * !IMPORTANT! Currently you need to manually update the user
50
 * guide (doc/user/errcode.xml) with each added error code.
51
 * Please don't forget to do it!
52
 */
53

54
#define ERROR_CODES(_)                                            \
55
        /*  0 */_(ER_UNKNOWN,                        "Unknown error") \
56
        /*  1 */_(ER_ILLEGAL_PARAMS,                "Illegal parameters, %s") \
57
        /*  2 */_(ER_MEMORY_ISSUE,                "Failed to allocate %u bytes in %s for %s") \
58
        /*  3 */_(ER_TUPLE_FOUND,                "Duplicate key exists in unique index '%s' in space '%s'") \
59
        /*  4 */_(ER_TUPLE_NOT_FOUND,                "Tuple doesn't exist in index '%s' in space '%s'") \
60
        /*  5 */_(ER_UNSUPPORTED,                "%s does not support %s") \
61
        /*  6 */_(ER_NONMASTER,                        "Can't modify data on a replication slave. My master is: %s") \
62
        /*  7 */_(ER_READONLY,                        "Can't modify data because this instance is in read-only mode.") \
63
        /*  8 */_(ER_INJECTION,                        "Error injection '%s'") \
64
        /*  9 */_(ER_CREATE_SPACE,                "Failed to create space '%s': %s") \
65
        /* 10 */_(ER_SPACE_EXISTS,                "Space '%s' already exists") \
66
        /* 11 */_(ER_DROP_SPACE,                "Can't drop space '%s': %s") \
67
        /* 12 */_(ER_ALTER_SPACE,                "Can't modify space '%s': %s") \
68
        /* 13 */_(ER_INDEX_TYPE,                "Unsupported index type supplied for index '%s' in space '%s'") \
69
        /* 14 */_(ER_MODIFY_INDEX,                "Can't create or modify index '%s' in space '%s': %s") \
70
        /* 15 */_(ER_LAST_DROP,                        "Can't drop the primary key in a system space, space '%s'") \
71
        /* 16 */_(ER_TUPLE_FORMAT_LIMIT,        "Tuple format limit reached: %u") \
72
        /* 17 */_(ER_DROP_PRIMARY_KEY,                "Can't drop primary key in space '%s' while secondary keys exist") \
73
        /* 18 */_(ER_KEY_PART_TYPE,                "Supplied key type of part %u does not match index part type: expected %s") \
74
        /* 19 */_(ER_EXACT_MATCH,                "Invalid key part count in an exact match (expected %u, got %u)") \
75
        /* 20 */_(ER_INVALID_MSGPACK,                "Invalid MsgPack - %s") \
76
        /* 21 */_(ER_PROC_RET,                        "msgpack.encode: can not encode Lua type '%s'") \
77
        /* 22 */_(ER_TUPLE_NOT_ARRAY,                "Tuple/Key must be MsgPack array") \
78
        /* 23 */_(ER_FIELD_TYPE,                "Tuple field %u type does not match one required by operation: expected %s") \
79
        /* 24 */_(ER_FIELD_TYPE_MISMATCH,        "Ambiguous field type, field %u. Requested type is %s but the field has previously been defined as %s") \
80
        /* 25 */_(ER_SPLICE,                        "SPLICE error on field %u: %s") \
81
        /* 26 */_(ER_UPDATE_ARG_TYPE,                "Argument type in operation '%c' on field %u does not match field type: expected %s") \
82
        /* 27 */_(ER_TUPLE_IS_TOO_LONG,                "Tuple is too long %u") \
83
        /* 28 */_(ER_UNKNOWN_UPDATE_OP,                "Unknown UPDATE operation") \
84
        /* 29 */_(ER_UPDATE_FIELD,                "Field %u UPDATE error: %s") \
85
        /* 30 */_(ER_FIBER_STACK,                "Can not create a new fiber: recursion limit reached") \
86
        /* 31 */_(ER_KEY_PART_COUNT,                "Invalid key part count (expected [0..%u], got %u)") \
87
        /* 32 */_(ER_PROC_LUA,                        "%s") \
88
        /* 33 */_(ER_NO_SUCH_PROC,                "Procedure '%.*s' is not defined") \
89
        /* 34 */_(ER_NO_SUCH_TRIGGER,                "Trigger is not found") \
90
        /* 35 */_(ER_NO_SUCH_INDEX,                "No index #%u is defined in space '%s'") \
91
        /* 36 */_(ER_NO_SUCH_SPACE,                "Space '%s' does not exist") \
92
        /* 37 */_(ER_NO_SUCH_FIELD,                "Field %d was not found in the tuple") \
93
        /* 38 */_(ER_EXACT_FIELD_COUNT,                "Tuple field count %u does not match space field count %u") \
94
        /* 39 */_(ER_INDEX_FIELD_COUNT,                "Tuple field count %u is less than required by a defined index (expected %u)") \
95
        /* 40 */_(ER_WAL_IO,                        "Failed to write to disk") \
96
        /* 41 */_(ER_MORE_THAN_ONE_TUPLE,        "Get() doesn't support partial keys and non-unique indexes") \
97
        /* 42 */_(ER_ACCESS_DENIED,                "%s access on %s is denied for user '%s'") \
98
        /* 43 */_(ER_CREATE_USER,                "Failed to create user '%s': %s") \
99
        /* 44 */_(ER_DROP_USER,                        "Failed to drop user or role '%s': %s") \
100
        /* 45 */_(ER_NO_SUCH_USER,                "User '%s' is not found") \
101
        /* 46 */_(ER_USER_EXISTS,                "User '%s' already exists") \
102
        /* 47 */_(ER_PASSWORD_MISMATCH,                "Incorrect password supplied for user '%s'") \
103
        /* 48 */_(ER_UNKNOWN_REQUEST_TYPE,        "Unknown request type %u") \
104
        /* 49 */_(ER_UNKNOWN_SCHEMA_OBJECT,        "Unknown object type '%s'") \
105
        /* 50 */_(ER_CREATE_FUNCTION,                "Failed to create function '%s': %s") \
106
        /* 51 */_(ER_NO_SUCH_FUNCTION,                "Function '%s' does not exist") \
107
        /* 52 */_(ER_FUNCTION_EXISTS,                "Function '%s' already exists") \
108
        /* 53 */_(ER_FUNCTION_ACCESS_DENIED,        "%s access is denied for user '%s' to function '%s'") \
109
        /* 54 */_(ER_FUNCTION_MAX,                "A limit on the total number of functions has been reached: %u") \
110
        /* 55 */_(ER_SPACE_ACCESS_DENIED,        "%s access is denied for user '%s' to space '%s'") \
111
        /* 56 */_(ER_USER_MAX,                        "A limit on the total number of users has been reached: %u") \
112
        /* 57 */_(ER_NO_SUCH_ENGINE,                "Space engine '%s' does not exist") \
113
        /* 58 */_(ER_RELOAD_CFG,                "Can't set option '%s' dynamically") \
114
        /* 59 */_(ER_CFG,                        "Incorrect value for option '%s': %s") \
115
        /* 60 */_(ER_SAVEPOINT_EMPTY_TX,        "Can not set a savepoint in an empty transaction") \
116
        /* 61 */_(ER_NO_SUCH_SAVEPOINT,                "Can not rollback to savepoint: the savepoint does not exist") \
117
        /* 62 */_(ER_UNKNOWN_REPLICA,                "Replica %s is not registered with replica set %s") \
118
        /* 63 */_(ER_REPLICASET_UUID_MISMATCH,        "Replica set UUID of the replica %s doesn't match replica set UUID of the master %s") \
119
        /* 64 */_(ER_INVALID_UUID,                "Invalid UUID: %s") \
120
        /* 65 */_(ER_REPLICASET_UUID_IS_RO,        "Can't reset replica set UUID: it is already assigned") \
121
        /* 66 */_(ER_INSTANCE_UUID_MISMATCH,        "Remote ID mismatch for %s: expected %u, got %u") \
122
        /* 67 */_(ER_REPLICA_ID_IS_RESERVED,        "Can't initialize replica id with a reserved value %u") \
123
        /* 68 */_(ER_INVALID_ORDER,                "Invalid LSN order for instance %u: previous LSN = %llu, new lsn = %llu") \
124
        /* 69 */_(ER_MISSING_REQUEST_FIELD,        "Missing mandatory field '%s' in request") \
125
        /* 70 */_(ER_IDENTIFIER,                "Invalid identifier '%s' (expected letters, digits or an underscore)") \
126
        /* 71 */_(ER_DROP_FUNCTION,                "Can't drop function %u: %s") \
127
        /* 72 */_(ER_ITERATOR_TYPE,                "Unknown iterator type '%s'") \
128
        /* 73 */_(ER_REPLICA_MAX,                "Replica count limit reached: %u") \
129
        /* 74 */_(ER_INVALID_XLOG,                "Failed to read xlog: %lld") \
130
        /* 75 */_(ER_INVALID_XLOG_NAME,                "Invalid xlog name: expected %lld got %lld") \
131
        /* 76 */_(ER_INVALID_XLOG_ORDER,        "Invalid xlog order: %lld and %lld") \
132
        /* 77 */_(ER_NO_CONNECTION,                "Connection is not established") \
133
        /* 78 */_(ER_TIMEOUT,                        "Timeout exceeded") \
134
        /* 79 */_(ER_ACTIVE_TRANSACTION,        "Operation is not permitted when there is an active transaction ") \
135
        /* 80 */_(ER_CURSOR_NO_TRANSACTION,        "The transaction the cursor belongs to has ended") \
136
        /* 81 */_(ER_CROSS_ENGINE_TRANSACTION,        "A multi-statement transaction can not use multiple storage engines") \
137
        /* 82 */_(ER_NO_SUCH_ROLE,                "Role '%s' is not found") \
138
        /* 83 */_(ER_ROLE_EXISTS,                "Role '%s' already exists") \
139
        /* 84 */_(ER_CREATE_ROLE,                "Failed to create role '%s': %s") \
140
        /* 85 */_(ER_INDEX_EXISTS,                "Index '%s' already exists") \
141
        /* 86 */_(ER_TUPLE_REF_OVERFLOW,        "Tuple reference counter overflow") \
142
        /* 87 */_(ER_ROLE_LOOP,                        "Granting role '%s' to role '%s' would create a loop") \
143
        /* 88 */_(ER_GRANT,                        "Incorrect grant arguments: %s") \
144
        /* 89 */_(ER_PRIV_GRANTED,                "User '%s' already has %s access on %s '%s'") \
145
        /* 90 */_(ER_ROLE_GRANTED,                "User '%s' already has role '%s'") \
146
        /* 91 */_(ER_PRIV_NOT_GRANTED,                "User '%s' does not have %s access on %s '%s'") \
147
        /* 92 */_(ER_ROLE_NOT_GRANTED,                "User '%s' does not have role '%s'") \
148
        /* 93 */_(ER_MISSING_SNAPSHOT,                "Can't find snapshot") \
149
        /* 94 */_(ER_CANT_UPDATE_PRIMARY_KEY,        "Attempt to modify a tuple field which is part of index '%s' in space '%s'") \
150
        /* 95 */_(ER_UPDATE_INTEGER_OVERFLOW,   "Integer overflow when performing '%c' operation on field %u") \
151
        /* 96 */_(ER_GUEST_USER_PASSWORD,       "Setting password for guest user has no effect") \
152
        /* 97 */_(ER_TRANSACTION_CONFLICT,      "Transaction has been aborted by conflict") \
153
        /* 98 */_(ER_UNSUPPORTED_ROLE_PRIV,     "Unsupported role privilege '%s'") \
154
        /* 99 */_(ER_LOAD_FUNCTION,                "Failed to dynamically load function '%s': %s") \
155
        /*100 */_(ER_FUNCTION_LANGUAGE,                "Unsupported language '%s' specified for function '%s'") \
156
        /*101 */_(ER_RTREE_RECT,                "RTree: %s must be an array with %u (point) or %u (rectangle/box) numeric coordinates") \
157
        /*102 */_(ER_PROC_C,                        "%s") \
158
        /*103 */_(ER_UNKNOWN_RTREE_INDEX_DISTANCE_TYPE,        "Unknown RTREE index distance type %s") \
159
        /*104 */_(ER_PROTOCOL,                        "%s") \
160
        /*105 */_(ER_UPSERT_UNIQUE_SECONDARY_KEY, "Space %s has a unique secondary index and does not support UPSERT") \
161
        /*106 */_(ER_WRONG_INDEX_RECORD,        "Wrong record in _index space: got {%s}, expected {%s}") \
162
        /*107 */_(ER_WRONG_INDEX_PARTS,                "Wrong index parts: %s; expected field1 id (number), field1 type (string), ...") \
163
        /*108 */_(ER_WRONG_INDEX_OPTIONS,        "Wrong index options (field %u): %s") \
164
        /*109 */_(ER_WRONG_SCHEMA_VERSION,        "Wrong schema version, current: %d, in request: %u") \
165
        /*110 */_(ER_MEMTX_MAX_TUPLE_SIZE,        "Failed to allocate %u bytes for tuple: tuple is too large. Check 'memtx_max_tuple_size' configuration option.") \
166
        /*111 */_(ER_WRONG_SPACE_OPTIONS,        "Wrong space options (field %u): %s") \
167
        /*112 */_(ER_UNSUPPORTED_INDEX_FEATURE,        "Index '%s' (%s) of space '%s' (%s) does not support %s") \
168
        /*113 */_(ER_VIEW_IS_RO,                "View '%s' is read-only") \
169
        /*114 */_(ER_SAVEPOINT_NO_TRANSACTION,        "Can not set a savepoint in absence of active transaction") \
170
        /*115 */_(ER_SYSTEM,                        "%s") \
171
        /*116 */_(ER_LOADING,                        "Instance bootstrap hasn't finished yet") \
172
        /*117 */_(ER_CONNECTION_TO_SELF,        "Connection to self") \
173
        /*118 */_(ER_KEY_PART_IS_TOO_LONG,        "Key part is too long: %u of %u bytes") \
174
        /*119 */_(ER_COMPRESSION,                "Compression error: %s") \
175
        /*120 */_(ER_CHECKPOINT_IN_PROGRESS,        "Snapshot is already in progress") \
176
        /*121 */_(ER_SUB_STMT_MAX,                "Can not execute a nested statement: nesting limit reached") \
177
        /*122 */_(ER_COMMIT_IN_SUB_STMT,        "Can not commit transaction in a nested statement") \
178
        /*123 */_(ER_ROLLBACK_IN_SUB_STMT,        "Rollback called in a nested statement") \
179
        /*124 */_(ER_DECOMPRESSION,                "Decompression error: %s") \
180
        /*125 */_(ER_INVALID_XLOG_TYPE,                "Invalid xlog type: expected %s, got %s") \
181
        /*126 */_(ER_ALREADY_RUNNING,                "Failed to lock WAL directory %s and hot_standby mode is off") \
182
        /*127 */_(ER_INDEX_FIELD_COUNT_LIMIT,        "Indexed field count limit reached: %d indexed fields") \
183
        /*128 */_(ER_LOCAL_INSTANCE_ID_IS_READ_ONLY, "The local instance id %u is read-only") \
184
        /*129 */_(ER_BACKUP_IN_PROGRESS,        "Backup is already in progress") \
185
        /*130 */_(ER_READ_VIEW_ABORTED,         "The read view is aborted") \
186
        /*131 */_(ER_INVALID_INDEX_FILE,        "Invalid INDEX file %s: %s") \
187
        /*132 */_(ER_INVALID_RUN_FILE,                "Invalid RUN file: %s") \
188
        /*133 */_(ER_INVALID_VYLOG_FILE,        "Invalid VYLOG file: %s") \
189
        /*134 */_(ER_CHECKPOINT_ROLLBACK,        "Can't start a checkpoint while in cascading rollback") \
190
        /*135 */_(ER_VY_QUOTA_TIMEOUT,                "Timed out waiting for Vinyl memory quota") \
191
        /*136 */_(ER_PARTIAL_KEY,                "%s index  does not support selects via a partial key (expected %u parts, got %u). Please Consider changing index type to TREE.") \
192
        /*137 */_(ER_TRUNCATE_SYSTEM_SPACE,        "Can't truncate a system space, space '%s'") \
193
        /*138 */_(ER_LOAD_MODULE,                "Failed to dynamically load module '%.*s': %s") \
194
        /*139 */_(ER_VINYL_MAX_TUPLE_SIZE,        "Failed to allocate %u bytes for tuple: tuple is too large. Check 'vinyl_max_tuple_size' configuration option.") \
195
        /*140 */_(ER_CREATE_SEQUENCE,                "Failed to create sequence '%s': %s") \
196
        /*141 */_(ER_ALTER_SEQUENCE,                "Can't modify sequence '%s': %s") \
197
        /*142 */_(ER_DROP_SEQUENCE,                "Can't drop sequence '%s': %s") \
198
        /*143 */_(ER_NO_SUCH_SEQUENCE,                "Sequence '%s' does not exist") \
199
        /*144 */_(ER_SEQUENCE_EXISTS,                "Sequence '%s' already exists") \
200
        /*145 */_(ER_SEQUENCE_OVERFLOW,                "Sequence '%s' overflowed") \
201
        /*146 */_(ER_SEQUENCE_NOT_STARTED,        "Sequence '%s' was not started") \
202

203
/*
204
 * !IMPORTANT! Please follow instructions at start of the file
205
 * when adding new errors.
206
 */
207

208
ENUM0(box_error_code, ERROR_CODES);
209
extern struct errcode_record box_error_codes[];
210

211
/** Return a string representation of error name, e.g. "ER_OK".
212
 */
213

214
static inline const char *tnt_errcode_str(uint32_t errcode)
561✔
215
{
216
        if (errcode >= box_error_code_MAX) {
561✔
217
                /* Unknown error code - can be triggered using box.error() */
218
                return "ER_UNKNOWN";
×
219
        }
220
        return box_error_codes[errcode].errstr;
561✔
221
}
222

223
/** Return a description of the error. */
224
static inline const char *tnt_errcode_desc(uint32_t errcode)
28,268✔
225
{
226
        if (errcode >= box_error_code_MAX)
28,268✔
227
                return "Unknown error";
1✔
228

229
        return box_error_codes[errcode].errdesc;
28,267✔
230
}
231

232
#ifdef __cplusplus
233
} /* extern "C" */
234
#endif
235

236
#endif /* TARANTOOL_BOX_ERRCODE_H_INCLUDED */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc