Commit b868d8c
authored
Use State to track the order of MongoDB transactions (#1742)
Summary: This PR adds functionality to track the order of transactions
as they are parsed. It adds the streamID of each request to the state
vector at parsing time which will then be used to iterate over at
stitching time. Adding this will mainly help the stitching process when
trying to stitch a request with N `moreToCome` responses.
**Motivation behind this change:**
The stitching implementation relies on the new interface using
`absl::flat_hash_map` to store the `streamID` and a deque of
request/response frames. We then use a response led matching algorithm
where we loop through the response map and stitch the first response
frame in a deque with its corresponding request frame. A response pairs
with a request when both frames share the same `streamID`, the response
frame's `streamID` is its `responseTo` and the request frame's
`streamID` is its `requestID`.
MongoDB's `OP_MSG` wire protocol has the concept of `more_to_come` which
means that the server could send `N` responses back to a singular
request by the client. Each frame in the series of the `N` responses are
linked by the `responseTo` of the frame matching the `requestID` of the
previous response frame, similar to a singly linked list. The head
response frame's `responseTo` will be the `requestID` of the request
frame. Note: the `requestID` of each frame in the `N more_to_come`
frames is random and unique.
At the time of stitching, if we do not use state to track the order of
transactions we would iterate over the response map in a "random" order
and could iterate over the `more_to_come` response frames out of order.
We could lose context on how the `more_to_come` frames are linked due to
not knowing the head response frame and if we were to iterate over the
end of the `more_to_come` message before looping through all prior
`more_to_come` frames in the message they would be dropped since we do
not know which request those frames are responding to. To solve this
issue, tracking the order of transactions' `streamIDs` to iterate over
would ensure that could use the response led stitching approach and find
the complete `more_to_come` message for a given request.
**New test case:**
The new test case checks to make sure the state's `stream_order` vector
is correctly populated with the order of `streamIDs` as we parse new
request frames (transactions). The test case parses 3 frames and expects
that the state's `stream_order` after parsing the first frame to contain
`std::pair<917, false>` since the first frame's `requestID` is 917. It
expects the `stream_order` to contain `std::pair<917, false>`,
`std::pair<444, false>` after parsing the second request frame since
that frame's requestID is 444 and so on.
Related issues: #640
Type of change: /kind feature
Test Plan: Modified the existing tests and added another test to make
sure the vector is populated correctly.
---------
Signed-off-by: Kartik Pattaswamy <kpattaswamy@pixielabs.ai>1 parent 1cd1ac5 commit b868d8c
File tree
4 files changed
+117
-23
lines changed- src/stirling/source_connectors/socket_tracer/protocols/mongodb
4 files changed
+117
-23
lines changedLines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
| |||
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
83 | | - | |
84 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
85 | 91 | | |
86 | 92 | | |
87 | 93 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
Lines changed: 83 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
351 | 353 | | |
352 | 354 | | |
353 | 355 | | |
354 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
355 | 359 | | |
356 | 360 | | |
357 | 361 | | |
| |||
360 | 364 | | |
361 | 365 | | |
362 | 366 | | |
363 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
364 | 370 | | |
365 | 371 | | |
366 | 372 | | |
| |||
369 | 375 | | |
370 | 376 | | |
371 | 377 | | |
372 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
373 | 381 | | |
374 | 382 | | |
375 | 383 | | |
| |||
378 | 386 | | |
379 | 387 | | |
380 | 388 | | |
381 | | - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
382 | 392 | | |
383 | 393 | | |
384 | 394 | | |
| |||
387 | 397 | | |
388 | 398 | | |
389 | 399 | | |
390 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
391 | 403 | | |
392 | 404 | | |
393 | 405 | | |
| |||
396 | 408 | | |
397 | 409 | | |
398 | 410 | | |
399 | | - | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
400 | 414 | | |
401 | 415 | | |
402 | 416 | | |
| |||
408 | 422 | | |
409 | 423 | | |
410 | 424 | | |
411 | | - | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
412 | 428 | | |
413 | 429 | | |
414 | 430 | | |
| |||
418 | 434 | | |
419 | 435 | | |
420 | 436 | | |
421 | | - | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
422 | 440 | | |
423 | 441 | | |
424 | 442 | | |
| |||
428 | 446 | | |
429 | 447 | | |
430 | 448 | | |
431 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
432 | 452 | | |
433 | 453 | | |
434 | 454 | | |
| |||
437 | 457 | | |
438 | 458 | | |
439 | 459 | | |
440 | | - | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
441 | 463 | | |
442 | 464 | | |
443 | 465 | | |
| |||
452 | 474 | | |
453 | 475 | | |
454 | 476 | | |
455 | | - | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
456 | 480 | | |
457 | 481 | | |
458 | 482 | | |
| |||
468 | 492 | | |
469 | 493 | | |
470 | 494 | | |
471 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
472 | 498 | | |
473 | 499 | | |
474 | 500 | | |
| |||
485 | 511 | | |
486 | 512 | | |
487 | 513 | | |
488 | | - | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
489 | 517 | | |
490 | 518 | | |
491 | 519 | | |
| |||
504 | 532 | | |
505 | 533 | | |
506 | 534 | | |
507 | | - | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
508 | 538 | | |
509 | 539 | | |
510 | 540 | | |
| |||
521 | 551 | | |
522 | 552 | | |
523 | 553 | | |
524 | | - | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
525 | 558 | | |
526 | 559 | | |
527 | 560 | | |
| |||
532 | 565 | | |
533 | 566 | | |
534 | 567 | | |
535 | | - | |
| 568 | + | |
536 | 569 | | |
537 | 570 | | |
538 | 571 | | |
539 | | - | |
| 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 | + | |
540 | 606 | | |
541 | 607 | | |
542 | 608 | | |
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
156 | 176 | | |
157 | 177 | | |
158 | 178 | | |
159 | | - | |
| 179 | + | |
| 180 | + | |
160 | 181 | | |
161 | 182 | | |
162 | 183 | | |
| |||
0 commit comments