-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy pathosqlcomm.c
8959 lines (7536 loc) · 301 KB
/
osqlcomm.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, 2017, 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.
*/
#include <strings.h>
#include <errno.h>
#include <poll.h>
#include <util.h>
#include "osqlcomm.h"
#include "osqlsession.h"
#include "osqlsqlthr.h"
#include "sqloffload.h"
#include "osqlcheckboard.h"
#include "osqlrepository.h"
#include "osqlblockproc.h"
#include <compile_time_assert.h>
#include <netinet/in.h>
#include <endian_core.h>
#include <alloca.h>
#include "comdb2.h"
#include "net.h"
#include "sqlstat1.h"
#include <ctrace.h>
#include "comdb2uuid.h"
#include "socket_interfaces.h"
#include "debug_switches.h"
#include <schemachange.h>
#include <genid.h>
#include <flibc.h>
#include <net_types.h>
#include <errstat.h>
#include "cron.h"
#include <bpfunc.h>
#include <strbuf.h>
#include "logmsg.h"
#include "reqlog.h"
#include "views.h"
#include "str0.h"
#include "sc_struct.h"
#include <compat.h>
#include <unistd.h>
#include "osqlsqlnet.h"
#include "osqlsqlsocket.h"
#include "sc_global.h"
#include "logical_cron.h"
#include "sc_logic.h"
#include "eventlog.h"
#include <disttxn.h>
#define MAX_CLUSTER REPMAX
/**
* NOTE: the assumption here is that there are no more comm users
* when g_osql_ready is reset. This is done by closing all possible
* sqlthread and appsock threads before disabling g_osql_ready.
*
*/
extern __thread int send_prefault_udp;
extern int gbl_prefault_udp;
extern int g_osql_ready;
extern int gbl_goslow;
extern int gbl_partial_indexes;
int gbl_master_sends_query_effects = 1;
int gbl_toblock_random_deadlock_trans;
int gbl_toblock_random_verify_error;
int gbl_selectv_writelock = 0;
int gbl_debug_invalid_genid;
int gbl_partition_sc_reorder = 1;
extern int db_is_exiting();
static int osql_net_type_to_net_uuid_type(int type);
static void osql_extract_snap_info(osql_sess_t *sess, void *rpl, int rpllen);
#ifdef XMACRO_OSQL_RPL_TYPES
# undef XMACRO_OSQL_RPL_TYPES
#endif
#define XMACRO_OSQL_RPL_TYPES(a, b, c) case a: osql_rpl_type_to_str = c; break;
#define OSQL_RPL_TYPE_TO_STR(type) \
({ \
char *osql_rpl_type_to_str = "UNKNOWN"; \
switch (type) { \
OSQL_RPL_TYPES \
} \
osql_rpl_type_to_str; \
})
const char *osql_reqtype_str(int type)
{
assert(0 <= type && type < MAX_OSQL_TYPES);
return OSQL_RPL_TYPE_TO_STR(type);
}
typedef struct osql_blknds {
char *nds[MAX_CLUSTER]; /* list of nodes to blackout in offloading */
time_t times[MAX_CLUSTER]; /* time of blacking out */
int n; /* 0..n-1 nodes valid in blknds */
time_t delta; /* blackout window in seconds */
time_t heartbeat[MAX_CLUSTER]; /* the last heartbeat received; used to
select active nodes only */
time_t delta_hbeat; /* heartbeat timestamp cannot be older than delta_hbeat
seconds */
} osql_blknds_t;
typedef struct osql_comm {
void *
handle_sibling; /* pointer to netinfo structure supporting offloading */
} osql_comm_t;
typedef struct osql_poke {
unsigned long long rqid; /* look for this session id */
int tstamp; /* when this was sent */
short from; /* who sent this (i.e. the master) */
short to; /* intended offloading node */
} osql_poke_t;
typedef struct osql_poke_uuid {
uuid_t uuid; /* look for this session id */
int tstamp; /* when this was sent */
} osql_poke_uuid_t;
enum { OSQLCOMM_POKE_TYPE_LEN = 8 + 4 + 2 + 2 };
enum { OSQLCOMM_POKE_UUID_TYPE_LEN = 16 + 4 };
BB_COMPILE_TIME_ASSERT(osqlcomm_poke_type_len,
sizeof(osql_poke_t) == OSQLCOMM_POKE_TYPE_LEN);
BB_COMPILE_TIME_ASSERT(osqlcomm_poke_uuid_type_len,
sizeof(osql_poke_uuid_t) == OSQLCOMM_POKE_UUID_TYPE_LEN);
static uint8_t *osqlcomm_poke_type_put(const osql_poke_t *p_poke_type,
uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_POKE_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_put(&(p_poke_type->rqid), sizeof(p_poke_type->rqid), p_buf,
p_buf_end);
p_buf = buf_put(&(p_poke_type->tstamp), sizeof(p_poke_type->tstamp), p_buf,
p_buf_end);
p_buf = buf_put(&(p_poke_type->from), sizeof(p_poke_type->from), p_buf,
p_buf_end);
p_buf =
buf_put(&(p_poke_type->to), sizeof(p_poke_type->to), p_buf, p_buf_end);
return p_buf;
}
static const uint8_t *osqlcomm_poke_type_get(osql_poke_t *p_poke_type,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_POKE_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_get(&(p_poke_type->rqid), sizeof(p_poke_type->rqid), p_buf,
p_buf_end);
p_buf = buf_get(&(p_poke_type->tstamp), sizeof(p_poke_type->tstamp), p_buf,
p_buf_end);
p_buf = buf_get(&(p_poke_type->from), sizeof(p_poke_type->from), p_buf,
p_buf_end);
p_buf =
buf_get(&(p_poke_type->to), sizeof(p_poke_type->to), p_buf, p_buf_end);
return p_buf;
}
static uint8_t *osqlcomm_poke_uuid_type_put(const osql_poke_uuid_t *p_poke_type,
uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_POKE_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_no_net_put(p_poke_type->uuid, sizeof(p_poke_type->uuid), p_buf,
p_buf_end);
p_buf = buf_put(&(p_poke_type->tstamp), sizeof(p_poke_type->tstamp), p_buf,
p_buf_end);
return p_buf;
}
static const uint8_t *osqlcomm_poke_uuid_type_get(osql_poke_uuid_t *p_poke_type,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_POKE_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_no_net_get(p_poke_type->uuid, sizeof(p_poke_type->uuid), p_buf,
p_buf_end);
p_buf = buf_get(&(p_poke_type->tstamp), sizeof(p_poke_type->tstamp), p_buf,
p_buf_end);
return p_buf;
}
typedef struct osql_echo {
int nonce;
int idx;
unsigned long long snt;
unsigned long long rcv;
} osql_echo_t;
enum { OSQLCOMM_ECHO_TYPE_LEN = 4 + 4 + 8 + 8 };
BB_COMPILE_TIME_ASSERT(osqlcomm_echo_type_len,
sizeof(osql_echo_t) == OSQLCOMM_ECHO_TYPE_LEN);
static uint8_t *osqlcomm_echo_type_put(const osql_echo_t *p_echo_type,
uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_ECHO_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_put(&(p_echo_type->nonce), sizeof(p_echo_type->nonce), p_buf,
p_buf_end);
p_buf = buf_put(&(p_echo_type->idx), sizeof(p_echo_type->idx), p_buf,
p_buf_end);
p_buf = buf_put(&(p_echo_type->snt), sizeof(p_echo_type->snt), p_buf,
p_buf_end);
p_buf = buf_put(&(p_echo_type->rcv), sizeof(p_echo_type->rcv), p_buf,
p_buf_end);
return p_buf;
}
static const uint8_t *osqlcomm_echo_type_get(osql_echo_t *p_echo_type,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_ECHO_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_get(&(p_echo_type->nonce), sizeof(p_echo_type->nonce), p_buf,
p_buf_end);
p_buf = buf_get(&(p_echo_type->idx), sizeof(p_echo_type->idx), p_buf,
p_buf_end);
p_buf = buf_get(&(p_echo_type->snt), sizeof(p_echo_type->snt), p_buf,
p_buf_end);
p_buf = buf_get(&(p_echo_type->rcv), sizeof(p_echo_type->rcv), p_buf,
p_buf_end);
return p_buf;
}
/* messages */
struct osql_req {
enum OSQL_REQ_TYPE type;
int rqlen;
int sqlqlen;
int padding;
unsigned long long rqid; /* fastseed */
char tzname[DB_MAX_TZNAMEDB];
unsigned char unused;
unsigned char flags;
char pad[1];
char sqlq[1];
};
enum { OSQLCOMM_REQ_TYPE_LEN = 8 + 4 + 4 + 8 + DB_MAX_TZNAMEDB + 3 + 1 };
BB_COMPILE_TIME_ASSERT(osqlcomm_req_type_len,
sizeof(struct osql_req) == OSQLCOMM_REQ_TYPE_LEN);
static uint8_t *osqlcomm_req_type_put(const struct osql_req *p_osql_req,
uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_REQ_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
#if 0
p_buf = buf_no_net_put(&(p_osql_req->pad), sizeof(p_osql_req->pad), p_buf,
p_buf_end);
#endif
p_buf =
buf_put(&p_osql_req->type, sizeof(p_osql_req->type), p_buf, p_buf_end);
p_buf = buf_put(&p_osql_req->rqlen, sizeof(p_osql_req->rqlen), p_buf,
p_buf_end);
p_buf = buf_put(&p_osql_req->sqlqlen, sizeof(p_osql_req->sqlqlen), p_buf,
p_buf_end);
p_buf = buf_put(&p_osql_req->padding, sizeof(p_osql_req->padding), p_buf,
p_buf_end);
p_buf =
buf_put(&p_osql_req->rqid, sizeof(p_osql_req->rqid), p_buf, p_buf_end);
p_buf = buf_put(&p_osql_req->tzname, sizeof(p_osql_req->tzname), p_buf,
p_buf_end);
p_buf = buf_put(&p_osql_req->unused, sizeof(p_osql_req->unused), p_buf,
p_buf_end);
p_buf = buf_put(&p_osql_req->flags, sizeof(p_osql_req->flags), p_buf,
p_buf_end);
p_buf =
buf_put(&p_osql_req->pad, sizeof(p_osql_req->pad), p_buf, p_buf_end);
return p_buf;
}
static const uint8_t *osqlcomm_req_type_get(struct osql_req *p_osql_req,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_REQ_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_get(&(p_osql_req->type), sizeof(p_osql_req->type), p_buf,
p_buf_end);
p_buf = buf_get(&p_osql_req->rqlen, sizeof(p_osql_req->rqlen), p_buf,
p_buf_end);
p_buf = buf_get(&p_osql_req->sqlqlen, sizeof(p_osql_req->sqlqlen), p_buf,
p_buf_end);
p_buf = buf_get(&p_osql_req->padding, sizeof(p_osql_req->padding), p_buf,
p_buf_end);
p_buf =
buf_get(&p_osql_req->rqid, sizeof(p_osql_req->rqid), p_buf, p_buf_end);
p_buf = buf_get(&p_osql_req->tzname, sizeof(p_osql_req->tzname), p_buf,
p_buf_end);
p_buf = buf_get(&p_osql_req->unused, sizeof(p_osql_req->unused), p_buf,
p_buf_end);
p_buf = buf_get(&p_osql_req->flags, sizeof(p_osql_req->flags), p_buf,
p_buf_end);
p_buf =
buf_get(&p_osql_req->pad, sizeof(p_osql_req->pad), p_buf, p_buf_end);
return (const uint8_t *)p_buf;
}
struct osql_uuid_req {
enum OSQL_REQ_TYPE type;
int rqlen;
int sqlqlen;
int flags;
uuid_t uuid;
char tzname[DB_MAX_TZNAMEDB];
unsigned char unused;
char pad[2];
char sqlq[1];
};
enum { OSQLCOMM_REQ_UUID_TYPE_LEN = 8 + 4 + 4 + 16 + DB_MAX_TZNAMEDB + 3 + 1 };
BB_COMPILE_TIME_ASSERT(osqlcomm_req_uuid_type_len,
sizeof(struct osql_req) == OSQLCOMM_REQ_TYPE_LEN);
static uint8_t *
osqlcomm_req_uuid_type_put(const struct osql_uuid_req *p_osql_req,
uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_REQ_UUID_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf =
buf_put(&p_osql_req->type, sizeof(p_osql_req->type), p_buf, p_buf_end);
p_buf = buf_put(&p_osql_req->rqlen, sizeof(p_osql_req->rqlen), p_buf,
p_buf_end);
p_buf = buf_put(&p_osql_req->sqlqlen, sizeof(p_osql_req->sqlqlen), p_buf,
p_buf_end);
p_buf = buf_put(&p_osql_req->flags, sizeof(p_osql_req->flags), p_buf,
p_buf_end);
p_buf = buf_no_net_put(&p_osql_req->uuid, sizeof(p_osql_req->uuid), p_buf,
p_buf_end);
p_buf = buf_put(&p_osql_req->tzname, sizeof(p_osql_req->tzname), p_buf,
p_buf_end);
p_buf = buf_put(&p_osql_req->unused, sizeof(p_osql_req->unused), p_buf,
p_buf_end);
p_buf =
buf_put(&p_osql_req->pad, sizeof(p_osql_req->pad), p_buf, p_buf_end);
return p_buf;
}
static const uint8_t *
osqlcomm_req_uuid_type_get(struct osql_uuid_req *p_osql_req,
const uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_REQ_UUID_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_get(&(p_osql_req->type), sizeof(p_osql_req->type), p_buf,
p_buf_end);
p_buf = buf_get(&p_osql_req->rqlen, sizeof(p_osql_req->rqlen), p_buf,
p_buf_end);
p_buf = buf_get(&p_osql_req->sqlqlen, sizeof(p_osql_req->sqlqlen), p_buf,
p_buf_end);
p_buf = buf_get(&p_osql_req->flags, sizeof(p_osql_req->flags), p_buf,
p_buf_end);
p_buf =
buf_get(&p_osql_req->uuid, sizeof(p_osql_req->uuid), p_buf, p_buf_end);
p_buf = buf_get(&p_osql_req->tzname, sizeof(p_osql_req->tzname), p_buf,
p_buf_end);
p_buf = buf_get(&p_osql_req->unused, sizeof(p_osql_req->unused), p_buf,
p_buf_end);
p_buf =
buf_get(&p_osql_req->pad, sizeof(p_osql_req->pad), p_buf, p_buf_end);
return (const uint8_t *)p_buf;
}
typedef struct osql_rpl {
/* keep this header aligned head and tail! */
enum OSQL_RPL_TYPE type;
int padding;
unsigned long long sid; /* concurrent access */
} osql_rpl_t;
enum { OSQLCOMM_RPL_TYPE_LEN = 4 + 4 + 8 };
BB_COMPILE_TIME_ASSERT(osqlcomm_rpl_type_len,
sizeof(osql_rpl_t) == OSQLCOMM_RPL_TYPE_LEN);
static uint8_t *osqlcomm_rpl_type_put(const osql_rpl_t *p_osql_rpl,
uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_RPL_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_put(&(p_osql_rpl->type), sizeof(p_osql_rpl->type), p_buf,
p_buf_end);
p_buf = buf_no_net_put(&(p_osql_rpl->padding), sizeof(p_osql_rpl->padding),
p_buf, p_buf_end);
if (p_osql_rpl->sid == 0)
abort();
p_buf =
buf_put(&(p_osql_rpl->sid), sizeof(p_osql_rpl->sid), p_buf, p_buf_end);
return p_buf;
}
/*static const uint8_t *osqlcomm_rpl_type_get(osql_rpl_t *p_osql_rpl, const
* uint8_t */
const uint8_t *osqlcomm_rpl_type_get(osql_rpl_t *p_osql_rpl,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_RPL_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_get(&(p_osql_rpl->type), sizeof(p_osql_rpl->type), p_buf,
p_buf_end);
p_buf = buf_no_net_get(&(p_osql_rpl->padding), sizeof(p_osql_rpl->padding),
p_buf, p_buf_end);
p_buf =
buf_get(&(p_osql_rpl->sid), sizeof(p_osql_rpl->sid), p_buf, p_buf_end);
return p_buf;
}
typedef struct osql_rpl_uuid {
enum OSQL_RPL_TYPE type;
int padding;
uuid_t uuid;
} osql_uuid_rpl_t;
enum { OSQLCOMM_UUID_RPL_TYPE_LEN = 4 + 4 + 16 };
BB_COMPILE_TIME_ASSERT(osqlcomm_rpl_uuid_type_len,
sizeof(osql_uuid_rpl_t) == OSQLCOMM_UUID_RPL_TYPE_LEN);
uuid_t zero_uuid = {0};
static uint8_t *osqlcomm_uuid_rpl_type_put(const osql_uuid_rpl_t *p_osql_rpl,
uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_UUID_RPL_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
if (!memcmp(&p_osql_rpl->uuid, &zero_uuid, sizeof(uuid_t)))
abort();
p_buf = buf_put(&(p_osql_rpl->type), sizeof(p_osql_rpl->type), p_buf,
p_buf_end);
p_buf = buf_no_net_put(&(p_osql_rpl->padding), sizeof(p_osql_rpl->padding),
p_buf, p_buf_end);
p_buf = buf_no_net_put(&(p_osql_rpl->uuid), sizeof(p_osql_rpl->uuid), p_buf,
p_buf_end);
return p_buf;
}
/*static const uint8_t *osqlcomm_rpl_type_get(osql_rpl_t *p_osql_rpl, const
* uint8_t */
const uint8_t *osqlcomm_uuid_rpl_type_get(osql_uuid_rpl_t *p_osql_rpl,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_UUID_RPL_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_get(&(p_osql_rpl->type), sizeof(p_osql_rpl->type), p_buf,
p_buf_end);
p_buf = buf_no_net_get(&(p_osql_rpl->padding), sizeof(p_osql_rpl->padding),
p_buf, p_buf_end);
p_buf = buf_get(&(p_osql_rpl->uuid), sizeof(p_osql_rpl->uuid), p_buf,
p_buf_end);
return p_buf;
}
typedef struct osql_del {
unsigned long long genid;
unsigned long long dk; /* flag to indicate which keys to modify */
} osql_del_t;
enum { OSQLCOMM_DEL_TYPE_LEN = 8 + 8 };
BB_COMPILE_TIME_ASSERT(osqlcomm_del_type_len,
sizeof(osql_del_t) == OSQLCOMM_DEL_TYPE_LEN);
static uint8_t *osqlcomm_del_type_put(const osql_del_t *p_osql_del,
uint8_t *p_buf, const uint8_t *p_buf_end,
int send_dk)
{
if (p_buf_end < p_buf ||
(send_dk ? OSQLCOMM_DEL_TYPE_LEN
: OSQLCOMM_DEL_TYPE_LEN - sizeof(unsigned long long)) >
(p_buf_end - p_buf))
return NULL;
p_buf = buf_no_net_put(&(p_osql_del->genid), sizeof(p_osql_del->genid),
p_buf, p_buf_end);
if (send_dk)
p_buf = buf_no_net_put(&(p_osql_del->dk), sizeof(p_osql_del->dk), p_buf,
p_buf_end);
return p_buf;
}
static const uint8_t *osqlcomm_del_type_get(osql_del_t *p_osql_del,
const uint8_t *p_buf,
const uint8_t *p_buf_end,
int recv_dk)
{
if (p_buf_end < p_buf ||
(recv_dk ? OSQLCOMM_DEL_TYPE_LEN
: OSQLCOMM_DEL_TYPE_LEN - sizeof(unsigned long long)) >
(p_buf_end - p_buf))
return NULL;
p_buf = buf_no_net_get(&(p_osql_del->genid), sizeof(p_osql_del->genid),
p_buf, p_buf_end);
if (recv_dk)
p_buf = buf_no_net_get(&(p_osql_del->dk), sizeof(p_osql_del->dk), p_buf,
p_buf_end);
return p_buf;
}
typedef struct {
osql_uuid_rpl_t hd;
genid_t genid;
} osql_dbq_consume_uuid_t;
typedef struct {
osql_rpl_t hd;
genid_t genid;
} osql_dbq_consume_t;
typedef struct osql_del_rpl {
osql_rpl_t hd;
osql_del_t dt;
} osql_del_rpl_t;
enum {
OSQLCOMM_OSQL_DEL_RPL_TYPE_LEN =
OSQLCOMM_RPL_TYPE_LEN + OSQLCOMM_DEL_TYPE_LEN
};
BB_COMPILE_TIME_ASSERT(osqlcomm_del_rpl_type_len,
sizeof(osql_del_rpl_t) ==
OSQLCOMM_OSQL_DEL_RPL_TYPE_LEN);
static uint8_t *osqlcomm_del_rpl_type_put(osql_del_rpl_t *p_del_rpl,
uint8_t *p_buf, uint8_t *p_buf_end,
int send_dk)
{
if (p_buf_end < p_buf ||
(send_dk ? OSQLCOMM_OSQL_DEL_RPL_TYPE_LEN
: OSQLCOMM_OSQL_DEL_RPL_TYPE_LEN -
sizeof(unsigned long long)) > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_rpl_type_put(&(p_del_rpl->hd), p_buf, p_buf_end);
p_buf = osqlcomm_del_type_put(&(p_del_rpl->dt), p_buf, p_buf_end, send_dk);
return p_buf;
}
/* startgen */
typedef struct osql_startgen {
unsigned int start_gen;
int padding;
} osql_startgen_t;
enum { OSQLCOMM_STARTGEN_TYPE_LEN = 8 };
BB_COMPILE_TIME_ASSERT(osqlcomm_startgen_type_len,
sizeof(osql_startgen_t) == OSQLCOMM_STARTGEN_TYPE_LEN);
static uint8_t *
osqlcomm_startgen_type_put(const osql_startgen_t *p_osql_startgen,
uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_STARTGEN_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_put(&(p_osql_startgen->start_gen),
sizeof(p_osql_startgen->start_gen), p_buf, p_buf_end);
p_buf = buf_put(&(p_osql_startgen->padding),
sizeof(p_osql_startgen->padding), p_buf, p_buf_end);
return p_buf;
}
const uint8_t *osqlcomm_startgen_type_get(osql_startgen_t *p_osql_startgen,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_STARTGEN_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_get(&(p_osql_startgen->start_gen),
sizeof(p_osql_startgen->start_gen), p_buf, p_buf_end);
return p_buf;
}
typedef struct osql_startgen_rpl {
osql_rpl_t hd;
osql_startgen_t dt;
} osql_startgen_rpl_t;
enum {
OSQLCOMM_STARTGEN_RPL_LEN =
OSQLCOMM_RPL_TYPE_LEN + OSQLCOMM_STARTGEN_TYPE_LEN
};
BB_COMPILE_TIME_ASSERT(osqlcomm_startgen_rpl_len,
sizeof(osql_startgen_rpl_t) ==
OSQLCOMM_STARTGEN_RPL_LEN);
static uint8_t *
osqlcomm_startgen_rpl_type_put(const osql_startgen_rpl_t *p_startgen_rpl,
uint8_t *p_buf, uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_STARTGEN_RPL_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_rpl_type_put(&(p_startgen_rpl->hd), p_buf, p_buf_end);
p_buf = osqlcomm_startgen_type_put(&(p_startgen_rpl->dt), p_buf, p_buf_end);
return p_buf;
}
static const uint8_t *
osqlcomm_startgen_rpl_type_get(osql_startgen_rpl_t *p_startgen_rpl,
const uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_STARTGEN_RPL_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_rpl_type_get(&(p_startgen_rpl->hd), p_buf, p_buf_end);
p_buf = osqlcomm_startgen_type_get(&(p_startgen_rpl->dt), p_buf, p_buf_end);
return p_buf;
}
typedef struct osql_startgen_uuid_rpl {
osql_uuid_rpl_t hd;
osql_startgen_t dt;
} osql_startgen_uuid_rpl_t;
enum {
OSQLCOMM_STARTGEN_UUID_RPL_LEN =
OSQLCOMM_UUID_RPL_TYPE_LEN + OSQLCOMM_STARTGEN_TYPE_LEN
};
BB_COMPILE_TIME_ASSERT(osqlcomm_startgen_uuid_type_len,
sizeof(osql_startgen_uuid_rpl_t) ==
OSQLCOMM_STARTGEN_UUID_RPL_LEN);
static uint8_t *osqlcomm_startgen_uuid_rpl_type_put(
const osql_startgen_uuid_rpl_t *p_startgen_rpl, uint8_t *p_buf,
uint8_t *p_buf_end)
{
if (p_buf_end < p_buf ||
OSQLCOMM_STARTGEN_UUID_RPL_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_uuid_rpl_type_put(&(p_startgen_rpl->hd), p_buf, p_buf_end);
p_buf = osqlcomm_startgen_type_put(&(p_startgen_rpl->dt), p_buf, p_buf_end);
return p_buf;
}
static const uint8_t *
osqlcomm_startgen_uuid_rpl_type_get(osql_startgen_uuid_rpl_t *p_startgen_rpl,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf ||
OSQLCOMM_STARTGEN_UUID_RPL_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_uuid_rpl_type_get(&(p_startgen_rpl->hd), p_buf, p_buf_end);
p_buf = osqlcomm_startgen_type_get(&(p_startgen_rpl->dt), p_buf, p_buf_end);
return p_buf;
}
/********* OSQL BPLOG FUNC *****************/
typedef struct osql_bpfunc {
int32_t data_len;
uint8_t data[];
} osql_bpfunc_t;
enum { OSQLCOMM_BPFUNC_TYPE_LEN = 4 };
BB_COMPILE_TIME_ASSERT(osqlcomm_bpfunc_type_len,
sizeof(osql_bpfunc_t) == OSQLCOMM_BPFUNC_TYPE_LEN);
static uint8_t *osqlcomm_bpfunc_type_put(const osql_bpfunc_t *p_osql_bpfunc,
uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf ||
OSQLCOMM_BPFUNC_TYPE_LEN + p_osql_bpfunc->data_len >
(p_buf_end - p_buf))
return NULL;
p_buf = buf_put(&p_osql_bpfunc->data_len, sizeof(p_osql_bpfunc->data_len),
p_buf, p_buf_end);
p_buf = buf_no_net_put(&p_osql_bpfunc->data, p_osql_bpfunc->data_len, p_buf,
p_buf_end);
return p_buf;
}
static const uint8_t *osqlcomm_bpfunc_type_get(osql_bpfunc_t **p_osql_bpfunc,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_BPFUNC_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
int32_t data_len = 0;
p_buf = buf_get(&data_len, sizeof(data_len), p_buf, p_buf_end);
*p_osql_bpfunc = malloc(sizeof(osql_bpfunc_t) + data_len);
if (!*p_osql_bpfunc)
return p_buf;
(*p_osql_bpfunc)->data_len = data_len;
if (data_len > 0) {
p_buf = buf_no_net_get(&((*p_osql_bpfunc)->data), data_len, p_buf,
p_buf_end);
}
return p_buf;
}
static uint8_t *osqlcomm_bpfunc_rpl_type_put(osql_rpl_t *hd, osql_bpfunc_t *dt,
uint8_t *p_buf, uint8_t *p_buf_end)
{
if (p_buf_end < p_buf ||
OSQLCOMM_RPL_TYPE_LEN + OSQLCOMM_BPFUNC_TYPE_LEN + dt->data_len >
(p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_rpl_type_put(hd, p_buf, p_buf_end);
p_buf = osqlcomm_bpfunc_type_put(dt, p_buf, p_buf_end);
return p_buf;
}
static uint8_t *osqlcomm_bpfunc_uuid_rpl_type_put(osql_uuid_rpl_t *hd,
osql_bpfunc_t *dt,
uint8_t *p_buf,
uint8_t *p_buf_end)
{
if (p_buf_end < p_buf ||
OSQLCOMM_RPL_TYPE_LEN + OSQLCOMM_BPFUNC_TYPE_LEN + dt->data_len >
(p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_uuid_rpl_type_put(hd, p_buf, p_buf_end);
p_buf = osqlcomm_bpfunc_type_put(dt, p_buf, p_buf_end);
return p_buf;
}
/********* OSQL_SCHEMACHANGE *****************/
static uint8_t *osqlcomm_schemachange_type_get(struct schema_change_type *sc,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
uint8_t *tmp_buf =
buf_get_schemachange(sc, (void *)p_buf, (void *)p_buf_end);
if (sc->tablename_len == -1 || sc->fname_len == -1 || sc->aname_len == -1)
return NULL;
return tmp_buf;
}
extern int gbl_sc_protobuf;
static uint8_t *osqlcomm_packed_schemachange_rpl_type_put(osql_rpl_t *hd, void *packed_sc, size_t sc_len,
uint8_t *p_buf, uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_RPL_TYPE_LEN + sc_len > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_rpl_type_put(hd, p_buf, p_buf_end);
p_buf = buf_no_net_put(packed_sc, sc_len, p_buf, p_buf_end);
return p_buf;
}
static uint8_t *osqlcomm_schemachange_rpl_type_put(osql_rpl_t *hd, struct schema_change_type *sc, uint8_t *p_buf,
uint8_t *p_buf_end)
{
size_t sc_len = schemachange_packed_size(sc);
if (p_buf_end < p_buf ||
OSQLCOMM_RPL_TYPE_LEN + sc_len > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_rpl_type_put(hd, p_buf, p_buf_end);
p_buf = buf_put_schemachange(sc, p_buf, p_buf_end);
return p_buf;
}
static uint8_t *osqlcomm_packed_schemachange_uuid_rpl_type_put(osql_uuid_rpl_t *hd, void *packed_sc, size_t sc_len,
uint8_t *p_buf, uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_UUID_RPL_TYPE_LEN + sc_len > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_uuid_rpl_type_put(hd, p_buf, p_buf_end);
p_buf = buf_no_net_put(packed_sc, sc_len, p_buf, p_buf_end);
return p_buf;
}
static uint8_t *osqlcomm_schemachange_uuid_rpl_type_put(osql_uuid_rpl_t *hd, struct schema_change_type *sc,
uint8_t *p_buf, uint8_t *p_buf_end)
{
size_t sc_len = schemachange_packed_size(sc);
if (p_buf_end < p_buf || OSQLCOMM_UUID_RPL_TYPE_LEN + sc_len > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_uuid_rpl_type_put(hd, p_buf, p_buf_end);
p_buf = buf_put_schemachange(sc, p_buf, p_buf_end);
return p_buf;
}
/***************************************************************************/
typedef struct osql_serial {
// ranges info
int buf_size;
int arr_size;
unsigned int file;
unsigned int offset;
} osql_serial_t;
typedef struct osql_del_uuid_rpl {
osql_uuid_rpl_t hd;
osql_del_t dt;
} osql_del_uuid_rpl_t;
enum {
OSQLCOMM_OSQL_DEL_UUID_RPL_TYPE_LEN =
OSQLCOMM_UUID_RPL_TYPE_LEN + OSQLCOMM_DEL_TYPE_LEN
};
BB_COMPILE_TIME_ASSERT(osqlcomm_del_uuid_rpl_type_len,
sizeof(osql_del_uuid_rpl_t) ==
OSQLCOMM_OSQL_DEL_UUID_RPL_TYPE_LEN);
static uint8_t *osqlcomm_del_uuid_rpl_type_put(osql_del_uuid_rpl_t *p_del_rpl,
uint8_t *p_buf,
uint8_t *p_buf_end, int send_dk)
{
if (p_buf_end < p_buf ||
(send_dk ? OSQLCOMM_OSQL_DEL_UUID_RPL_TYPE_LEN
: OSQLCOMM_OSQL_DEL_UUID_RPL_TYPE_LEN -
sizeof(unsigned long long)) > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_uuid_rpl_type_put(&(p_del_rpl->hd), p_buf, p_buf_end);
p_buf = osqlcomm_del_type_put(&(p_del_rpl->dt), p_buf, p_buf_end, send_dk);
return p_buf;
}
enum { OSQLCOMM_SERIAL_TYPE_LEN = 4 + 4 + 4 + 4 };
BB_COMPILE_TIME_ASSERT(osqlcomm_serial_type_len,
sizeof(osql_serial_t) == OSQLCOMM_SERIAL_TYPE_LEN);
static uint8_t *osqlcomm_serial_type_put(const osql_serial_t *p_osql_serial,
uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_SERIAL_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_put(&(p_osql_serial->buf_size), sizeof(p_osql_serial->buf_size),
p_buf, p_buf_end);
p_buf = buf_put(&(p_osql_serial->arr_size), sizeof(p_osql_serial->arr_size),
p_buf, p_buf_end);
p_buf = buf_put(&(p_osql_serial->file), sizeof(p_osql_serial->file), p_buf,
p_buf_end);
p_buf = buf_put(&(p_osql_serial->offset), sizeof(p_osql_serial->offset),
p_buf, p_buf_end);
return p_buf;
}
static const uint8_t *osqlcomm_serial_type_get(osql_serial_t *p_osql_serial,
const uint8_t *p_buf,
const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_SERIAL_TYPE_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = buf_get(&(p_osql_serial->buf_size), sizeof(p_osql_serial->buf_size),
p_buf, p_buf_end);
p_buf = buf_get(&(p_osql_serial->arr_size), sizeof(p_osql_serial->arr_size),
p_buf, p_buf_end);
p_buf = buf_get(&(p_osql_serial->file), sizeof(p_osql_serial->file), p_buf,
p_buf_end);
p_buf = buf_get(&(p_osql_serial->offset), sizeof(p_osql_serial->offset),
p_buf, p_buf_end);
return p_buf;
}
typedef struct osql_serial_rpl {
osql_rpl_t hd;
osql_serial_t dt;
} osql_serial_rpl_t;
enum {
OSQLCOMM_SERIAL_RPL_LEN = OSQLCOMM_RPL_TYPE_LEN + OSQLCOMM_SERIAL_TYPE_LEN
};
typedef struct osql_serial_uuid_rpl {
osql_uuid_rpl_t hd;
osql_serial_t dt;
} osql_serial_uuid_rpl_t;
enum {
OSQLCOMM_SERIAL_UUID_RPL_LEN =
OSQLCOMM_UUID_RPL_TYPE_LEN + OSQLCOMM_SERIAL_TYPE_LEN
};
BB_COMPILE_TIME_ASSERT(osqlcomm_serial_uuid_rpl_len,
sizeof(osql_serial_uuid_rpl_t) ==
OSQLCOMM_SERIAL_UUID_RPL_LEN);
static uint8_t *
osqlcomm_serial_rpl_put(const osql_serial_rpl_t *p_osql_serial_rpl,
uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_SERIAL_RPL_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_rpl_type_put(&(p_osql_serial_rpl->hd), p_buf, p_buf_end);
p_buf =
osqlcomm_serial_type_put(&(p_osql_serial_rpl->dt), p_buf, p_buf_end);
return p_buf;
}
static const uint8_t *
osqlcomm_serial_rpl_get(osql_serial_rpl_t *p_osql_serial_rpl,
const uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_SERIAL_RPL_LEN > (p_buf_end - p_buf))
return NULL;
p_buf = osqlcomm_rpl_type_get(&(p_osql_serial_rpl->hd), p_buf, p_buf_end);
p_buf =
osqlcomm_serial_type_get(&(p_osql_serial_rpl->dt), p_buf, p_buf_end);
return p_buf;
}
static uint8_t *
osqlcomm_serial_uuid_rpl_put(const osql_serial_uuid_rpl_t *p_osql_serial_rpl,
uint8_t *p_buf, const uint8_t *p_buf_end)
{
if (p_buf_end < p_buf || OSQLCOMM_SERIAL_UUID_RPL_LEN > (p_buf_end - p_buf))