* Given an activity on a worker node via SingleWorkerActivity, * writes the activity to the target pgbson_writer. The activity * is written in a format compatible with the currentOp command output. */
| 723 | * is written in a format compatible with the currentOp command output. |
| 724 | */ |
| 725 | static void |
| 726 | WriteOneActivityToDocument(SingleWorkerActivity *workerActivity, |
| 727 | pgbson_writer *singleActivityWriter) |
| 728 | { |
| 729 | DetectMongoCollection(workerActivity); |
| 730 | |
| 731 | char *shardId = psprintf("shard_%d", workerActivity->shardId); |
| 732 | PgbsonWriterAppendUtf8(singleActivityWriter, "shard", 5, shardId); |
| 733 | bool isActive = false; |
| 734 | const char *type = "unknown"; |
| 735 | if (strcmp(workerActivity->state, "active") == 0) |
| 736 | { |
| 737 | isActive = true; |
| 738 | type = "op"; |
| 739 | } |
| 740 | else if (strcmp(workerActivity->state, "idle") == 0) |
| 741 | { |
| 742 | type = "idleSession"; |
| 743 | } |
| 744 | else if (strcmp(workerActivity->state, "idle in transaction") == 0) |
| 745 | { |
| 746 | /* We mark these differently to provide info to the user */ |
| 747 | type = "idleSessionInTransaction"; |
| 748 | } |
| 749 | else if (strcmp(workerActivity->state, "idle in transaction (aborted)") == 0) |
| 750 | { |
| 751 | /* We mark these differently to provide info to the user */ |
| 752 | type = "idleSessionInTransaction"; |
| 753 | } |
| 754 | |
| 755 | PgbsonWriterAppendBool(singleActivityWriter, "active", 6, isActive); |
| 756 | PgbsonWriterAppendUtf8(singleActivityWriter, "type", 4, type); |
| 757 | |
| 758 | PgbsonWriterAppendUtf8(singleActivityWriter, "opid", 4, workerActivity->operationId); |
| 759 | |
| 760 | /* report the globalPid so that we can track locks back to this process */ |
| 761 | PgbsonWriterAppendInt64(singleActivityWriter, "op_prefix", 9, |
| 762 | workerActivity->globalPid); |
| 763 | |
| 764 | |
| 765 | if (workerActivity->backendType != NULL && |
| 766 | strcmp(workerActivity->backendType, "parallel worker") == 0) |
| 767 | { |
| 768 | PgbsonWriterAppendBool(singleActivityWriter, "parallelWorker", 14, true); |
| 769 | } |
| 770 | |
| 771 | if (workerActivity->leaderPid != 0) |
| 772 | { |
| 773 | PgbsonWriterAppendInt64(singleActivityWriter, "leaderOpPattern", 14, |
| 774 | workerActivity->leaderPid); |
| 775 | } |
| 776 | |
| 777 | if (isActive) |
| 778 | { |
| 779 | /* ns is only valid for an active query. */ |
| 780 | int databaseNameLength = strlen(workerActivity->processedMongoDatabase); |
| 781 | if (databaseNameLength > 0) |
| 782 | { |
no test coverage detected