|
20 | 20 | #pragma once |
21 | 21 |
|
22 | 22 | #include <memory> |
| 23 | +#include <optional> |
23 | 24 | #include <string> |
24 | 25 | #include <unordered_map> |
25 | 26 |
|
|
31 | 32 |
|
32 | 33 | namespace iceberg { |
33 | 34 |
|
34 | | -// Forward declaration: CommitMetricsResult is defined later in this header. |
35 | | -struct CommitMetricsResult; |
36 | | - |
37 | | -/// \brief Live commit metrics collected during a table commit operation. |
38 | | -/// |
39 | | -/// Tracks the overall commit duration and retry count. File/record counts come |
40 | | -/// from the snapshot summary after the commit succeeds and are stored separately |
41 | | -/// in CommitMetricsResult. |
42 | | -class ICEBERG_EXPORT CommitMetrics { |
43 | | - public: |
44 | | - /// \brief Create a CommitMetrics instance backed by the given MetricsContext. |
45 | | - static std::unique_ptr<CommitMetrics> Of(MetricsContext& context); |
46 | | - |
47 | | - /// \brief Create a CommitMetrics instance with all-noop timer and counter. |
48 | | - static std::unique_ptr<CommitMetrics> Noop(); |
49 | | - |
50 | | - /// \brief Snapshot timer and counter values into the corresponding fields of result. |
51 | | - /// |
52 | | - /// Only total_duration and attempts are written; the caller is responsible for |
53 | | - /// populating the remaining snapshot-summary fields. |
54 | | - void PopulateResult(CommitMetricsResult& result) const; |
55 | | - |
56 | | - /// \brief Timer measuring total wall-clock time of the commit call. |
57 | | - std::shared_ptr<Timer> total_duration; |
58 | | - |
59 | | - /// \brief Counter for the number of commit attempts (including retries). |
60 | | - std::shared_ptr<Counter> attempts; |
61 | | - |
62 | | - private: |
63 | | - CommitMetrics() = default; |
64 | | -}; |
| 35 | +// Forward declaration: CommitMetrics is defined later in this header. |
| 36 | +class CommitMetrics; |
65 | 37 |
|
66 | 38 | /// \brief Immutable snapshot of commit metrics for use in CommitReport. |
| 39 | +/// |
| 40 | +/// Populated by CommitMetrics::ToResult() after a commit completes. File and |
| 41 | +/// record counts can also be combined from the snapshot summary with From(). |
67 | 42 | struct ICEBERG_EXPORT CommitMetricsResult { |
68 | 43 | /// \brief Total wall-clock duration of the commit attempt. |
69 | | - TimerResult total_duration; |
| 44 | + std::optional<TimerResult> total_duration; |
70 | 45 | /// \brief Number of commit attempts (1 on success without retries). |
71 | | - CounterResult attempts; |
| 46 | + std::optional<CounterResult> attempts; |
72 | 47 | /// \brief Number of data files added in this commit. |
73 | | - CounterResult added_data_files; |
| 48 | + std::optional<CounterResult> added_data_files; |
74 | 49 | /// \brief Number of data files removed in this commit. |
75 | | - CounterResult removed_data_files; |
| 50 | + std::optional<CounterResult> removed_data_files; |
76 | 51 | /// \brief Total live data files after this commit. |
77 | | - CounterResult total_data_files; |
| 52 | + std::optional<CounterResult> total_data_files; |
78 | 53 | /// \brief Number of delete files added in this commit. |
79 | | - CounterResult added_delete_files; |
| 54 | + std::optional<CounterResult> added_delete_files; |
80 | 55 | /// \brief Equality delete files added. |
81 | | - CounterResult added_equality_delete_files; |
| 56 | + std::optional<CounterResult> added_equality_delete_files; |
82 | 57 | /// \brief Positional delete files added. |
83 | | - CounterResult added_positional_delete_files; |
| 58 | + std::optional<CounterResult> added_positional_delete_files; |
84 | 59 | /// \brief Deletion vectors added. |
85 | | - CounterResult added_dvs; |
| 60 | + std::optional<CounterResult> added_dvs; |
| 61 | + /// \brief Number of delete files removed in this commit. |
| 62 | + std::optional<CounterResult> removed_delete_files; |
86 | 63 | /// \brief Positional delete files removed. |
87 | | - CounterResult removed_positional_delete_files; |
| 64 | + std::optional<CounterResult> removed_positional_delete_files; |
88 | 65 | /// \brief Deletion vectors removed. |
89 | | - CounterResult removed_dvs; |
| 66 | + std::optional<CounterResult> removed_dvs; |
90 | 67 | /// \brief Equality delete files removed. |
91 | | - CounterResult removed_equality_delete_files; |
92 | | - /// \brief Number of delete files removed in this commit. |
93 | | - CounterResult removed_delete_files; |
| 68 | + std::optional<CounterResult> removed_equality_delete_files; |
94 | 69 | /// \brief Total live delete files after this commit. |
95 | | - CounterResult total_delete_files; |
| 70 | + std::optional<CounterResult> total_delete_files; |
96 | 71 | /// \brief Number of records added in this commit. |
97 | | - CounterResult added_records; |
| 72 | + std::optional<CounterResult> added_records; |
98 | 73 | /// \brief Number of records removed in this commit. |
99 | | - CounterResult removed_records; |
| 74 | + std::optional<CounterResult> removed_records; |
100 | 75 | /// \brief Total live records after this commit. |
101 | | - CounterResult total_records; |
| 76 | + std::optional<CounterResult> total_records; |
102 | 77 | /// \brief Total byte size of files added. |
103 | | - CounterResult added_files_size_bytes; |
| 78 | + std::optional<CounterResult> added_files_size_bytes; |
104 | 79 | /// \brief Total byte size of files removed. |
105 | | - CounterResult removed_files_size_bytes; |
| 80 | + std::optional<CounterResult> removed_files_size_bytes; |
106 | 81 | /// \brief Total byte size of all live files after this commit. |
107 | | - CounterResult total_files_size_bytes; |
| 82 | + std::optional<CounterResult> total_files_size_bytes; |
108 | 83 | /// \brief Positional delete records added. |
109 | | - CounterResult added_positional_deletes; |
| 84 | + std::optional<CounterResult> added_positional_deletes; |
110 | 85 | /// \brief Positional delete records removed. |
111 | | - CounterResult removed_positional_deletes; |
| 86 | + std::optional<CounterResult> removed_positional_deletes; |
112 | 87 | /// \brief Total positional delete records after this commit. |
113 | | - CounterResult total_positional_deletes; |
| 88 | + std::optional<CounterResult> total_positional_deletes; |
114 | 89 | /// \brief Equality delete records added. |
115 | | - CounterResult added_equality_deletes; |
| 90 | + std::optional<CounterResult> added_equality_deletes; |
116 | 91 | /// \brief Equality delete records removed. |
117 | | - CounterResult removed_equality_deletes; |
| 92 | + std::optional<CounterResult> removed_equality_deletes; |
118 | 93 | /// \brief Total equality delete records after this commit. |
119 | | - CounterResult total_equality_deletes; |
| 94 | + std::optional<CounterResult> total_equality_deletes; |
120 | 95 | /// \brief Manifest files kept unchanged in this commit. |
121 | | - CounterResult kept_manifest_count; |
| 96 | + std::optional<CounterResult> kept_manifest_count; |
122 | 97 | /// \brief Manifest files created in this commit. |
123 | | - CounterResult created_manifest_count; |
| 98 | + std::optional<CounterResult> created_manifest_count; |
124 | 99 | /// \brief Manifest files replaced in this commit. |
125 | | - CounterResult replaced_manifest_count; |
| 100 | + std::optional<CounterResult> replaced_manifest_count; |
126 | 101 | /// \brief Manifest entries processed in this commit. |
127 | | - CounterResult processed_manifest_entries_count; |
| 102 | + std::optional<CounterResult> processed_manifest_entries_count; |
128 | 103 |
|
129 | 104 | bool operator==(const CommitMetricsResult&) const = default; |
130 | 105 |
|
131 | 106 | /// \brief Build a CommitMetricsResult from live metrics and a snapshot summary map. |
132 | 107 | /// |
133 | 108 | /// Combines timer/retry measurements from \p live_metrics with records parsed |
134 | | - /// from \p snapshot_summary. Missing or unparseable summary keys default to 0. |
| 109 | + /// from \p snapshot_summary. Missing or unparseable summary keys are omitted. |
135 | 110 | static CommitMetricsResult From( |
136 | 111 | const CommitMetrics& live_metrics, |
137 | 112 | const std::unordered_map<std::string, std::string>& snapshot_summary); |
138 | 113 | }; |
139 | 114 |
|
| 115 | +/// \brief Live commit metrics collected during a table commit operation. |
| 116 | +/// |
| 117 | +/// Tracks the overall commit duration and retry count. File/record counts come |
| 118 | +/// from the snapshot summary after the commit succeeds and are stored separately |
| 119 | +/// in CommitMetricsResult. |
| 120 | +class ICEBERG_EXPORT CommitMetrics { |
| 121 | + public: |
| 122 | + /// \brief Create a CommitMetrics instance backed by the given MetricsContext. |
| 123 | + static std::unique_ptr<CommitMetrics> Make(MetricsContext& context); |
| 124 | + |
| 125 | + /// \brief Create a CommitMetrics instance with all-noop timer and counter. |
| 126 | + static std::unique_ptr<CommitMetrics> Noop(); |
| 127 | + |
| 128 | + /// \brief Snapshot current timer and counter values into a CommitMetricsResult. |
| 129 | + CommitMetricsResult ToResult() const; |
| 130 | + |
| 131 | + /// \brief Timer measuring total wall-clock time of the commit call. |
| 132 | + std::shared_ptr<Timer> total_duration; |
| 133 | + |
| 134 | + /// \brief Counter for the number of commit attempts (including retries). |
| 135 | + std::shared_ptr<Counter> attempts; |
| 136 | + |
| 137 | + private: |
| 138 | + CommitMetrics() = default; |
| 139 | +}; |
| 140 | + |
140 | 141 | /// \brief Report generated after a commit operation. |
141 | 142 | /// |
142 | 143 | /// Contains metrics about the changes made in a commit. |
|
0 commit comments