### 6597: Add blob files to VersionStorageInfo/VersionBuilder - https://github.com/facebook/rocksdb/pull/6597 - `SharedBlobFileMetaData`:包含了 blob file 不可变的信息,如 - blob file number - blob file 内的 blob 个数 和 总大小 - `BlobFileMetaData`:可能会变,比如文件内的垃圾数量 - owned by `Version` - 扩展 `VersionStorageInfo`:添加 blob file metadata - 扩展 `VersionBuilder`:可以 apply blob file 相关的 `VersionEdit`,例如 - `BlobFileAddition` - `BlobFileGarbage`:表示对应的 blob file 新增了多少垃圾 - 一致性检查: - Version 中引用的 blob file 里面的内容不能全部都是垃圾 ### 6755: Keep track of obsolete blob files in VersionSet - https://github.com/facebook/rocksdb/pull/6755 - 当 `SharedBlobFileMetaData` 的引用计数变为 0 时,blob file 就变为 obsolete。 - 即最后一个引用 blob file 的 `Version` destroy 后 - Obsolete blob files 可以通过 `VersionSet::GetObsoleteFiles` 返回,并且存储在 `JobContext` 中 ### 6835: Refactor the blob file related logic in VersionBuilder - https://github.com/facebook/rocksdb/pull/6835 ### 6945: Maintain the set of linked SSTs in BlobFileMetaData - https://github.com/facebook/rocksdb/pull/6945 - `FileMetaData` 中已经包含了 `oldest_blob_file_number` - 这个 patch 在 `BlobFileMeta` 中添加了反向映射(oldest blob file -> sst),GC 时使用。 - linked/unlinked SSTs 的变更会累积到 `BlobFileMetaDataDelta` 中,在 save `Version` 时进行 apply。 ### 7001: Clean up blob files based on the linked SST set - https://github.com/facebook/rocksdb/pull/7001 - 处理:table files 被 simply dropped(例如 deletion compaction 或者 `DeleteFile` API) - cleans up all blob files at the head of the list until the first one with linked SSTs is found. - 例如有10个 blob files 编号 1..10 ,一个有 linked SSTs 的编号是 8,这意味着 SSTs 只依赖 >= 8 的 blob files,1..7 的就不再需要。 ### 7345: Integrate blob file writing with the flush logic ^9a8d9d - https://github.com/facebook/rocksdb/pull/7345 - 在 flush 期间可以分离大 Value 写入到 blob file - 生成的 blob files 会通过 flush job 的 `VersionEdit` 记录到 MANIFEST 中,然后添加到 `Version` 中,类似 table files。 - 在 `CompactionIterator` 中迭代时将大 value 写入到 blob file。 - `InternalStats::CompactionStats::bytes_written` 等统计信息也考虑 blob file 的写入。 ### 7573: Integrate BlobFileBuilder into the compaction process - https://github.com/facebook/rocksdb/pull/7573 - 类似 [[rocksdb-blobdb-prs#^9a8d9d]] ### 7694: Integrated blob garbage collection: relocate blobs ^2b538c - https://github.com/facebook/rocksdb/pull/7694 - Valid blobs residing in the oldest blob files are relocated as they are encountered during compaction - 根据 `blob_garbage_collection_age_cutoff` 参数判断哪些 blob files 属于 'old' - re-inline 所有 blob values(不分离)的方法: - 设置 `enable_blob_files` 为 `false` - 设置 `enable_blob_garbage_collection` 为 `true` - 设置 `blob_file_garbage_collection_age_cutoff` 为 `1.0` - 然后执行一次 full manual compaction - 只 relocate 小于 `blob_garbage_collection_cutoff_file_number_` 的 blobs ```cpp if (blob_index.file_number() >= blob_garbage_collection_cutoff_file_number_) { return; } ``` - `ComputeBlobGarbageCollectionCutoffFileNumber()` 计算 cutoff file number: ```cpp // blob_files: compaction input version 中的所有 blob files const size_t cutoff_index = static_cast<size_t>( compaction->blob_garbage_collection_age_cutoff() * blob_files.size()); const auto& meta = blob_files[cutoff_index]; return meta->GetBlobFileNumber(); ``` - relocate 逻辑就是读取出 blob,调用 `ExtractLargeValueIfNeededImpl` 尝试写入到新的 blob file 中 - 关键文件:`db/compaction/compaction_iterator.cc` ### 7731: Add blob support to DBIter - https://github.com/facebook/rocksdb/pull/7731 ### 7766: Add initial blob support to batched MultiGet - https://github.com/facebook/rocksdb/pull/7766 ### 7903: Accumulate blob file additions in VersionEdit during recovery  - https://github.com/facebook/rocksdb/pull/7903/ ### 8426: Add a class for measuring the amount of garbage generated during compaction ^c3365f - https://github.com/facebook/rocksdb/pull/8426 - 跟踪 (sub)compaction input 和 output 中每个 blob file 的 blobs 数量、大小 - 这些信息可以用来计算 compaction 产生的垃圾(流入减去流出) - 关键文件:`db/blob/blob_garbage_meter.{h,cc}` - 解析compaction 读取/写入的每对 KV, 如果类型是 `BlobIndex`,则累计到对应的 blob file 上。 ### 8443: Add an internal iterator that can measure the inflow of blobs - https://github.com/facebook/rocksdb/pull/8443 - 添加了一种新的 `InternalIterator`,它包装了另一个 `InternalIterator`,将遇到的每对 KV 作为 inflow 传递给 `BlobGarbageMeter` - 这个 iterator 将会用来作为 compaction 的 input iterator(当 input SSTs 引用 blob files 时) - 关键文件: `db/blob/blob_counting_iterator.h` ### 8450 Log the amount of blob garbage generated by compactions in the MANIFEST - https://github.com/facebook/rocksdb/pull/8450 - 测量 compaction 产生的垃圾,记录对应的 `BlobFileGarbage` 作为 compaction job `VersionEdit` 的一部分。 - 检查 compaction input 的 SSTs 是否引用 blob files,avoid unnecessary counting。 ### 8667 Add statistics support to integrated BlobDB - https://github.com/facebook/rocksdb/pull/8667 - Tickers - `BLOB_DB_BLOB_FILE_BYTES_READ` - `BLOB_DB_GC_{NUM_KEYS, BYTES}_RELOCATED` - Histograms - `BLOB_DB_(DE)COMPRESSION_MICROS` - 之前已经支持的: - `BLOB_DB_BLOB_FILE_BYTES_WRITTEN` - `BLOB_DB_BLOB_FILE_SYNCED` - `BLOB_DB_BLOB_FILE_{READ,WRITE,SYNC}_MICROS` ### 8902: Use GetBlobFileSize instead of GetTotalBlobBytes in DB properties ```cpp db_->GetIntProperty(DB::Properties::kTotalBlobFileSize, &total_blob_file_size)); ``` ^293d88 ### 8994: Make it possible to force the garbage collection of the oldest blob files ^bc3d52 - https://github.com/facebook/rocksdb/pull/8994 - 当前的 GC 逻辑: - 对 compaction 时遇到的 oldest blob files 进行 relocate,然后删除只包含垃圾的 blob files。 - 问题:包含 oldest blob files 的 SST files 可能没有触发 compaction,导致 GC 无法运行造成空间放大 - 添加了新的选项:`blob_garbage_collection_force_threshold` - 通知 BlobDB 为 SST files 调度定向 compaction。 - SST 条件: - 引用的 oldest blob files 的整体垃圾比例满足阈值 - 所有给定的 blob files 满足 `blob_garbage_collection_age_cutoff` 条件 - 例如设置成 0.9,如果 oldest blob files 的总垃圾 bytes 达到 90% 就会触发定向 compaction(将 oldest blob files 的 blobs 进行 relocate,清理oldest blob files)。 - 调度的 targeted compactions 只针对一个文件。(但可能也涉及相同 level 的相邻文件,满足 clean cut boundary 的需求)。 - 支持 leveled compaction style,默认关闭(默认值是 1.0) - 关键函数: - db/version_set.cc: `VersionStorageInfo::ComputeFilesMarkedForForcedBlobGC()` - 只考虑 age cut off 之前的 blob files - 每次只统计挑选一个batch;垃圾比例统计整个 batch 的; - batch 切分:以一个有 linked SSTs blob file开始遇到下一个有 linked SSTs 的截止(不包含它) - corner case:只有一个文件有 linked SSTs,age cut off 没选中所有文件(如果执行会导致下一个batch 开头的 blob file 没有 linked SSTs) - db/compaction/compaction_picker_level.cc: - `LevelCompactionBuilder::SetupInitialFiles()` - `PickFileToCompact(vstorage_->FilesMarkedForForcedBlobGC(), false);` ### 9538: Log blob file space amp and expose it via the rocksdb.blob-stats DB property ### 9548: Rework VersionStorageInfo::ComputeFilesMarkedForForcedBlobGC a bit - https://github.com/facebook/rocksdb/pull/9548 ### 10571: Introduce a dedicated class to represent blob values - https://github.com/facebook/rocksdb/pull/10571 - 增加 `BlobContents` b表示一个解压后的 blob value