forked from bloomberg/comdb2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comdb2.c
6278 lines (5347 loc) · 200 KB
/
comdb2.c
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.
*/
int __berkdb_write_alarm_ms;
int __berkdb_read_alarm_ms;
int __berkdb_fsync_alarm_ms;
extern int gbl_delay_sql_lock_release_sec;
void __berkdb_set_num_read_ios(long long *n);
void __berkdb_set_num_write_ios(long long *n);
void __berkdb_set_num_fsyncs(long long *n);
void berk_memp_sync_alarm_ms(int);
#include <pthread.h>
#include <sys/resource.h>
#include <sys/utsname.h>
#include <berkdb/dbinc/queue.h>
#include <limits.h>
#include <arpa/inet.h>
#include <alloca.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <netdb.h>
#include <poll.h>
#include <pwd.h>
#include <libgen.h>
#include <mem_uncategorized.h>
#include <epochlib.h>
#include <segstr.h>
#include "thread_stats.h"
#include <list.h>
#include <mem.h>
#include <str0.h>
#include <rtcpu.h>
#include <ctrace.h>
#include <memory_sync.h>
#include <net.h>
#include <bdb_api.h>
#include <sbuf2.h>
#include "quantize.h"
#include "timers.h"
#include "comdb2.h"
#include "sql.h"
#include "logmsg.h"
#include "reqlog.h"
#include "comdb2_trn_intrl.h"
#include "history.h"
#include "tag.h"
#include "types.h"
#include "timer.h"
#include <plhash.h>
#include "verify.h"
#include "ssl_bend.h"
#include "switches.h"
#include "sqloffload.h"
#include "osqlblockproc.h"
#include "osqlblkseq.h"
#include <sqliteInt.h>
#include "thdpool.h"
#include "memdebug.h"
#include "bdb_access.h"
#include "analyze.h"
#include "osqlcomm.h"
#include <cdb2_constants.h>
#include <crc32c.h>
#include "fdb_fend.h"
#include "fdb_bend.h"
#include <flibc.h>
#include "perf.h"
#include <autoanalyze.h>
#include <sqlglue.h>
#include "dbdest.h"
#include "intern_strings.h"
#include "bb_oscompat.h"
#include "comdb2uuid.h"
#include "debug_switches.h"
#include "eventlog.h"
#include "config.h"
#include "views.h"
#include <autoanalyze.h>
#include <cdb2_constants.h>
#include <bb_oscompat.h>
#include <schemachange.h>
#include "comdb2_atomic.h"
#include "cron.h"
#include "metrics.h"
#include "time_accounting.h"
#include <build/db.h>
#include "comdb2_ruleset.h"
#include <hostname_support.h>
#include "string_ref.h"
#include "sql_stmt_cache.h"
#include "phys_rep.h"
#include "comdb2_query_preparer.h"
#include <net_appsock.h>
#include "sc_csc2.h"
#include "reverse_conn.h"
#define tokdup strndup
int gbl_thedb_stopped = 0;
int gbl_sc_timeoutms = 1000 * 60;
char gbl_dbname[MAX_DBNAME_LENGTH];
int gbl_largepages;
int gbl_llmeta_open = 0;
int gbl_sqlite_sortermult = 1;
int gbl_sqlite_sorter_mem = 300 * 1024 * 1024; /* 300 meg */
int gbl_strict_dbl_quotes = 0;
int gbl_rep_node_pri = 0;
int gbl_handoff_node = 0;
int gbl_use_node_pri = 0;
int gbl_allow_lua_print = 0;
int gbl_allow_lua_dynamic_libs = 0;
int gbl_lua_prepare_max_retries = 0;
int gbl_lua_prepare_retry_sleep = 200;
int gbl_allow_pragma = 0;
int gbl_master_changed_oldfiles = 0;
int gbl_recovery_timestamp = 0;
int gbl_recovery_lsn_file = 0;
int gbl_recovery_lsn_offset = 0;
int gbl_trace_prepare_errors = 0;
int gbl_trigger_timepart = 0;
int gbl_extended_sql_debug_trace = 0;
int gbl_perform_full_clean_exit = 1;
struct ruleset *gbl_ruleset = NULL;
void myctrace(const char *c) { ctrace("%s", c); }
void berkdb_use_malloc_for_regions_with_callbacks(void *mem,
void *(*alloc)(void *, int),
void (*free)(void *, void *));
extern void bb_berkdb_reset_worst_lock_wait_time_us();
extern int has_low_headroom(const char *path, int headroom, int debug);
extern void *clean_exit_thd(void *unused);
extern void bdb_durable_lsn_for_single_node(void *in_bdb_state);
/* How frequent metrics are refreshed, once per this many seconds */
int gbl_update_metrics_interval = 5;
extern void update_metrics(void);
extern void *timer_thread(void *);
extern void comdb2_signal_timer();
void init_lua_dbtypes(void);
static int put_all_csc2();
static void *purge_old_blkseq_thread(void *arg);
static void *purge_old_files_thread(void *arg);
static int lrllinecmp(char *lrlline, char *cmpto);
static void ttrap(struct timer_parm *parm);
int clear_temp_tables(void);
pthread_key_t comdb2_open_key;
/*---GLOBAL SETTINGS---*/
#define QUOTE_(x) #x
#define QUOTE(x) QUOTE_(x)
const char *const gbl_db_git_version_sha = QUOTE(GIT_VERSION_SHA=COMDB2_GIT_VERSION_SHA);
const char gbl_db_version[] = QUOTE(COMDB2_BUILD_VERSION);
const char gbl_db_semver[] = QUOTE(COMDB2_SEMVER);
const char gbl_db_codename[] = QUOTE(COMDB2_CODENAME);
const char gbl_db_buildtype[] = QUOTE(COMDB2_BUILD_TYPE);
int gbl_enque_flush_interval;
int gbl_enque_reorder_lookahead = 20;
int gbl_morecolumns = 0;
int gbl_return_long_column_names = 1;
int gbl_maxreclen;
int gbl_penaltyincpercent = 20;
int gbl_maxwthreadpenalty;
int gbl_spstrictassignments = 0;
int gbl_lock_conflict_trace = 0;
int gbl_move_deadlk_max_attempt = 500;
int gbl_uses_password;
int gbl_unauth_tag_access = 0;
int64_t gbl_num_auth_allowed = 0;
int64_t gbl_num_auth_denied = 0;
int gbl_uses_externalauth = 0;
int gbl_uses_externalauth_connect = 0;
int gbl_externalauth_warn = 0;
int gbl_identity_cache_max = 500;
int gbl_upd_key;
unsigned long long gbl_sqltick;
int gbl_watchdog_watch_threshold = 60;
int gbl_watchdog_disable_at_start = 0; /* don't enable watchdog on start */
int gbl_nonames = 1;
int gbl_reject_osql_mismatch = 1;
int gbl_abort_on_clear_inuse_rqid = 1;
pthread_t gbl_invalid_tid; /* set this to our main threads tid */
/* lots of defaults. */
int gbl_exit_on_pthread_create_fail = 1;
int gbl_exit_on_internal_error = 1;
int gbl_osql_blockproc_timeout_sec = 5; /* wait for 5 seconds for a blocproc*/
int gbl_osql_max_throttle_sec = 60 * 10; /* 10-minute default */
int gbl_osql_bkoff_netsend_lmt = 5 * 60 * 1000; /* 5 mins */
int gbl_osql_bkoff_netsend = 100; /* wait 100 msec */
int gbl_net_max_queue = 25000;
int gbl_net_max_mem = 0;
int gbl_net_poll = 100;
int gbl_net_throttle_percent = 50;
int gbl_osql_net_poll = 100;
int gbl_osql_max_queue = 10000;
int gbl_osql_net_portmux_register_interval = 600;
int gbl_net_portmux_register_interval = 600;
int gbl_serialise_sqlite3_open = 0;
int gbl_notimeouts = 0; /* set this if you don't need the server timeouts
(use this for new code testing) */
int gbl_nullfkey = 1;
/* Default fast sql timeouts */
int gbl_sqlwrtimeoutms = 10000;
long long gbl_converted_blocksql_requests = 0;
/* TODO: delete */
int gbl_rangextunit =
16; /* dont do more than 16 records in a single rangext op */
int gbl_honor_rangextunit_for_old_apis = 0;
/* various roles for the prefault helper threads. */
int gbl_prefaulthelper_blockops = 1;
int gbl_prefaulthelper_sqlreadahead = 1;
/* this many "next" ops trigger a readahead */
int gbl_sqlreadaheadthresh = 0;
int gbl_iothreads = 0;
int gbl_sqlreadahead = 0;
int gbl_ioqueue = 0;
int gbl_prefaulthelperthreads = 0;
int gbl_osqlpfault_threads = 0;
int gbl_prefault_udp = 0;
__thread int send_prefault_udp = 0;
__thread snap_uid_t *osql_snap_info; /* contains cnonce */
int gbl_starttime = 0;
int gbl_use_sqlthrmark = 1000;
int gbl_repchecksum = 0;
int gbl_pfault = 0;
int gbl_pfaultrmt = 1;
int gbl_dtastripe = 8;
int gbl_blobstripe = 1;
int gbl_rebuild_mode = 0;
int gbl_dbsizetime = 15 * 60; /* number of seconds for db size calculation */
int gbl_debug = 0; /* operation debugging */
int gbl_sdebug = 0; /* sql operation debugging */
int gbl_debug_until = 0; /* "debg" debugging */
int gbl_who = 0; /* "who" debugging */
int gbl_maxthreads = 48; /* max # of threads */
int gbl_maxwthreads = 8; /* max # of threads */
int gbl_maxqueue = 192; /* max pending requests.*/
int gbl_thd_linger = 5; /* number of seconds for threads to linger */
int gbl_report = 0; /* update rate to log */
int gbl_report_last;
long gbl_report_last_n;
long gbl_report_last_r;
char *gbl_myhostname; /* my hostname */
struct interned_string *gbl_myhostname_interned;
char *gbl_mycname; /* my cname */
struct in_addr gbl_myaddr; /* my IPV4 address */
int gbl_mynodeid = 0; /* node number, for backwards compatibility */
pid_t gbl_mypid; /* my pid */
char *gbl_myuri; /* added for fdb uri for this db: dbname@hostname */
int gbl_myroom;
int gbl_exit = 0; /* exit requested.*/
int gbl_create_mode = 0; /* turn on create-if-not-exists mode*/
const char *gbl_repoplrl_fname = NULL; /* if != NULL this is the fname of the
* external lrl file to create with
* this db's settings and table defs */
int gbl_local_mode = 0; /* local mode, no siblings */
int gbl_fullrecovery = 0; /* backend full-recovery mode*/
int gbl_maxretries = 500; /* thats a lotta retries */
int gbl_maxblobretries =
0; /* everyone assures me this can't happen unless the data is corrupt */
int gbl_maxcontextskips = 10000; /* that's a whole whale of a lotta retries */
int gbl_heartbeat_check = 0, gbl_heartbeat_send = 0, gbl_decom = 0;
int gbl_netbufsz = 1 * 1024 * 1024;
int gbl_loghist = 0;
int gbl_loghist_verbose = 0;
int gbl_repdebug = -1;
int gbl_elect_time_secs = 0;
char *gbl_pmblock = NULL;
int gbl_rtcpu_debug = 0;
int gbl_longblk_trans_purge_interval =
30; /* initially, set this to 30 seconds */
int gbl_sqlflush_freq = 0;
int gbl_sbuftimeout = 0;
int gbl_conv_flush_freq = 100; /* this is currently ignored */
pthread_attr_t gbl_pthread_attr;
int gbl_meta_lite = 1;
int gbl_context_in_key = 1;
int gbl_ready = 0; /* gets set just before waitft is called
and never gets unset */
static int gbl_db_is_exiting = 0; /* Indicates this process is exiting */
int gbl_debug_omit_dta_write;
int gbl_debug_omit_idx_write;
int gbl_debug_omit_blob_write;
int gbl_debug_omit_zap_on_rebuild = 0;
int gbl_debug_txn_sleep = 0;
int gbl_debug_skip_constraintscheck_on_insert;
int gbl_debug_pb_connectmsg_dbname_check = 0;
int gbl_debug_pb_connectmsg_gibberish = 0;
double gbl_query_plan_percentage = 50;
int gbl_readonly = 0;
int gbl_init_single_meta = 1;
int gbl_schedule = 0;
int gbl_init_with_rowlocks = 0;
int gbl_init_with_genid48 = 1;
int gbl_init_with_odh = 1;
int gbl_init_with_queue_odh = 1;
int gbl_init_with_queue_compr = BDB_COMPRESS_LZ4;
int gbl_init_with_queue_persistent_seq = 0;
int gbl_init_with_ipu = 1;
int gbl_init_with_instant_sc = 1;
int gbl_init_with_compr = BDB_COMPRESS_CRLE;
int gbl_init_with_compr_blobs = BDB_COMPRESS_LZ4;
int gbl_init_with_bthash = 0;
uint32_t gbl_nsql;
long long gbl_nsql_steps;
uint32_t gbl_nnewsql;
uint32_t gbl_nnewsql_ssl;
long long gbl_nnewsql_steps;
uint32_t gbl_masterrejects = 0;
volatile uint32_t gbl_analyze_gen = 0;
volatile int gbl_views_gen = 0;
int gbl_sqlhistsz = 25;
int gbl_lclpooled_buffers = 32;
int gbl_maxblockops = 25000;
int gbl_replicate_local = 0;
int gbl_replicate_local_concurrent = 0;
/* TMP BROKEN DATETIME */
int gbl_allowbrokendatetime = 1;
int gbl_sort_nulls_correctly = 1;
int gbl_check_client_tags = 1;
char *gbl_spfile_name = NULL;
char *gbl_timepart_file_name = NULL;
int gbl_max_lua_instructions = 10000;
int gbl_check_wrong_cmd = 1;
int gbl_updategenids = 0;
int gbl_osql_heartbeat_send = 5;
int gbl_osql_heartbeat_alert = 7;
int gbl_chkpoint_alarm_time = 60;
int gbl_incoherent_msg_freq = 60 * 60; /* one hour between messages */
int gbl_incoherent_alarm_time = 2 * 60; /* alarm if we are incoherent for
more than two minutes */
int gbl_max_incoherent_nodes = 1; /* immediate alarm if more than
this number of (online) nodes fall
incoherent */
int gbl_bad_lrl_fatal = 0;
int gbl_force_highslot = 0;
int gbl_num_contexts = 16;
int gbl_buffers_per_context = 255;
int gbl_max_columns_soft_limit = 255; /* this is the old hard limit */
int gbl_dispatch_rowlocks_bench = 1;
int gbl_rowlocks_bench_logical_rectype = 1;
int gbl_verbose_toblock_backouts = 0;
/* TODO */
int gbl_page_latches = 0;
int gbl_replicant_latches = 0;
int gbl_disable_update_shadows = 0;
int gbl_disable_rowlocks_logging = 0;
int gbl_disable_rowlocks = 0;
int gbl_disable_rowlocks_sleepns = 0;
int gbl_random_rowlocks = 0;
int gbl_already_aborted_trace = 0;
int gbl_deadlock_policy_override = -1;
int gbl_dump_sql_dispatched = 0; /* dump all sql strings dispatched */
int gbl_time_osql = 0; /* dump timestamps for osql steps */
int gbl_time_fdb = 0; /* dump timestamps for remote sql */
int gbl_goslow = 0; /* set to disable "gofast" */
int gbl_selectv_rangechk = 0; /* disable selectv range check by default */
int gbl_sql_tranlevel_preserved = SQL_TDEF_SOCK;
int gbl_sql_tranlevel_default = SQL_TDEF_SOCK;
int gbl_exit_alarm_sec = 300;
int gbl_test_blkseq_replay_code = 0;
int gbl_dump_blkseq = 0;
int gbl_test_curtran_change_code = 0;
int gbl_enable_pageorder_trace = 0;
int gbl_disable_deadlock_trace = 1;
int gbl_disable_overflow_page_trace = 1;
int gbl_simulate_rowlock_deadlock_interval = 0;
int gbl_enable_berkdb_retry_deadlock_bias = 0;
int gbl_enable_cache_internal_nodes = 1;
int gbl_use_appsock_as_sqlthread = 0;
int gbl_rep_process_txn_time = 0;
int gbl_utxnid_log = 1;
int gbl_commit_lsn_map = 1;
/* how many times we retry osql for verify */
int gbl_osql_verify_retries_max = 499;
/* extended verify-checking after this many failures */
int gbl_osql_verify_ext_chk = 1;
int gbl_test_badwrite_intvl = 0;
int gbl_test_blob_race = 0;
int gbl_skip_ratio_trace = 0;
int gbl_throttle_sql_overload_dump_sec = 5;
int gbl_toblock_net_throttle = 0;
int gbl_temptable_pool_capacity = 8192;
int gbl_ftables = 0;
/* cdb2 features */
int gbl_disable_skip_rows = 0;
#if 0
u_int gbl_blk_pq_shmkey = 0;
#endif
int gbl_round_robin_stripes = 0;
int gbl_num_record_converts = 100;
int gbl_rrenablecountchanges = 0;
int gbl_debug_log_twophase = 0;
int gbl_debug_log_twophase_transactions = 0;
int gbl_early_blkseq_check = 0;
int gbl_sql_time_threshold = 5000;
int gbl_allow_mismatched_tag_size = 0;
double gbl_sql_cost_error_threshold = -1;
int gbl_parallel_recovery_threads = 0;
int gbl_fdb_resolve_local = 0;
int gbl_fdb_allow_cross_classes = 0;
uint64_t gbl_sc_headroom = 10;
/*---COUNTS---*/
long n_qtrap;
long n_fstrap;
long n_qtrap_notcoherent;
long n_bad_parm;
long n_bad_swapin;
long n_retries;
long n_missed;
long n_dbinfo;
int n_commits;
long long n_commit_time; /* in micro seconds.*/
int n_retries_transaction_active = 0;
int n_retries_transaction_done = 0;
int gbl_num_rr_rejected = 0;
history *reqhist;
struct dbenv *thedb; /*handles 1 db for now*/
int gbl_exclusive_blockop_qconsume = 0;
pthread_rwlock_t gbl_block_qconsume_lock = PTHREAD_RWLOCK_INITIALIZER;
pthread_rwlock_t thedb_lock = PTHREAD_RWLOCK_INITIALIZER;
int gbl_malloc_regions = 1;
int gbl_rowlocks = 0;
int gbl_disable_tagged_api = 1;
int gbl_snapisol = 0;
int gbl_new_snapisol = 0;
int gbl_new_snapisol_asof = 0;
int gbl_new_snapisol_logging = 0;
int gbl_disable_new_snapshot = 0;
int gbl_newsi_use_timestamp_table = 0;
int gbl_update_shadows_interval = 0;
int gbl_lowpri_snapisol_sessions = 0;
int gbl_support_sock_luxref = 1;
int gbl_allow_user_schema;
struct quantize *q_min;
struct quantize *q_hour;
struct quantize *q_all;
struct quantize *q_sql_min;
struct quantize *q_sql_hour;
struct quantize *q_sql_all;
struct quantize *q_sql_steps_min;
struct quantize *q_sql_steps_hour;
struct quantize *q_sql_steps_all;
extern int gbl_net_lmt_upd_incoherent_nodes;
extern int gbl_skip_cget_in_db_put;
int gbl_argc;
char **gbl_argv;
int gbl_stop_thds_time = 0;
int gbl_stop_thds_time_threshold = 60;
pthread_mutex_t stop_thds_time_lk = PTHREAD_MUTEX_INITIALIZER;
int gbl_disallow_null_blobs = 1;
int gbl_force_notnull_static_tag_blobs = 1;
int gbl_key_updates = 1;
int gbl_partial_indexes = 1;
int gbl_expressions_indexes = 1;
int gbl_new_indexes = 0;
int gbl_optimize_truncate_repdb = 1;
static void set_datetime_dir(void);
extern void tz_hash_init(void);
extern void tz_hash_free(void);
void set_tzdir(char *dir);
void free_tzdir();
extern void init_sql_hint_table();
extern void init_clientstats_table();
extern int bdb_osql_log_repo_init(int *bdberr);
extern void set_stop_mempsync_thread();
extern void bdb_prepare_close(bdb_state_type *bdb_state);
extern void bdb_stop_recover_threads(bdb_state_type *bdb_state);
int gbl_use_plan = 1;
double gbl_querylimits_maxcost = 0;
int gbl_querylimits_tablescans_ok = 1;
int gbl_querylimits_temptables_ok = 1;
double gbl_querylimits_maxcost_warn = 0;
int gbl_querylimits_tablescans_warn = 0;
int gbl_querylimits_temptables_warn = 0;
extern int gbl_empty_strings_dont_convert_to_numbers;
extern int gbl_master_retry_poll_ms;
int gbl_check_schema_change_permissions = 1;
int gbl_print_syntax_err = 0;
extern int gbl_verify_direct_io;
extern int gbl_verify_lsn_written;
extern int gbl_parallel_memptrickle;
int gbl_verify_dbreg = 0;
extern int gbl_checkpoint_paranoid_verify;
int gbl_forbid_ulonglong = 1;
int gbl_support_datetime_in_triggers = 1;
int gbl_use_block_mode_status_code = 1;
unsigned int gbl_delayed_skip = 0;
int gbl_enable_osql_logging = 0;
int gbl_enable_osql_longreq_logging = 0;
int gbl_broken_num_parser = 0;
int gbl_fk_allow_prefix_keys = 1;
int gbl_fk_allow_superset_keys = 1;
int gbl_update_delete_limit = 1;
int verbose_deadlocks = 0;
int gbl_early = 1;
int gbl_reallyearly = 0;
int gbl_udp = 1;
int gbl_berkdb_verify_skip_skipables = 0;
int gbl_berkdb_epochms_repts = 0;
int gbl_disable_sql_dlmalloc = 0;
int gbl_decimal_rounding = DEC_ROUND_HALF_EVEN;
int gbl_sparse_lockerid_map = 1;
int gbl_inplace_blobs = 1;
int gbl_osql_blob_optimization = 1;
int gbl_inplace_blob_optimization = 1;
int gbl_report_sqlite_numeric_conversion_errors = 1;
int gbl_max_sql_hint_cache = 100;
unsigned long long gbl_untouched_blob_cnt = 0;
unsigned long long gbl_update_genid_blob_cnt = 0;
unsigned long long gbl_inplace_blob_cnt = 0;
unsigned long long gbl_delupd_blob_cnt = 0;
unsigned long long gbl_addupd_blob_cnt = 0;
unsigned long long gbl_rowlocks_deadlock_retries = 0;
int gbl_use_fastseed_for_comdb2_seqno = 0;
int gbl_disable_stable_for_ipu = 1;
int gbl_disable_exit_on_thread_error = 0;
int gbl_berkdb_iomap = 1;
int gbl_check_dbnum_conflicts = 1;
int gbl_requeue_on_tran_dispatch = 1;
int gbl_crc32c = 1;
int gbl_repscore = 0;
int gbl_surprise = 1; // TODO: change name to something else
int gbl_check_wrong_db = 1;
int gbl_broken_max_rec_sz = 0;
int gbl_private_blkseq = 1;
int gbl_use_blkseq = 1;
int gbl_reorder_socksql_no_deadlock = 0;
int gbl_reorder_idx_writes = 0;
char *gbl_recovery_options = NULL;
int gbl_rcache = 0;
int gbl_check_sql_source = 0;
int skip_clear_queue_extents = 0;
int gbl_flush_check_active_peer = 1;
int gbl_ctrace_dbdir = 0;
int gbl_inflate_log = 0;
int gbl_skip_llmeta_progress_updates_on_schema_change = 0;
int gbl_sc_inco_chk = 1;
int gbl_track_queue_time = 1;
int gbl_locks_check_waiters = 1;
int gbl_update_startlsn_printstep = 0;
int gbl_rowlocks_commit_on_waiters = 1;
int gbl_rowlocks_deadlock_trace = 0;
int gbl_durable_wait_seqnum_test = 0;
int gbl_durable_replay_test = 0;
int gbl_durable_set_trace = 0;
int gbl_durable_calc_trace = 0;
int gbl_dumptxn_at_commit = 0;
char *gbl_crypto = NULL;
int gbl_log_fstsnd_triggers = 0;
int gbl_broadcast_check_rmtpol = 1;
int gbl_replicate_rowlocks = 1;
int gbl_replicant_gather_rowlocks = 1;
int gbl_force_old_cursors = 0;
int gbl_track_curtran_locks = 0;
int gbl_print_deadlock_cycles = 100;
int gbl_always_send_cnonce = 1;
int gbl_dump_page_on_byteswap_error = 0;
int gbl_dump_after_byteswap = 0;
int gbl_micro_retry_on_deadlock = 1;
int gbl_disable_blob_check = 0;
int gbl_disable_new_snapisol_overhead = 0;
int gbl_verify_all_pools = 0;
int gbl_print_blockp_stats = 0;
int gbl_allow_parallel_rep_on_pagesplit = 1;
int gbl_allow_parallel_rep_on_prefix = 1;
// XXX remove before merging jepsen
int gbl_only_match_commit_records = 1;
/* Release locks if replication is waiting on a lock you hold (si-only) */
int gbl_sql_release_locks_on_si_lockwait = 1;
/* If this is set, recom_replay will see the same row multiple times in a scan &
* fail */
int gbl_sql_release_locks_on_emit_row = 0;
int gbl_sql_release_locks_on_slow_reader = 1;
int gbl_sql_no_timeouts_on_release_locks = 1;
int gbl_sql_release_locks_in_update_shadows = 1;
int gbl_sql_random_release_interval = 0;
int gbl_sql_release_locks_trace = 0;
int gbl_lock_get_verbose_waiter = 0;
int gbl_lock_get_list_start = 0;
int gbl_dump_locks_on_repwait = 0;
int gbl_slow_rep_process_txn_maxms = 0;
int gbl_slow_rep_process_txn_minms = 0;
int gbl_slow_rep_process_txn_freq = 0;
int gbl_check_page_in_recovery = 0;
int gbl_cmptxn_inherit_locks = 1;
int gbl_rep_printlock = 0;
int gbl_keycompr = 1;
int gbl_memstat_freq = 60 * 5;
int gbl_accept_on_child_nets = 0;
int gbl_disable_etc_services_lookup = 0;
int gbl_fingerprint_queries = 1;
int gbl_query_plans = 1;
int gbl_prioritize_queries = 1;
int gbl_verbose_normalized_queries = 0;
int gbl_verbose_prioritize_queries = 0;
int gbl_stable_rootpages_test = 0;
/* Only allows the ability to enable: must be enabled on a session via 'set' */
int gbl_allow_incoherent_sql = 0;
char *gbl_dbdir = NULL;
int gbl_backup_logfiles = 0;
static int gbl_backend_opened = 0;
extern int gbl_verbose_net;
static void create_service_file(const char *lrlname);
/* FOR PAGE COMPACTION.
The threshold should be kept under 0.5. By default, we make it lg(2)/2
(see comment in bdb/rep.c to learn more about expected node utilization). */
/* Disabling for the time being */
double gbl_pg_compact_thresh = 0;
int gbl_pg_compact_latency_ms = 0;
int gbl_large_str_idx_find = 1;
int gbl_abort_invalid_query_info_key;
extern int gbl_direct_count;
extern int gbl_parallel_count;
extern int gbl_debug_sqlthd_failures;
extern int gbl_random_get_curtran_failures;
extern int gbl_random_blkseq_replays;
extern int gbl_disable_cnonce_blkseq;
extern int gbl_create_dba_user;
int gbl_mifid2_datetime_range = 1;
int gbl_early_verify = 1;
int gbl_bbenv;
extern int gbl_legacy_defaults;
int64_t gbl_temptable_created;
int64_t gbl_temptable_create_reqs;
int64_t gbl_temptable_spills;
int gbl_osql_odh_blob = 1;
int gbl_clean_exit_on_sigterm = 1;
int gbl_is_physical_replicant;
int gbl_server_admin_mode = 0;
comdb2_tunables *gbl_tunables; /* All registered tunables */
int init_gbl_tunables();
int free_gbl_tunables();
int register_db_tunables(struct dbenv *tbl);
int destroy_plugins(void);
void register_plugin_tunables(void);
int install_static_plugins(void);
int run_init_plugins(int phase);
extern void clear_sqlhist();
int gbl_hostname_refresh_time = 60;
int gbl_pstack_self = 1;
char *gbl_cdb2api_policy_override = NULL;
int close_all_dbs_tran(tran_type *tran);
int open_all_dbs_tran(void *tran);
int reload_lua_sfuncs();
int reload_lua_afuncs();
void oldfile_clear(void);
inline int getkeyrecnums(const dbtable *tbl, int ixnum)
{
if (ixnum < 0 || ixnum >= tbl->nix)
return -1;
return tbl->ix_recnums[ixnum] != 0;
}
inline int getkeysize(const dbtable *tbl, int ixnum)
{
if (ixnum < 0 || ixnum >= tbl->nix)
return -1;
return tbl->ix_keylen[ixnum];
}
inline int getdatsize(const dbtable *tbl)
{
return tbl->lrl;
}
/*lookup dbs..*/
dbtable *getdbbynum(int num)
{
int ii;
dbtable *p_db = NULL;
Pthread_rwlock_rdlock(&thedb_lock);
for (ii = 0; ii < thedb->num_dbs; ii++) {
if (thedb->dbs[ii]->dbnum == num) {
p_db = thedb->dbs[ii];
break;
}
}
Pthread_rwlock_unlock(&thedb_lock);
return p_db;
}
static inline dbtable *_db_hash_find(const char *p_name)
{
dbtable *tbl;
tbl = hash_find_readonly(thedb->db_hash, &p_name);
if (!tbl)
tbl = hash_find_readonly(thedb->sqlalias_hash, &p_name);
return tbl;
}
static inline void _db_hash_add(dbtable *tbl)
{
hash_add(thedb->db_hash, tbl);
if (tbl->sqlaliasname)
hash_add(thedb->sqlalias_hash, tbl);
}
static inline void _db_hash_del(dbtable *tbl)
{
hash_del(thedb->db_hash, tbl);
if (tbl->sqlaliasname)
hash_del(thedb->sqlalias_hash, tbl);
}
/* get the index offset of table tablename in thedb->dbs array
* notice that since the caller does not hold the lock, accessing
* thedb->dbs[idx] can result in undefined behavior if that table
* is dropped and idx would point to a different table or worse
*/
int get_dbtable_idx_by_name(const char *tablename)
{
struct dbtable *table = get_dbtable_by_name(tablename);
return table ? table->dbs_idx : -1;
}
dbtable *get_dbtable_by_name(const char *p_name)
{
dbtable *p_db = NULL;
Pthread_rwlock_rdlock(&thedb_lock);
p_db = _db_hash_find(p_name);
Pthread_rwlock_unlock(&thedb_lock);
if (!p_db && !strcmp(p_name, COMDB2_STATIC_TABLE))
p_db = &thedb->static_table;
return p_db;
}
dbtable *getqueuebyname(const char *name)
{
return hash_find_readonly(thedb->qdb_hash, &name);
}
int get_max_reclen(struct dbenv *dbenv)
{
int max = -1;
char *fname, fname_tail[] = "_file_vers_map";
int file, fnamelen;
SBUF2 *sbfile;
char line[256];
char tablename[64];
int reclen;
int rc;
/* get the mem we need for fname */
fnamelen = strlen(dbenv->basedir) + strlen(dbenv->envname) +
strlen(fname_tail) + 2 /* one for / and one for NULL byte */;
fname = malloc(fnamelen);
if (!fname) {
logmsg(LOGMSG_ERROR, "get_max_reclen: failed to malloc file name\n");
return -1;
}
/* construct the file's name */
if (gbl_nonames)
rc = snprintf(fname, fnamelen, "%s/file_vers_map", dbenv->basedir);
else
rc = snprintf(fname, fnamelen, "%s/%s%s", dbenv->basedir,
dbenv->envname, fname_tail);
if (rc < 0 || rc >= fnamelen) {
logmsg(LOGMSG_ERROR, "get_max_reclen: failed to create file name\n");
free(fname);
return -1;
}
/* open file */
file = open(fname, O_RDONLY);
if (file == -1) {
logmsg(LOGMSG_ERROR, "get_max_reclen: failed to open %s for writing\n",
fname);
free(fname);
return -1;
}
free(fname);
sbfile = sbuf2open(file, 0);
if (!sbfile) {
logmsg(LOGMSG_ERROR, "get_max_reclen: failed to open sbuf2\n");
close(file);
return -1;
}
while (sbuf2gets(line, 256, sbfile) > 0) {
reclen = 0;
sscanf(line, "table %s %d\n", tablename, &reclen);
if (reclen) {
if (strncmp(tablename, "sqlite_stat", 11) != 0) {
if (reclen > max)
max = reclen;
}
}
}
sbuf2close(sbfile);
return max;
}
void showdbenv(struct dbenv *dbenv)
{
int ii, jj;
dbtable *usedb;
logmsg(LOGMSG_USER, "-----\n");
for (jj = 0; jj < dbenv->num_dbs; jj++) {
usedb = dbenv->dbs[jj]; /*de-stink*/
logmsg(LOGMSG_USER,
"table '%s' comdbg compat dbnum %d\ndir '%s' lrlfile '%s' "
"nconns %zu nrevconns %zu\n",
usedb->tablename, usedb->dbnum, dbenv->basedir, (usedb->lrlfname) ? usedb->lrlfname : "NULL",
usedb->n_constraints, usedb->n_rev_constraints);
logmsg(LOGMSG_ERROR, " data reclen %-3d bytes\n", usedb->lrl);
for (ii = 0; ii < usedb->nix; ii++) {
logmsg(LOGMSG_USER,
" index %-2d keylen %-3d bytes dupes? %c recnums? %c"
" datacopy? %c collattr? %c uniqnulls %c datacopylen %-3d bytes\n",
ii, usedb->ix_keylen[ii], (usedb->ix_dupes[ii] ? 'y' : 'n'), (usedb->ix_recnums[ii] ? 'y' : 'n'),
(usedb->ix_datacopy[ii] ? 'y' : 'n'), (usedb->ix_collattr[ii] ? 'y' : 'n'),