-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathcomdb2.h
More file actions
3782 lines (3172 loc) · 140 KB
/
comdb2.h
File metadata and controls
3782 lines (3172 loc) · 140 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2015, 2021 Bloomberg Finance L.P.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef INCLUDED_COMDB2_H
#define INCLUDED_COMDB2_H
/* MOVE THESE TO COMDB2_API.H */
#define SQLHERR_ROLLBACKTOOLARGE (-108)
#define SQLHERR_ROLLBACK_TOOOLD (-109)
#define SQLHERR_ROLLBACK_NOLOG (-110)
#define MAXVER 255
#define SP_FILE_NAME "stored_procedures.sp"
#define SP_VERS_FILE_NAME "vers_stored_procedures.sp"
#define TIMEPART_FILE_NAME "time_partitions.tp"
#define REPOP_QDB_FMT "%s/%s.%d.queuedb" /* /dir/dbname.num.ext */
#define DEFAULT_USER "default"
#define DEFAULT_PASSWORD ""
#define COMDB2_STATIC_TABLE "_comdb2_static_table"
#define MAX_LSN_STR 24
enum { IOTIMEOUTMS = 10000 };
struct dbtable;
struct consumer;
struct thr_handle;
struct reqlogger;
struct thdpool;
struct schema_change_type;
struct rootpage;
typedef long long tranid_t;
#include <sys/types.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <bb_stdint.h>
#include <comdb2buf.h>
#include <netinet/in.h>
#include <flibc.h>
#include <endian_core.h>
#include <epochlib.h>
#include <fsnapf.h>
#include <plhash_glue.h>
#include <list.h>
#include <queue.h>
#include <compile_time_assert.h>
#include <history.h>
#include <comdb2_dbinfo.h>
#include <comdb2_trn_intrl.h>
#include <sqlthdpool.h>
#include <prefault.h>
#include <quantize.h>
#include <dlmalloc.h>
#include "sqlinterfaces.h"
#include "errstat.h"
#include "comdb2_rcodes.h"
#include "repl_wait.h"
#include "types.h"
#include "thread_util.h"
#include "request_stats.h"
#include "bdb_osqltrn.h"
#include "thdpool.h"
#include "thrman.h"
#include "comdb2uuid.h"
#include "machclass.h"
#include "shard_range.h"
#include "tunables.h"
#include "comdb2_plugin.h"
#ifndef LUASP
#include <mem_uncategorized.h>
#include <mem_override.h>
#endif
#include <trigger.h>
#include <cdb2_constants.h>
#include <schema_lk.h>
#include "perf.h"
#include "constraints.h"
#include "osqlrpltypes.h"
#include "macc_glue.h"
#include "api_history.h"
/* buffer offset, given base ptr & right ptr */
#define BUFOFF(base, right) ((int)(((char *)right) - ((char *)base)))
/* we will delete at most this many per run of purge_old_blkseq */
#define MAXBLKSEQ_PURGE (5 * 1024)
#define DEC_ROUND_NONE (-1)
enum AUXDB_TYPES {
AUXDB_NONE = 0
/* 1 used to be AUXDB_BLKSEQ, but it has been purged */
,
AUXDB_META = 2,
AUXDB_FSTBLK = 3
};
/* This is thenumber of bytes taken up by the null bitmap in the wire protocol,
* which traditionally is fixed at 32 bytes (enough for 256 columns). */
enum { NULLBMPWIRELENGTH = 32 };
enum {
DONT_FORM_KEYS = 0 /*original comdbg requests and '2'-type requests
supporeted. 2-requests don't form keys */
,
CLIENT_FORMS_KEYS = 1 /*convert client keys in requests to ondisk format*/
,
SERVER_FORMS_KEYS = 2 /*ignore any keys in client requests: always form
keys from data*/
};
#define MAXNULLBITS (MAXCOLUMNS / 8)
enum SYNC_FLAGS {
REP_SYNC_FULL = 0, /* all nodes are sync'd before ack */
REP_SYNC_SOURCE = 1, /* source node only is synchronized before ack */
REP_SYNC_NONE = 2, /* run asynchronously */
REP_SYNC_ROOM = 3, /* sync to nodes in my machine room */
REP_SYNC_N = 4 /* wait for N machines */
};
enum OPCODES {
OP_DBINFO = 0 /*rmtdb info req*/
,
OP_FIND = 4 /*find*/
,
OP_NEXT = 5 /*next*/
,
OP_JSTNX = 11 /*jstnx*/
,
OP_JSTFND = 13 /*jstfnd*/
,
OP_FNDRRN = 15,
OP_PREV = 29 /*prev*/
,
OP_NUMRRN = 30 /*number rrns*/
,
OP_HIGHRRN = 33 /*highest rrn*/
,
OP_JSTPREV = 37 /*jstprev*/
,
OP_STORED = 41 /*stored proc*/
,
OP_FIND2 = 45 /*new find*/
,
OP_NEXT2 = 46 /*new next*/
,
OP_PREV2 = 47 /*new prev*/
,
OP_JFND2 = 48 /*new just find*/
,
OP_JNXT2 = 49 /*new just next*/
,
OP_JPRV2 = 50 /*new just prev*/
,
OP_RNGEXT2 = 51 /*new range extract (extended limits) */
,
OP_RNGEXTP2 = 52 /*new range extract previous (extended limits) */
,
OP_FNDKLESS = 53,
OP_JFNDKLESS = 54,
OP_FORMKEY = 55,
OP_FNDNXTKLESS = 56,
OP_FNDPRVKLESS = 57,
OP_JFNDNXTKLESS = 58,
OP_JFNDPRVKLESS = 59,
OP_RNGEXTTAG = 60,
OP_RNGEXTTAGP = 61,
OP_FNDRRNX = 62,
OP_RNGEXTTAGTZ = 63,
OP_RNGEXTTAGPTZ = 64,
OP_MSG_TRAP = 99 /*process message trap*/
,
OP_BLOCK = 100,
OP_FWD_BLOCK = 101 /*forwarded block operation*/
,
OP_DBINFO2 = 102,
OP_DESCRIBE = 103,
OP_NEWRNGEX = 104,
OP_SQL = 105 /* all sql calls set this */
,
OP_REBUILD = 106 /* dummy code for online rebuilds */
,
OP_LONGBLOCK = 107 /* long block transaction opcode */
,
OP_FWD_LBLOCK = 108 /* long block transaction forward opcode */
,
OP_BLOBASK = 109 /* ask for a blob fragment */
,
OP_CLEARTABLE = 110,
OP_COUNTTABLE = 111
/* marshalled find requests */
,
OP_ANALYZE = 112,
OP_RMTFIND = 113,
OP_RMTFINDLASTDUP = 114,
OP_RMTFINDNEXT = 115,
OP_RMTFINDPREV = 116,
OP_RMTFINDRRN = 117,
OP_DESCRIBEKEYS = 119 /* describe keys */
,
OP_GETKEYNAMES = 120 /* get key names */
,
OP_FASTINIT = 121,
OP_PROX_CONFIG = 122
,
OP_TRAN_COMMIT = 123,
OP_TRAN_ABORT = 124,
OP_TRAN_FINALIZE = 125,
OP_CHECK_TRANS = 127,
OP_NOTCOHERENT = 128,
OP_NOTCOHERENT2 = 129,
OP_MAKE_NODE_INCOHERENT = 130,
OP_CLIENT_STATS = 131,
OP_FWD_BLOCK_LE = 132,
OP_UPGRADE = 133 /* dummy code for online upgrade */
,
OP_SORESE = 134 /* no blk buffers here */
,
MAXTYPCNT = 134
,
OP_DEBUG = 200 /* for debugging (unused?) */
};
/* if you add a new blockop, please update toblock_init() and breq2a()
* in toblock.c */
enum BLOCK_OPS {
BLOCK_ADDSL = 110,
BLOCK_ADDSEC = 111,
BLOCK_SECAFPRI = 112,
BLOCK_ADNOD = 113,
BLOCK_DELSC = 114,
BLOCK_DELSEC = 115,
BLOCK_DELNOD = 116,
BLOCK_UPVRRN = 117,
BLOCK2_ADDDTA = 130,
BLOCK2_ADDKEY = 131,
BLOCK2_DELDTA = 132,
BLOCK2_DELKEY = 133,
BLOCK2_UPDATE = 134,
BLOCK2_ADDKL = 135,
BLOCK2_DELKL = 136,
BLOCK2_UPDKL = 137,
BLOCK2_ADDKL_POS = 138,
BLOCK2_UPDKL_POS = 139,
BLOCK_DEBUG = 777,
BLOCK_SEQ = 800,
BLOCK_USE = 801,
BLOCK2_USE = 802,
BLOCK2_SEQ = 803,
BLOCK2_QBLOB = 804,
BLOCK2_RNGDELKL = 805,
BLOCK_SETFLAGS = 806,
BLOCK2_CUSTOM = 807,
BLOCK2_QADD = 808,
BLOCK2_QCONSUME = 809,
BLOCK2_TZ = 810,
BLOCK2_SQL = 811, /* obsolete */
BLOCK2_DELOLDER = 812,
BLOCK2_TRAN = 813,
BLOCK2_MODNUM = 814,
BLOCK2_SOCK_SQL = 815,
BLOCK2_SCSMSK = 816,
BLOCK2_RECOM = 817,
BLOCK2_UPDBYKEY = 818,
BLOCK2_SERIAL = 819,
BLOCK2_SQL_PARAMS = 820, /* obsolete */
BLOCK2_DBGLOG_COOKIE = 821,
BLOCK2_PRAGMA = 822,
BLOCK2_SNAPISOL = 823,
BLOCK2_SEQV2 = 824,
BLOCK2_UPTBL = 825,
BLOCK_MAXOPCODE
/* Used for some condensed blockop stats; this should be the number of
* opcodes that there actually really are. */
,
NUM_BLOCKOP_OPCODES = 45
};
enum DEBUGREQ { DEBUG_METADB_PUT = 1 };
enum RCODES {
RC_OK = 0, /* SUCCESS */
ERR_VERIFY = 4, /* failed verify on updwver */
ERR_CORRUPT = 8, /* CORRUPT INDEX */
ERR_BADRRN = 9, /* findbyrrn on bad rrn */
ERR_ACCESS = 10, /* access denied */
ERR_DTA_FAILED = 11, /* failed operation on data */
ERR_INTERNAL = 177, /* internal logic error. */
ERR_REJECTED = 188, /* request rejected */
RC_INTERNAL_FORWARD = 193, /* forwarded block request */
ERR_FAILED_FORWARD = 194, /* block update failed to send to remote */
ERR_READONLY = 195, /* database is currently read-only */
ERR_NOMASTER = 1000, /* database has no master, it is readonly */
ERR_NESTED = 1001, /* this is not master, returns actual master */
ERR_RMTDB_NESTED = 198, /* reserved for use by rmtdb/prox2 */
ERR_BADREQ = 199, /* bad request parameters */
ERR_TRAN_TOO_BIG = 208, /* transaction exceeded size limit */
ERR_TXN_EXCEEDED_TIME_LIMIT = 209,
ERR_BLOCK_FAILED = 220, /* block update failed */
ERR_NOTSERIAL = 230, /* transaction not serializable */
ERR_SC = 240, /* schemachange failed */
RC_INTERNAL_RETRY = 300, /* need to retry comdb upper level request */
ERR_CONVERT_DTA = 301,
ERR_CONVERT_IX = 301,
ERR_KEYFORM_UNIMP = 303,
RC_TRAN_TOO_COMPLEX = 304, /* too many rrns allocated per trans */
RC_TRAN_CLIENT_RETRY = 305,
ERR_BLOB_TOO_LARGE = 306, /* a blob exceeded MAXBLOBLENGTH */
ERR_BUF_TOO_SMALL = 307, /* buffer provided too small to fit data */
ERR_NO_BUFFER = 308, /* can't get fstsnd buffer */
ERR_JAVASP_ABORT = 309, /* stored procedure ordered this trans aborted */
ERR_NO_SUCH_TABLE = 310, /* operation tried to use non-existant table */
ERR_CALLBACK = 311, /* operation failed due to errors in callback */
ERR_TRAN_FAILED = 312, /* could not start of finish transaction */
ERR_CONSTR = 313, /* could not complete the operation because of
constraints in the table */
ERR_SC_COMMIT = 314, /* schema change in its final stages;
proxy should retry */
ERR_CONFIG_FAILED = 316,
ERR_NO_RECORDS_FOUND = 317,
ERR_NULL_CONSTRAINT = 318,
ERR_VERIFY_PI = 319,
ERR_CHECK_CONSTRAINT = 320,
ERR_INDEX_CONFLICT = 330,
ERR_UNCOMMITTABLE_TXN = 404, /* txn is uncommittable, returns ERR_VERIFY
rather than retry */
ERR_DIST_ABORT = 430, /* Prepared txn has been aborted */
ERR_QUERY_REJECTED = 451,
ERR_INCOHERENT = 996, /* prox2 understands it should retry another
node for 996 */
ERR_SQL_PREPARE = 1003,
ERR_NO_AUXDB = 2000, /* requested auxiliary database not available */
ERR_SQL_PREP = 2001, /* block sql error in sqlite3_prepare */
ERR_LIMIT = 2002, /* sql request exceeds max cost */
ERR_NOT_DURABLE = 2003, /* commit didn't make it to a majority */
ERR_RECOVER_DEADLOCK = 2004
};
#define IS_BAD_IX_FND_RCODE(rc) \
(((rc) < IX_OK || (rc) > IX_PASTEOF) && \
((rc) < IX_FNDNOCONV || (rc) > IX_PASTEOFNOCONV) && ((rc) != IX_EMPTY))
#include "ix_return_codes.h"
enum COMDB2_TAIL_REPLY_FLAGS {
TAIL_EMPTY = 0x00000000, /**< nothing has been returned */
TAIL_ERRSTAT = 0x00000001, /**< db errstat */
TAIL_EXTENDED = 0x40000000 /**< reserved to provide extension */
};
enum RMTDB_TYPE {
RMTDB_LOCAL = 0,
RMTDB_COMDB2_TAGGED = 1,
RMTDB_COMDB2_UNTAGGED = 2,
RMTDB_COMDBG = 3,
RMTDB_COMDB2_REMCUR = 4
};
enum DB_METADATA {
META_SCHEMA_RRN = 0, /* use this rrn in the meta table for schema info */
META_SCHEMA_VERSION = 1, /* this key holds the current ONDISK schema version
as a 32 bit int */
META_CSC2_RRN = -1, /* for the csc2 versioning */
META_CSC2_VERSION = -1, /* key for current version of csc2 file */
META_CSC2DATE_RRN = -2, /* in this rrn we store the date as a unix epoch)
when a schema was loaded. key is a schema
version number. */
META_BLOBSTRIPE_GENID_RRN = -3, /* in this rrn store the genid of table
when it was converted to blobstripe */
META_STUFF_RRN = -4, /* used by pushlogs.c to do "stuff" to the database
until we get past a given lsn. */
META_ONDISK_HEADER_RRN = -5, /* do we have the new ondisk header? */
META_COMPRESS_RRN = -6, /* which compression algorithm to use for new
records (if any) */
META_COMPRESS_BLOBS_RRN = -7, /* and which to use for blobs. */
META_FILEVERS = -8, /* 64 bit id for filenames */
META_FILE_LWM = -9, /* int - lower deleteable log file */
META_INSTANT_SCHEMA_CHANGE = -10,
META_DATACOPY_ODH = -11,
META_INPLACE_UPDATES = -12,
META_BTHASH = -13,
META_QUEUE_ODH = -14,
META_QUEUE_COMPRESS = -15,
META_QUEUE_PERSISTENT_SEQ = -16,
META_QUEUE_SEQ = -17
};
enum CONSTRAINT_FLAGS {
CT_UPD_CASCADE = 0x00000001,
CT_DEL_CASCADE = 0x00000002,
CT_BLD_SKIP = 0x00000004,
CT_DEL_SETNULL = 0x00000008,
};
/* dbtable type specifier, please do not use for schema change type */
enum {
UNUSED_1 = 0,
DBTYPE_TAGGED_TABLE = 1,
DBTYPE_QUEUE = 2,
UNUSED_2 = 3,
DBTYPE_QUEUEDB = 4
};
/* Copied verbatim from bdb_api.h since we don't expose that file to most
* modules. */
enum {
COMDB2_THR_EVENT_DONE_RDONLY = 0,
COMDB2_THR_EVENT_START_RDONLY = 1,
COMDB2_THR_EVENT_DONE_RDWR = 2,
COMDB2_THR_EVENT_START_RDWR = 3
};
enum lclop {
LCL_OP_ADD = 1,
LCL_OP_DEL = 2,
/* update goes out as del+add */
LCL_OP_COMMIT = 3,
LCL_OP_TOOBIG = 4, /* internal to receiver, not used in comdb2 */
LCL_OP_CLEAR = 5,
LCL_OP_ANALYZE = 6
};
enum { DB_COHERENT = 0, DB_INCOHERENT = 1 };
/* Modern transaction modes, more or less */
enum transaction_level {
TRANLEVEL_INVALID = -1,
TRANLEVEL_SOSQL = 9,
/* SQL MODE, so-called read-commited:
- server-side parsing
- transaction-internal updates are visible only inside transaction thread
- external (commited) updates are visible inside transaction thread
*/
TRANLEVEL_RECOM = 10,
TRANLEVEL_SERIAL = 11,
TRANLEVEL_SNAPISOL = 12,
TRANLEVEL_MODSNAP = 13 /* server flag, client uses SNAPISOL */
};
enum RECORD_WRITE_TYPES {
RECORD_WRITE_INS = 0,
RECORD_WRITE_UPD = 1,
RECORD_WRITE_DEL = 2,
RECORD_WRITE_MAX = 3
};
enum RECOVER_DEADLOCK_FLAGS {
RECOVER_DEADLOCK_PTRACE = 0x00000001,
RECOVER_DEADLOCK_FORCE_FAIL = 0x00000002,
RECOVER_DEADLOCK_IGNORE_DESIRED= 0x00000004
};
enum CURTRAN_FLAGS { CURTRAN_RECOVERY = 0x00000001 };
/* Raw stats, kept on a per origin machine basis. Please don't add any other data
* type above `svc_time' as this allows us to easily sum it and diff it in a
* loop in reqlog.c.
*/
struct rawnodestats {
unsigned opcode_counts[MAXTYPCNT];
unsigned blockop_counts[NUM_BLOCKOP_OPCODES];
unsigned sql_queries_cdb2api;
unsigned sql_queries_comdb2api;
unsigned sql_queries_converted;
unsigned sql_queries;
unsigned sql_steps;
unsigned sql_rows;
struct time_metric *svc_time; /* <-- offsetof */
pthread_mutex_t lk;
hash_t *fingerprints;
api_history_t *api_history;
};
#define NUM_RAW_NODESTATS \
(offsetof(struct rawnodestats, svc_time) / sizeof(unsigned))
struct summary_nodestats {
int node;
char *host;
struct in_addr addr;
char *task;
char *stack;
char *identity;
int ref;
int is_ssl;
unsigned finds;
unsigned rngexts;
unsigned writes;
unsigned other_fstsnds;
unsigned adds;
unsigned upds;
unsigned dels;
unsigned bsql; /* block sql */
unsigned recom; /* recom sql */
unsigned snapisol; /* snapisol sql */
unsigned serial; /* serial sql */
unsigned sql_queries;
unsigned sql_queries_cdb2api;
unsigned sql_queries_comdb2api;
unsigned sql_queries_converted;
unsigned sql_steps;
unsigned sql_rows;
double svc_time;
};
/* records in sql master db look like this (no appended rrn info) */
struct sqlmdbrectype {
char type[8];
char name[20];
char tblname[20];
int rootpage;
char sql[876];
};
/* This is the transparent seqnum type, which should match the bdb_api defined
* type in size. backend_open() has a sanity check to enforce this. */
typedef int db_seqnum_type[10];
enum { COMDB2_NULL_TYPE = -1 };
/* All the data needed for a bulk import */
typedef struct bulk_import_data bulk_import_data_t;
struct bulk_import_data {
unsigned long long data_genid;
unsigned long long index_genids[MAXINDEX];
unsigned long long blob_genids[MAXBLOBS];
char table_name[MAXTABLELEN];
/* not check for equality in bulk_import_data_validate since it doesn't need
* to be the same on all machines */
char data_dir[256 /*arbitrary, must be able to fit any data dir*/];
unsigned csc2_crc32;
int checksums;
int odh;
int compress;
int compress_blobs;
int dtastripe;
int blobstripe;
size_t num_index_genids;
size_t num_blob_genids;
int filenames_provided;
char *data_files[MAXDTASTRIPE];
char *index_files[MAXINDEX];
char *blob_files[MAXBLOBS][MAXDTASTRIPE];
int bulk_import_version;
};
struct dbstore {
uint8_t ver;
int len;
void *data;
};
typedef struct timepart_views timepart_views_t;
#define consumer_lock_read(x) consumer_lock_read_int(x, __func__, __LINE__);
void consumer_lock_read_int(struct dbtable *db, const char *func, int line);
#define consumer_lock_write(x) consumer_lock_write_int(x, __func__, __LINE__);
void consumer_lock_write_int(struct dbtable *db, const char *func, int line);
#define consumer_unlock(x) consumer_unlock_int(x, __func__, __LINE__);
void consumer_unlock_int(struct dbtable *db, const char *func, int line);
/*
* We now have different types of db (I overloaded this structure rather than
* create a new structure because the ireq usedb concept is endemic anyway).
*/
typedef struct dbtable {
struct dbenv *dbenv; /*chain back to my environment*/
char *lrlfname;
char *tablename;
char *sqlaliasname;
struct ireq *iq; /* iq used at sc time */
int dbnum; /* zero unless setup as comdbg table */
int lrl; /*dat len in bytes*/
/*index*/
unsigned short nix; /*number of indices*/
unsigned short ix_keylen[MAXINDEX]; /*key len in bytes*/
signed char ix_dupes[MAXINDEX];
signed char ix_recnums[MAXINDEX];
signed char ix_datacopy[MAXINDEX];
int ix_datacopylen[MAXINDEX]; /* datacopy len in bytes (0 if full datacopy) */
signed char ix_collattr[MAXINDEX];
signed char ix_nullsallowed[MAXINDEX];
shard_limits_t *sharding;
int numblobs;
/* we do not necessarily have as many sql indexes as there are comdb2
* indexes - only indexes free of <DESCEND> can be advertised to sqlite.
* this for some values of n, ixsql[n] might be NULL. nsqlix is the count
* of indexes that are exposed to sqlite. */
struct schema *schema;
struct schema **ixschema;
char *sql;
char **ixsql;
int nsqlix;
/*backend db engine handle*/
bdb_state_type *handle;
/* meta-data. this may be a lite db. it may be NULL, because older
* comdb2s didn't have meta dbs. also it may be NULL if the dbenv
* meta handle is non-NULL - the new approach is one meta table per
* database a sthis scales much better as we add more tables. */
void *meta;
/*counters*/
int64_t typcnt[MAXTYPCNT + 1];
int64_t blocktypcnt[BLOCK_MAXOPCODE];
int64_t blockosqltypcnt[MAX_OSQL_TYPES];
int64_t nsql; // counter for queries to this table
/*prev counters for diff*/
int64_t prev_typcnt[MAXTYPCNT + 1];
int64_t prev_blocktypcnt[BLOCK_MAXOPCODE];
int64_t prev_blockosqltypcnt[MAX_OSQL_TYPES];
int64_t prev_nsql;
/* counters for writes to this table */
int64_t write_count[RECORD_WRITE_MAX];
int64_t saved_write_count[RECORD_WRITE_MAX];
/* counters for cascaded writes to this table */
int64_t casc_write_count;
int64_t saved_casc_write_count;
int64_t deadlock_count;
int64_t saved_deadlock_count;
int64_t aa_saved_counter; // zeroed out at autoanalyze
int64_t aa_lastepoch;
int64_t aa_needs_analyze_time; // time when analyze is needed for table in request mode, otherwise 0
int64_t read_count; // counter for reads to this table
int64_t index_used_count; // counter for number of times a table index was used
/* Foreign key constraints */
constraint_t *constraints;
size_t n_constraints;
/* Pointers to other table constraints that are directed at this table. */
constraint_t **rev_constraints;
size_t n_rev_constraints;
size_t cap_rev_constraints;
pthread_mutex_t rev_constraints_lk;
/* CHECK constraints */
check_constraint_t *check_constraints;
size_t n_check_constraints;
char **check_constraint_query;
/* One of the DBTYPE_ constants. */
int dbtype;
struct consumer *consumers[MAXCONSUMERS];
/* Expected average size of a queue item in bytes. */
int avgitemsz;
int queue_pagesize_override;
/* some queue stats */
unsigned int num_goose_adds;
unsigned int num_goose_consumes;
/* used by the queue goosing sub system */
int goose_consume_cnt;
int goose_add_cnt;
/* needed for foreign table support */
int dtastripe;
/* when we were blobstriped */
unsigned long long blobstripe_genid;
/* placeholder for storing file sizes when we need them */
uint64_t ixsizes[MAXINDEX];
uint64_t dtasize;
uint64_t blobsizes[MAXBLOBS];
uint64_t totalsize;
unsigned numextents;
/* index stats */
unsigned long long *ixuse;
unsigned long long *sqlixuse;
/* Used during schema change to describe how we will form the new table
* from the old table. The add/update/delete routines will only look at
* this information if plan!=NULL.
* To keep things sane we always create the full complement of dtafile,
* ix files and blob files for a new table. If a plan is in use then
* we may not populate all of them. Slightly wasteful, but for now this
* seems safer and more likely not to mess up.
* This probably doesn't work that great with constraints (yet).
*/
struct scplan *plan;
int dbs_idx; /* index of us in dbenv->dbs[] */
struct dbtable *sc_from; /* point to the source db, replace global sc_from */
struct dbtable *sc_to; /* point to the new db, replace global sc_to */
int sc_live_logical;
unsigned long long *sc_genids; /* schemachange stripe pointers */
/* All writer threads have to grab the lock in read/write mode. If a live
* schema change is in progress then they have to do extra stuff. */
pthread_rwlock_t sc_live_lk;
/* count the number of updates and deletes done by schemachange
* when behind the cursor. This helps us know how many
* records we've really done (since every update behind the cursor
* effectively means we have to go back and do that record again). */
uint32_t sc_adds;
uint32_t sc_deletes;
uint32_t sc_updates;
uint64_t sc_nrecs;
uint64_t sc_prev_nrecs;
unsigned int sqlcur_ix; /* count how many cursors where open in ix mode */
unsigned int sqlcur_cur; /* count how many cursors where open in cur mode */
char *csc2_schema;
int csc2_schema_len;
struct dbstore dbstore[MAXCOLUMNS];
int odh;
/* csc2 schema version increased on instantaneous schemachange */
int schema_version;
int instant_schema_change;
int inplace_updates;
/* tableversion is an ever increasing counter which is incremented for
* every schema change (add, alter, drop, etc.) but not for fastinit */
unsigned long long tableversion;
/* map of tag fields for schema version to curr schema */
unsigned int * versmap[MAXVER + 1];
/* is tag version compatible with ondisk schema */
uint8_t vers_compat_ondisk[MAXVER + 1];
/* lock for consumer list */
pthread_rwlock_t consumer_lk;
unsigned has_datacopy_ix : 1; /* set to 1 if we have datacopy indexes */
unsigned ix_partial : 1; /* set to 1 if we have partial indexes */
unsigned ix_expr : 1; /* set to 1 if we have indexes on expressions */
unsigned ix_blob : 1; /* set to 1 if blobs are involved in indexes */
unsigned ix_func : 1; /* set to 1 if sfuncs are involved in indexes */
char ** lua_sfuncs; /* The lua scalar functions used by indexes in this table*/
int num_lua_sfuncs; /* The number of lua scalar functions used by indexes in this table*/
unsigned sc_abort : 1;
unsigned sc_downgrading : 1;
/* boolean value set to nonzero if table rebuild is in progress */
unsigned doing_conversion : 1;
/* boolean value set to nonzero if table upgrade is in progress */
unsigned doing_upgrade : 1;
unsigned disableskipscan : 1;
unsigned do_local_replication : 1;
/* name of the timepartition, if this is a shard */
const char *timepartition_name;
/* generic sharding metadata */
uint32_t numdbs;
char **dbnames;
uint32_t numcols;
char **columns;
char **shardnames;
struct timepart_retro *sharding_arg;
struct dbtable *(*sharding_func)(struct timepart_retro *, unsigned long long, const char *, int);
} dbtable;
struct dbview {
char *view_name;
char *view_def;
};
struct log_delete_state {
int filenum;
LINKC_T(struct log_delete_state) linkv;
};
struct lrlfile {
char *file;
LINKC_T(struct lrlfile) lnk;
};
struct lrl_handler {
int (*handle)(struct dbenv*, const char *line);
LINKC_T(struct lrl_handler) lnk;
};
struct message_handler {
int (*handle)(struct dbenv*, const char *line);
LINKC_T(struct message_handler) lnk;
};
struct dbenv {
char *basedir;
char *envname;
int dbnum;
/*backend db engine handle*/
void *bdb_attr; /*engine attributes*/
void *bdb_callback; /*engine callbacks */
char *master; /*current master node, from callback*/
int gen; /*generation for current master node*/
int egen; /*election generation for current master node*/
int cacheszkb;
int cacheszkbmin;
int cacheszkbmax;
int override_cacheszkb;
/*sibling info*/
int nsiblings;
char *sibling_hostname[REPMAX];
unsigned short sibling_port[REPMAX][NET_MAX];
int listen_fds[NET_MAX];
/* banckend db engine handle for replication */
void *handle_sibling;
void *handle_sibling_offload;
/*replication sync mode */
int rep_sync;
/*log sync mode */
int log_sync;
int log_sync_time;
int log_mem_size;
/*log deletion is now sort of reference counted to allow socket
*applications to keep it held turned off during a backup. */
int log_delete;
pthread_mutex_t log_delete_counter_mutex;
/* the log delete age is the epoch time after which log files can't
* be deleted. if this is <=0 then we will always delete archiveable
* log files if log deletion is on. */
int log_delete_age;
/* the log delete filenum is the highest log file number that may
* be removed. set this to -1 if any log file may be removed.
* Since log files follow 1-based indexing, setting this to 0
* disables log deletion */
int log_delete_filenum;
/* this is a linked list of log_delete_stat structs. If the list is
* empty then log file deletion can proceed as normal. Otherwise we
* have one or more clients that have requested log deletion to be
* held up, at least beyond a certain log number. The log_delete_state
* structs themselves reside on the stacks of appsock threads. */
LISTC_T(struct log_delete_state) log_delete_state_list;
/*counters*/
int typcnt[MAXTYPCNT + 1];
/* bdb_environment */
bdb_state_type *bdb_env;
/* Tables */
int num_dbs;
dbtable **dbs;
dbtable static_table;
hash_t *db_hash;
hash_t *sqlalias_hash;
/* Queues */
int num_qdbs;
struct dbtable **qdbs;
hash_t *qdb_hash;
/* Views */
hash_t *view_hash;
LISTC_T(struct lua_func_t) lua_sfuncs;
LISTC_T(struct lua_func_t) lua_afuncs;
/* is sql mode enabled? */
int sql;
/* enable client side retrys for N seconds */
int retry;
int rep_always_wait;
pthread_t purge_old_blkseq_tid;
pthread_t purge_old_files_tid;
/* stupid - is the purge_old_blkseq thread running? */
int purge_old_blkseq_is_running;
int purge_old_files_is_running;
int stopped; /* set when exiting -- if set, drop requests */
int no_more_sql_connections;
LISTC_T(struct sql_thread) sql_threads;
LISTC_T(struct sql_hist) sqlhist;
hash_t *long_trn_table; /* h-table of long transactions--fast lookup */
struct long_trn_stat long_trn_stats;
pthread_mutex_t long_trn_mtx;
/* the per database meta table */
void *meta;
/* Replication stats (these are updated locklessly so may display
* gibberish). We only count successful commits. */
uint64_t biggest_txn;
uint64_t total_txn_sz;
int num_txns;
int max_timeout_ms;
int total_timeouts_ms;
int max_reptime_ms;
int total_reptime_ms;
/* gathered at startup time and processed */
char **allow_lines;
int num_allow_lines;
int max_allow_lines;
int errstaton;
sqlpool_t sqlthdpool;
prefaultiopool_type prefaultiopool;
prefault_helper_type prefault_helper;
readaheadprefault_type readahead_prefault;
prefault_stats_type prefault_stats;
int lowdiskpercent; /* % full at which disk space considered dangerous */
void *dl_cache_heap;
mspace dl_cache_mspace;
pthread_mutex_t incoherent_lk;
int num_incoherent;
int fallen_offline;
int manager_dbnum;
pthread_t watchdog_tid;
pthread_t watchdog_watcher_tid;
int64_t txns_committed;
int64_t txns_aborted;
int64_t prev_txns_committed;
int64_t prev_txns_aborted;
int wait_for_N_nodes;
LISTC_T(struct lrlfile) lrl_files;
int incoh_notcoherent;
uint32_t incoh_file, incoh_offset;
timepart_views_t *timepart_views;
struct time_metric *service_time;
struct time_metric *queue_depth;
struct time_metric *concurrent_queries;