Skip to content

Commit 00b3605

Browse files
committed
rgw/dedup: Add support for RGW versions.
Dedup code will scan all instances of versioned objects and include them in the dedup process Signed-off-by: Gabriel BenHanokh <[email protected]>
1 parent 5cc7a9d commit 00b3605

7 files changed

Lines changed: 278 additions & 51 deletions

File tree

‎src/rgw/driver/rados/rgw_dedup.cc‎

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,11 @@ namespace rgw::dedup {
418418
const rgw::sal::Bucket *p_bucket,
419419
const parsed_etag_t *p_parsed_etag,
420420
const std::string &obj_name,
421+
const std::string &instance,
421422
uint64_t obj_size,
422423
const std::string &storage_class)
423424
{
424-
disk_record_t rec(p_bucket, obj_name, p_parsed_etag, obj_size, storage_class);
425+
disk_record_t rec(p_bucket, obj_name, p_parsed_etag, instance, obj_size, storage_class);
425426
// First pass using only ETAG and size taken from bucket-index
426427
rec.s.flags.set_fastlane();
427428

@@ -682,10 +683,10 @@ namespace rgw::dedup {
682683
//---------------------------------------------------------------------------
683684
static int get_ioctx(const DoutPrefixProvider* const dpp,
684685
rgw::sal::Driver* driver,
685-
RGWRados* rados,
686+
rgw::sal::RadosStore* store,
686687
const disk_record_t *p_rec,
687688
librados::IoCtx *p_ioctx,
688-
std::string *oid)
689+
std::string *p_oid)
689690
{
690691
unique_ptr<rgw::sal::Bucket> bucket;
691692
{
@@ -698,23 +699,12 @@ namespace rgw::dedup {
698699
}
699700
}
700701

701-
build_oid(p_rec->bucket_id, p_rec->obj_name, oid);
702-
//ldpp_dout(dpp, 0) << __func__ << "::OID=" << oid << " || bucket_id=" << bucket_id << dendl;
703-
rgw_pool data_pool;
704-
rgw_obj obj{bucket->get_key(), *oid};
705-
if (!rados->get_obj_data_pool(bucket->get_placement_rule(), obj, &data_pool)) {
706-
ldpp_dout(dpp, 1) << __func__ << "::failed to get data pool for bucket "
707-
<< bucket->get_name() << dendl;
708-
return -EIO;
709-
}
710-
int ret = rgw_init_ioctx(dpp, rados->get_rados_handle(), data_pool, *p_ioctx);
711-
if (ret < 0) {
712-
ldpp_dout(dpp, 1) << __func__ << "::ERR: failed to get ioctx from data pool:"
713-
<< data_pool.to_str() << dendl;
714-
return -EIO;
715-
}
716-
717-
return 0;
702+
string dummy_locator;
703+
const rgw_obj_index_key key(p_rec->obj_name, p_rec->instance);
704+
rgw_obj obj(bucket->get_key(), key);
705+
get_obj_bucket_and_oid_loc(obj, *p_oid, dummy_locator);
706+
RGWBucketInfo& bucket_info = bucket->get_info();
707+
return store->get_obj_head_ioctx(dpp, bucket_info, obj, p_ioctx);
718708
}
719709

720710
//---------------------------------------------------------------------------
@@ -786,8 +776,8 @@ namespace rgw::dedup {
786776

787777
std::string src_oid, tgt_oid;
788778
librados::IoCtx src_ioctx, tgt_ioctx;
789-
int ret1 = get_ioctx(dpp, driver, rados, p_src_rec, &src_ioctx, &src_oid);
790-
int ret2 = get_ioctx(dpp, driver, rados, p_tgt_rec, &tgt_ioctx, &tgt_oid);
779+
int ret1 = get_ioctx(dpp, driver, store, p_src_rec, &src_ioctx, &src_oid);
780+
int ret2 = get_ioctx(dpp, driver, store, p_tgt_rec, &tgt_ioctx, &tgt_oid);
791781
if (unlikely(ret1 != 0 || ret2 != 0)) {
792782
ldpp_dout(dpp, 1) << __func__ << "::ERR: failed get_ioctx()" << dendl;
793783
return (ret1 ? ret1 : ret2);
@@ -1092,7 +1082,7 @@ namespace rgw::dedup {
10921082
<< p_rec->obj_name << ")" << dendl;
10931083
return 0;
10941084
}
1095-
1085+
p_obj->set_instance(p_rec->instance);
10961086
d_ctl.metadata_access_throttle.acquire();
10971087
ret = p_obj->get_obj_attrs(null_yield, dpp);
10981088
if (unlikely(ret < 0)) {
@@ -1190,7 +1180,7 @@ namespace rgw::dedup {
11901180
//---------------------------------------------------------------------------
11911181
static int write_blake3_object_attribute(const DoutPrefixProvider* const dpp,
11921182
rgw::sal::Driver* driver,
1193-
RGWRados* rados,
1183+
rgw::sal::RadosStore *store,
11941184
const disk_record_t *p_rec)
11951185
{
11961186
bufferlist etag_bl;
@@ -1203,7 +1193,7 @@ namespace rgw::dedup {
12031193

12041194
std::string oid;
12051195
librados::IoCtx ioctx;
1206-
int ret = get_ioctx(dpp, driver, rados, p_rec, &ioctx, &oid);
1196+
int ret = get_ioctx(dpp, driver, store, p_rec, &ioctx, &oid);
12071197
if (unlikely(ret != 0)) {
12081198
ldpp_dout(dpp, 5) << __func__ << "::ERR: failed get_ioctx()" << dendl;
12091199
return ret;
@@ -1298,10 +1288,11 @@ namespace rgw::dedup {
12981288
<< "/" << src_rec.obj_name << dendl;
12991289
// verify that SRC and TGT records don't refer to the same physical object
13001290
// This could happen in theory if we read the same objects twice
1301-
if (src_rec.obj_name == p_tgt_rec->obj_name && src_rec.bucket_name == p_tgt_rec->bucket_name) {
1291+
if (src_rec.ref_tag == p_tgt_rec->ref_tag) {
13021292
p_stats->duplicate_records++;
1303-
ldpp_dout(dpp, 10) << __func__ << "::WARN: Duplicate records for object="
1304-
<< src_rec.obj_name << dendl;
1293+
ldpp_dout(dpp, 10) << __func__ << "::WARN::REF_TAG::Duplicate records for "
1294+
<< src_rec.obj_name << "::" << src_rec.ref_tag << "::"
1295+
<< p_tgt_rec->obj_name << dendl;
13051296
return 0;
13061297
}
13071298

@@ -1320,11 +1311,11 @@ namespace rgw::dedup {
13201311
ldpp_dout(dpp, 10) << __func__ << "::HASH mismatch" << dendl;
13211312
// TBD: set hash attributes on head objects to save calc next time
13221313
if (src_rec.s.flags.hash_calculated()) {
1323-
write_blake3_object_attribute(dpp, driver, rados, &src_rec);
1314+
write_blake3_object_attribute(dpp, driver, store, &src_rec);
13241315
p_stats->set_hash_attrs++;
13251316
}
13261317
if (p_tgt_rec->s.flags.hash_calculated()) {
1327-
write_blake3_object_attribute(dpp, driver, rados, p_tgt_rec);
1318+
write_blake3_object_attribute(dpp, driver, store, p_tgt_rec);
13281319
p_stats->set_hash_attrs++;
13291320
}
13301321
return 0;
@@ -1582,8 +1573,8 @@ namespace rgw::dedup {
15821573
}
15831574

15841575
return add_disk_rec_from_bucket_idx(disk_arr, p_bucket, &parsed_etag,
1585-
entry.key.name, entry.meta.size,
1586-
storage_class);
1576+
entry.key.name, entry.key.instance,
1577+
entry.meta.size, storage_class);
15871578
}
15881579

15891580
//---------------------------------------------------------------------------
@@ -1682,15 +1673,21 @@ namespace rgw::dedup {
16821673
obj_count += result.dir.m.size();
16831674
for (auto& entry : result.dir.m) {
16841675
const rgw_bucket_dir_entry& dirent = entry.second;
1676+
// make sure to advance marker in all cases!
1677+
marker = dirent.key;
1678+
ldpp_dout(dpp, 20) << __func__ << "::dirent = " << bucket->get_name() << "/"
1679+
<< marker.name << "::instance=" << marker.instance << dendl;
16851680
if (unlikely((!dirent.exists && !dirent.is_delete_marker()) || !dirent.pending_map.empty())) {
16861681
// TBD: should we bailout ???
1687-
ldpp_dout(dpp, 1) << __func__ << "::ERR: calling check_disk_state bucket="
1688-
<< bucket->get_name() << " entry=" << dirent.key << dendl;
1689-
// make sure we're advancing marker
1690-
marker = dirent.key;
1682+
ldpp_dout(dpp, 1) << __func__ << "::ERR: bad dirent::" << bucket->get_name()
1683+
<< "/" << marker.name << "::instance=" << marker.instance << dendl;
1684+
continue;
1685+
}
1686+
else if (unlikely(dirent.is_delete_marker())) {
1687+
ldpp_dout(dpp, 20) << __func__ << "::skip delete_marker::" << bucket->get_name()
1688+
<< "/" << marker.name << "::instance=" << marker.instance << dendl;
16911689
continue;
16921690
}
1693-
marker = dirent.key;
16941691
ret = ingress_bucket_idx_single_object(disk_arr, bucket, dirent, p_worker_stats);
16951692
}
16961693
// TBD: advance marker only once here!

‎src/rgw/driver/rados/rgw_dedup.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ namespace rgw::dedup {
161161
const rgw::sal::Bucket *p_bucket,
162162
const parsed_etag_t *p_parsed_etag,
163163
const std::string &obj_name,
164+
const std::string &instance,
164165
uint64_t obj_size,
165166
const std::string &storage_class);
166167

‎src/rgw/driver/rados/rgw_dedup_cluster.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace rgw::dedup {
4343

4444
//---------------------------------------------------------------------------
4545
void set_shard(uint16_t shard) {
46-
int n = snprintf(this->buff + this->prefix_len, BUFF_SIZE, "%03x", shard);
46+
int n = snprintf(this->buff + this->prefix_len, BUFF_SIZE - this->prefix_len, "%03x", shard);
4747
this->total_len = this->prefix_len + n;
4848
}
4949

@@ -55,7 +55,7 @@ namespace rgw::dedup {
5555
inline const char* get_buff() { return this->buff; }
5656
inline unsigned get_buff_size() { return this->total_len; }
5757
private:
58-
static const unsigned BUFF_SIZE = 15;
58+
static const unsigned BUFF_SIZE = 16;
5959
unsigned total_len = 0;
6060
unsigned prefix_len = 0;
6161
char buff[BUFF_SIZE];

‎src/rgw/driver/rados/rgw_dedup_store.cc‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace rgw::dedup {
3636
disk_record_t::disk_record_t(const rgw::sal::Bucket *p_bucket,
3737
const std::string &obj_name,
3838
const parsed_etag_t *p_parsed_etag,
39+
const std::string &instance,
3940
uint64_t obj_size,
4041
const std::string &storage_class)
4142
{
@@ -50,12 +51,13 @@ namespace rgw::dedup {
5051
this->s.md5_high = p_parsed_etag->md5_high;
5152
this->s.md5_low = p_parsed_etag->md5_low;
5253
this->s.obj_bytes_size = obj_size;
53-
this->s.object_version = 0;
5454

5555
this->bucket_id = p_bucket->get_bucket_id();
5656
this->s.bucket_id_len = this->bucket_id.length();
5757
this->tenant_name = p_bucket->get_tenant();
5858
this->s.tenant_name_len = this->tenant_name.length();
59+
this->instance = instance;
60+
this->s.instance_len = instance.length();
5961
this->stor_class = storage_class;
6062
this->s.stor_class_len = storage_class.length();
6163

@@ -86,10 +88,10 @@ namespace rgw::dedup {
8688
this->s.md5_high = CEPHTOH_64(p_rec->s.md5_high);
8789
this->s.md5_low = CEPHTOH_64(p_rec->s.md5_low);
8890
this->s.obj_bytes_size = CEPHTOH_64(p_rec->s.obj_bytes_size);
89-
this->s.object_version = CEPHTOH_64(p_rec->s.object_version);
9091

9192
this->s.bucket_id_len = CEPHTOH_16(p_rec->s.bucket_id_len);
9293
this->s.tenant_name_len = CEPHTOH_16(p_rec->s.tenant_name_len);
94+
this->s.instance_len = CEPHTOH_16(p_rec->s.instance_len);
9395
this->s.stor_class_len = CEPHTOH_16(p_rec->s.stor_class_len);
9496
this->s.ref_tag_len = CEPHTOH_16(p_rec->s.ref_tag_len);
9597
this->s.manifest_len = CEPHTOH_16(p_rec->s.manifest_len);
@@ -107,6 +109,9 @@ namespace rgw::dedup {
107109
this->tenant_name = std::string(p, this->s.tenant_name_len);
108110
p += p_rec->s.tenant_name_len;
109111

112+
this->instance = std::string(p, this->s.instance_len);
113+
p += p_rec->s.instance_len;
114+
110115
this->stor_class = std::string(p, this->s.stor_class_len);
111116
p += p_rec->s.stor_class_len;
112117

@@ -144,10 +149,10 @@ namespace rgw::dedup {
144149
p_rec->s.md5_high = HTOCEPH_64(this->s.md5_high);
145150
p_rec->s.md5_low = HTOCEPH_64(this->s.md5_low);
146151
p_rec->s.obj_bytes_size = HTOCEPH_64(this->s.obj_bytes_size);
147-
p_rec->s.object_version = HTOCEPH_64(this->s.object_version);
148152

149153
p_rec->s.bucket_id_len = HTOCEPH_16(this->bucket_id.length());
150154
p_rec->s.tenant_name_len = HTOCEPH_16(this->tenant_name.length());
155+
p_rec->s.instance_len = HTOCEPH_16(this->instance.length());
151156
p_rec->s.stor_class_len = HTOCEPH_16(this->stor_class.length());
152157
p_rec->s.ref_tag_len = HTOCEPH_16(this->ref_tag.length());
153158
p_rec->s.manifest_len = HTOCEPH_16(this->manifest_bl.length());
@@ -168,6 +173,10 @@ namespace rgw::dedup {
168173
std::memcpy(p, this->tenant_name.data(), len);
169174
p += len;
170175

176+
len = this->instance.length();
177+
std::memcpy(p, this->instance.data(), len);
178+
p += len;
179+
171180
len = this->stor_class.length();
172181
std::memcpy(p, this->stor_class.data(), len);
173182
p += len;
@@ -205,6 +214,7 @@ namespace rgw::dedup {
205214
this->bucket_name.length() +
206215
this->bucket_id.length() +
207216
this->tenant_name.length() +
217+
this->instance.length() +
208218
this->stor_class.length() +
209219
this->ref_tag.length() +
210220
this->manifest_bl.length());
@@ -252,6 +262,7 @@ namespace rgw::dedup {
252262
stream << rec.bucket_name << "::" << rec.s.bucket_name_len << "\n";
253263
stream << rec.bucket_id << "::" << rec.s.bucket_id_len << "\n";
254264
stream << rec.tenant_name << "::" << rec.s.tenant_name_len << "\n";
265+
stream << rec.instance << "::" << rec.s.instance_len << "\n";
255266
stream << rec.stor_class << "::" << rec.s.stor_class_len << "\n";
256267
stream << rec.ref_tag << "::" << rec.s.ref_tag_len << "\n";
257268
stream << "num_parts = " << rec.s.num_parts << "\n";

‎src/rgw/driver/rados/rgw_dedup_store.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ namespace rgw::dedup {
138138
disk_record_t(const rgw::sal::Bucket *p_bucket,
139139
const std::string &obj_name,
140140
const parsed_etag_t *p_parsed_etag,
141+
const std::string &instance,
141142
uint64_t obj_size,
142143
const std::string &storage_class);
143144
disk_record_t() {}
@@ -161,10 +162,10 @@ namespace rgw::dedup {
161162
uint64_t md5_high; // High Bytes of the Object Data MD5
162163
uint64_t md5_low; // Low Bytes of the Object Data MD5
163164
uint64_t obj_bytes_size;
164-
uint64_t object_version;
165165

166166
uint16_t bucket_id_len;
167167
uint16_t tenant_name_len;
168+
uint16_t instance_len;
168169
uint16_t stor_class_len;
169170
uint16_t ref_tag_len;
170171

@@ -180,6 +181,7 @@ namespace rgw::dedup {
180181
std::string bucket_id;
181182
std::string tenant_name;
182183
std::string ref_tag;
184+
std::string instance;
183185
std::string stor_class;
184186
bufferlist manifest_bl;
185187
};

‎src/rgw/driver/rados/rgw_dedup_utils.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,6 @@ namespace rgw::dedup {
356356
size_t len,
357357
const DoutPrefixProvider* dpp);
358358

359-
//---------------------------------------------------------------------------
360-
static inline void build_oid(const std::string &bucket_id,
361-
const std::string &obj_name,
362-
std::string *oid)
363-
{
364-
*oid = bucket_id + "_" + obj_name;
365-
}
366-
367359
//---------------------------------------------------------------------------
368360
static inline uint64_t calc_deduped_bytes(uint64_t head_obj_size,
369361
uint16_t num_parts,

0 commit comments

Comments
 (0)