]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/blob/blob_garbage_meter.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 #include "db/blob/blob_garbage_meter.h"
8 #include "db/blob/blob_index.h"
9 #include "db/blob/blob_log_format.h"
10 #include "db/dbformat.h"
12 namespace ROCKSDB_NAMESPACE
{
14 Status
BlobGarbageMeter::ProcessInFlow(const Slice
& key
, const Slice
& value
) {
15 uint64_t blob_file_number
= kInvalidBlobFileNumber
;
18 const Status s
= Parse(key
, value
, &blob_file_number
, &bytes
);
23 if (blob_file_number
== kInvalidBlobFileNumber
) {
27 flows_
[blob_file_number
].AddInFlow(bytes
);
32 Status
BlobGarbageMeter::ProcessOutFlow(const Slice
& key
, const Slice
& value
) {
33 uint64_t blob_file_number
= kInvalidBlobFileNumber
;
36 const Status s
= Parse(key
, value
, &blob_file_number
, &bytes
);
41 if (blob_file_number
== kInvalidBlobFileNumber
) {
45 // Note: in order to measure the amount of additional garbage, we only need to
46 // track the outflow for preexisting files, i.e. those that also had inflow.
47 // (Newly written files would only have outflow.)
48 auto it
= flows_
.find(blob_file_number
);
49 if (it
== flows_
.end()) {
53 it
->second
.AddOutFlow(bytes
);
58 Status
BlobGarbageMeter::Parse(const Slice
& key
, const Slice
& value
,
59 uint64_t* blob_file_number
, uint64_t* bytes
) {
60 assert(blob_file_number
);
61 assert(*blob_file_number
== kInvalidBlobFileNumber
);
65 ParsedInternalKey ikey
;
68 constexpr bool log_err_key
= false;
69 const Status s
= ParseInternalKey(key
, &ikey
, log_err_key
);
75 if (ikey
.type
!= kTypeBlobIndex
) {
82 const Status s
= blob_index
.DecodeFrom(value
);
88 if (blob_index
.IsInlined() || blob_index
.HasTTL()) {
89 return Status::Corruption("Unexpected TTL/inlined blob index");
92 *blob_file_number
= blob_index
.file_number();
95 BlobLogRecord::CalculateAdjustmentForRecordHeader(ikey
.user_key
.size());
100 } // namespace ROCKSDB_NAMESPACE