|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#pragma once |
| 21 | + |
| 22 | +#include <memory> |
| 23 | +#include <string> |
| 24 | +#include <unordered_map> |
| 25 | + |
| 26 | +#include "iceberg/constants.h" |
| 27 | +#include "iceberg/iceberg_export.h" |
| 28 | +#include "iceberg/metrics/metrics_context.h" |
| 29 | +#include "iceberg/metrics/metrics_types.h" // CounterResult, TimerResult, DurationNs |
| 30 | +#include "iceberg/metrics/timer.h" |
| 31 | + |
| 32 | +namespace iceberg { |
| 33 | + |
| 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 CommitMetrics Of(MetricsContext& context); |
| 46 | + |
| 47 | + /// \brief Create a CommitMetrics instance with all-noop timer and counter. |
| 48 | + static 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 | + |
| 63 | +/// \brief Immutable snapshot of commit metrics for use in CommitReport. |
| 64 | +struct ICEBERG_EXPORT CommitMetricsResult { |
| 65 | + /// \brief Total wall-clock duration of the commit attempt. |
| 66 | + TimerResult total_duration; |
| 67 | + /// \brief Number of commit attempts (1 on success without retries). |
| 68 | + CounterResult attempts; |
| 69 | + /// \brief Number of data files added in this commit. |
| 70 | + CounterResult added_data_files; |
| 71 | + /// \brief Number of data files removed in this commit. |
| 72 | + CounterResult removed_data_files; |
| 73 | + /// \brief Total live data files after this commit. |
| 74 | + CounterResult total_data_files; |
| 75 | + /// \brief Number of delete files added in this commit. |
| 76 | + CounterResult added_delete_files; |
| 77 | + /// \brief Equality delete files added. |
| 78 | + CounterResult added_equality_delete_files; |
| 79 | + /// \brief Positional delete files added. |
| 80 | + CounterResult added_positional_delete_files; |
| 81 | + /// \brief Deletion vectors added. |
| 82 | + CounterResult added_dvs; |
| 83 | + /// \brief Positional delete files removed. |
| 84 | + CounterResult removed_positional_delete_files; |
| 85 | + /// \brief Deletion vectors removed. |
| 86 | + CounterResult removed_dvs; |
| 87 | + /// \brief Equality delete files removed. |
| 88 | + CounterResult removed_equality_delete_files; |
| 89 | + /// \brief Number of delete files removed in this commit. |
| 90 | + CounterResult removed_delete_files; |
| 91 | + /// \brief Total live delete files after this commit. |
| 92 | + CounterResult total_delete_files; |
| 93 | + /// \brief Number of records added in this commit. |
| 94 | + CounterResult added_records; |
| 95 | + /// \brief Number of records removed in this commit. |
| 96 | + CounterResult removed_records; |
| 97 | + /// \brief Total live records after this commit. |
| 98 | + CounterResult total_records; |
| 99 | + /// \brief Total byte size of files added. |
| 100 | + CounterResult added_files_size_bytes; |
| 101 | + /// \brief Total byte size of files removed. |
| 102 | + CounterResult removed_files_size_bytes; |
| 103 | + /// \brief Total byte size of all live files after this commit. |
| 104 | + CounterResult total_files_size_bytes; |
| 105 | + /// \brief Positional delete records added. |
| 106 | + CounterResult added_positional_deletes; |
| 107 | + /// \brief Positional delete records removed. |
| 108 | + CounterResult removed_positional_deletes; |
| 109 | + /// \brief Total positional delete records after this commit. |
| 110 | + CounterResult total_positional_deletes; |
| 111 | + /// \brief Equality delete records added. |
| 112 | + CounterResult added_equality_deletes; |
| 113 | + /// \brief Equality delete records removed. |
| 114 | + CounterResult removed_equality_deletes; |
| 115 | + /// \brief Total equality delete records after this commit. |
| 116 | + CounterResult total_equality_deletes; |
| 117 | + /// \brief Manifest files kept unchanged in this commit. |
| 118 | + CounterResult kept_manifest_count; |
| 119 | + /// \brief Manifest files created in this commit. |
| 120 | + CounterResult created_manifest_count; |
| 121 | + /// \brief Manifest files replaced in this commit. |
| 122 | + CounterResult replaced_manifest_count; |
| 123 | + /// \brief Manifest entries processed in this commit. |
| 124 | + CounterResult processed_manifest_entries_count; |
| 125 | + |
| 126 | + /// \brief Build a CommitMetricsResult from live metrics and a snapshot summary map. |
| 127 | + /// |
| 128 | + /// Combines timer/retry measurements from \p live_metrics with records parsed |
| 129 | + /// from \p snapshot_summary. Missing or unparseable summary keys |
| 130 | + /// default to 0. |
| 131 | + static CommitMetricsResult From( |
| 132 | + const CommitMetrics& live_metrics, |
| 133 | + const std::unordered_map<std::string, std::string>& snapshot_summary); |
| 134 | +}; |
| 135 | + |
| 136 | +/// \brief Report generated after a commit operation. |
| 137 | +/// |
| 138 | +/// Contains metrics about the changes made in a commit. |
| 139 | +struct ICEBERG_EXPORT CommitReport { |
| 140 | + /// \brief The fully qualified name of the table that was modified. |
| 141 | + std::string table_name; |
| 142 | + /// \brief The snapshot ID created by this commit. |
| 143 | + int64_t snapshot_id = kInvalidSnapshotId; |
| 144 | + /// \brief The sequence number assigned to this commit. |
| 145 | + int64_t sequence_number = kInvalidSequenceNumber; |
| 146 | + /// \brief The operation that was performed (write, delete, etc.). |
| 147 | + std::string operation; |
| 148 | + /// \brief Metrics collected during the commit operation. |
| 149 | + CommitMetricsResult commit_metrics; |
| 150 | + /// \brief Additional key-value metadata. |
| 151 | + std::unordered_map<std::string, std::string> metadata; |
| 152 | +}; |
| 153 | + |
| 154 | +} // namespace iceberg |
0 commit comments