@@ -262,9 +262,15 @@ Status FileStoreCommitImpl::Overwrite(
262262 std::shared_ptr<ManifestCommittable> committable =
263263 CreateManifestCommittable (identifier, commit_messages, watermark);
264264 std::vector<ManifestEntry> append_table_files;
265+ std::vector<ManifestEntry> append_changelog_files;
266+ std::vector<ManifestEntry> compact_table_files;
267+ std::vector<ManifestEntry> compact_changelog_files;
265268 std::vector<IndexManifestEntry> append_table_index_files;
269+ std::vector<IndexManifestEntry> compact_table_index_files;
266270 PAIMON_RETURN_NOT_OK (CollectChanges (committable->FileCommittables (), &append_table_files,
267- &append_table_index_files));
271+ &append_changelog_files, &compact_table_files,
272+ &compact_changelog_files, &append_table_index_files,
273+ &compact_table_index_files));
268274 if (!append_table_index_files.empty ()) {
269275 return Status::NotImplemented (" Overwrite not support index for now" );
270276 }
@@ -283,9 +289,15 @@ Result<int32_t> FileStoreCommitImpl::FilterAndOverwrite(
283289 FilterCommitted (committables));
284290 if (!actual_committables.empty ()) {
285291 std::vector<ManifestEntry> append_table_files;
292+ std::vector<ManifestEntry> append_changelog_files;
293+ std::vector<ManifestEntry> compact_table_files;
294+ std::vector<ManifestEntry> compact_changelog_files;
286295 std::vector<IndexManifestEntry> append_table_index_files;
296+ std::vector<IndexManifestEntry> compact_table_index_files;
287297 PAIMON_RETURN_NOT_OK (CollectChanges (actual_committables[0 ]->FileCommittables (),
288- &append_table_files, &append_table_index_files));
298+ &append_table_files, &append_changelog_files,
299+ &compact_table_files, &compact_changelog_files,
300+ &append_table_index_files, &compact_table_index_files));
289301 if (!append_table_index_files.empty ()) {
290302 return Status::NotImplemented (" FilterAndOverwrite not support index for now" );
291303 }
@@ -355,20 +367,72 @@ Status FileStoreCommitImpl::TryOverwrite(
355367Status FileStoreCommitImpl::Commit (const std::shared_ptr<ManifestCommittable>& committable,
356368 bool check_append_files) {
357369 std::vector<ManifestEntry> append_table_files;
370+ std::vector<ManifestEntry> append_changelog_files;
371+ std::vector<ManifestEntry> compact_table_files;
372+ std::vector<ManifestEntry> compact_changelog_files;
358373 std::vector<IndexManifestEntry> append_table_index_files;
374+ std::vector<IndexManifestEntry> compact_table_index_files;
359375 PAIMON_RETURN_NOT_OK (CollectChanges (committable->FileCommittables (), &append_table_files,
360- &append_table_index_files));
376+ &append_changelog_files, &compact_table_files,
377+ &compact_changelog_files, &append_table_index_files,
378+ &compact_table_index_files));
361379
362380 int32_t attempt = 0 ;
381+ int32_t generated_snapshot = 0 ;
382+ const auto started = std::chrono::high_resolution_clock::now ();
363383 if (!ignore_empty_commit_ || !append_table_files.empty () || !append_table_index_files.empty ()) {
364384 PAIMON_ASSIGN_OR_RAISE (int32_t cnt,
365385 TryCommit (append_table_files, append_table_index_files,
366386 committable->Identifier (), committable->Watermark (),
367387 committable->LogOffsets (), committable->Properties (),
368388 Snapshot::CommitKind::Append (), check_append_files));
369389 attempt += cnt;
390+ ++generated_snapshot;
391+ }
392+ auto table_files_added = static_cast <int32_t >(append_table_files.size ());
393+ int32_t table_files_deleted = 0 ;
394+ int64_t compaction_input_file_size = 0 ;
395+ int64_t compaction_output_file_size = 0 ;
396+ for (const auto & entry : compact_table_files) {
397+ const auto & kind = entry.Kind ();
398+ if (kind == FileKind::Add ()) {
399+ ++table_files_added;
400+ compaction_output_file_size += entry.File ()->file_size ;
401+ } else if (kind == FileKind::Delete ()) {
402+ ++table_files_deleted;
403+ compaction_input_file_size += entry.File ()->file_size ;
404+ }
370405 }
406+ metrics_->SetCounter (CommitMetrics::LAST_COMMIT_DURATION ,
407+ std::chrono::duration_cast<std::chrono::nanoseconds>(
408+ std::chrono::high_resolution_clock::now () - started)
409+ .count ());
371410 metrics_->SetCounter (CommitMetrics::LAST_COMMIT_ATTEMPTS , attempt);
411+ metrics_->SetCounter (CommitMetrics::LAST_TABLE_FILES_ADDED , table_files_added);
412+ metrics_->SetCounter (CommitMetrics::LAST_TABLE_FILES_DELETED , table_files_deleted);
413+ metrics_->SetCounter (CommitMetrics::LAST_TABLE_FILES_APPENDED , append_table_files.size ());
414+ metrics_->SetCounter (CommitMetrics::LAST_TABLE_FILES_COMMIT_COMPACTED ,
415+ compact_table_files.size ());
416+ metrics_->SetCounter (CommitMetrics::LAST_CHANGELOG_FILES_APPENDED ,
417+ append_changelog_files.size ());
418+ metrics_->SetCounter (CommitMetrics::LAST_CHANGELOG_FILES_COMMIT_COMPACTED ,
419+ compact_changelog_files.size ());
420+ metrics_->SetCounter (CommitMetrics::LAST_GENERATED_SNAPSHOTS , generated_snapshot);
421+ metrics_->SetCounter (CommitMetrics::LAST_DELTA_RECORDS_APPENDED , RowCounts (append_table_files));
422+ metrics_->SetCounter (CommitMetrics::LAST_CHANGELOG_RECORDS_APPENDED ,
423+ RowCounts (append_changelog_files));
424+ metrics_->SetCounter (CommitMetrics::LAST_DELTA_RECORDS_COMMIT_COMPACTED ,
425+ RowCounts (compact_table_files));
426+ metrics_->SetCounter (CommitMetrics::LAST_CHANGELOG_RECORDS_COMMIT_COMPACTED ,
427+ RowCounts (compact_changelog_files));
428+ metrics_->SetCounter (CommitMetrics::LAST_PARTITIONS_WRITTEN ,
429+ NumChangedPartitions ({append_table_files, compact_changelog_files}));
430+ metrics_->SetCounter (CommitMetrics::LAST_BUCKETS_WRITTEN ,
431+ NumChangedBuckets ({append_table_files, compact_changelog_files}));
432+ metrics_->SetCounter (CommitMetrics::LAST_COMPACTION_INPUT_FILE_SIZE ,
433+ compaction_input_file_size);
434+ metrics_->SetCounter (CommitMetrics::LAST_COMPACTION_OUTPUT_FILE_SIZE ,
435+ compaction_output_file_size);
372436 return Status::OK ();
373437}
374438
@@ -784,7 +848,11 @@ std::shared_ptr<ManifestCommittable> FileStoreCommitImpl::CreateManifestCommitta
784848Status FileStoreCommitImpl::CollectChanges (
785849 const std::vector<std::shared_ptr<CommitMessage>>& commit_messages,
786850 std::vector<ManifestEntry>* append_table_files,
787- std::vector<IndexManifestEntry>* append_table_index_files) {
851+ std::vector<ManifestEntry>* append_changelog_files,
852+ std::vector<ManifestEntry>* compact_table_files,
853+ std::vector<ManifestEntry>* compact_changelog_files,
854+ std::vector<IndexManifestEntry>* append_table_index_files,
855+ std::vector<IndexManifestEntry>* compact_table_index_files) {
788856 for (const auto & message : commit_messages) {
789857 auto commit_message = std::dynamic_pointer_cast<CommitMessageImpl>(message);
790858 if (commit_message) {
@@ -797,6 +865,11 @@ Status FileStoreCommitImpl::CollectChanges(
797865 append_table_files->push_back (
798866 MakeEntry (FileKind::Delete (), commit_message, deleted_file));
799867 }
868+ for (const std::shared_ptr<DataFileMeta>& changelog_file :
869+ new_files_increment.ChangelogFiles ()) {
870+ append_changelog_files->push_back (
871+ MakeEntry (FileKind::Add (), commit_message, changelog_file));
872+ }
800873 for (const std::shared_ptr<IndexFileMeta>& deleted_index_file :
801874 new_files_increment.DeletedIndexFiles ()) {
802875 append_table_index_files->emplace_back (
@@ -808,6 +881,34 @@ Status FileStoreCommitImpl::CollectChanges(
808881 append_table_index_files->emplace_back (FileKind::Add (), commit_message->Partition (),
809882 commit_message->Bucket (), new_index_file);
810883 }
884+ CompactIncrement compact_increment = commit_message->GetCompactIncrement ();
885+ for (const std::shared_ptr<DataFileMeta>& compact_before :
886+ compact_increment.CompactBefore ()) {
887+ compact_table_files->push_back (
888+ MakeEntry (FileKind::Delete (), commit_message, compact_before));
889+ }
890+ for (const std::shared_ptr<DataFileMeta>& compact_after :
891+ compact_increment.CompactAfter ()) {
892+ compact_table_files->push_back (
893+ MakeEntry (FileKind::Add (), commit_message, compact_after));
894+ }
895+ for (const std::shared_ptr<DataFileMeta>& changelog_file :
896+ compact_increment.ChangelogFiles ()) {
897+ compact_changelog_files->push_back (
898+ MakeEntry (FileKind::Add (), commit_message, changelog_file));
899+ }
900+ for (const std::shared_ptr<IndexFileMeta>& deleted_index_file :
901+ compact_increment.DeletedIndexFiles ()) {
902+ compact_table_index_files->emplace_back (
903+ FileKind::Delete (), commit_message->Partition (), commit_message->Bucket (),
904+ deleted_index_file);
905+ }
906+ for (const std::shared_ptr<IndexFileMeta>& new_index_file :
907+ compact_increment.NewIndexFiles ()) {
908+ compact_table_index_files->emplace_back (FileKind::Add (),
909+ commit_message->Partition (),
910+ commit_message->Bucket (), new_index_file);
911+ }
811912 } else {
812913 return Status::Invalid (" fail to cast commit message to commit message impl" );
813914 }
@@ -825,4 +926,37 @@ ManifestEntry FileStoreCommitImpl::MakeEntry(
825926 file);
826927}
827928
929+ int64_t FileStoreCommitImpl::RowCounts (const std::vector<ManifestEntry>& files) {
930+ return std::accumulate (files.begin (), files.end (), 0L ,
931+ [](int64_t row_count, const ManifestEntry& entry) {
932+ return row_count + entry.File ()->row_count ;
933+ });
934+ }
935+
936+ int64_t FileStoreCommitImpl::NumChangedPartitions (
937+ const std::vector<std::vector<ManifestEntry>>& changes) {
938+ std::unordered_set<BinaryRow> changed_partitions;
939+ for (const auto & change : changes) {
940+ for (const auto & entry : change) {
941+ changed_partitions.insert (entry.Partition ());
942+ }
943+ }
944+ return static_cast <int64_t >(changed_partitions.size ());
945+ }
946+
947+ int64_t FileStoreCommitImpl::NumChangedBuckets (
948+ const std::vector<std::vector<ManifestEntry>>& changes) {
949+ std::unordered_map<BinaryRow, std::unordered_set<int >> changed_partition_buckets;
950+ for (const auto & change : changes) {
951+ for (const auto & entry : change) {
952+ changed_partition_buckets[entry.Partition ()].insert (entry.Bucket ());
953+ }
954+ }
955+ return std::accumulate (changed_partition_buckets.begin (), changed_partition_buckets.end (),
956+ int64_t {0 }, [](int64_t num_changed_buckets, const auto & bucket) {
957+ return num_changed_buckets +
958+ static_cast <int64_t >(bucket.second .size ());
959+ });
960+ }
961+
828962} // namespace paimon
0 commit comments