Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #124 from irq0/pr/remove-types-objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Lauhoff authored Mar 23, 2023
2 parents 51e469f + 162e12d commit 256ad80
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 220 deletions.
33 changes: 15 additions & 18 deletions src/rgw/driver/sfs/bucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "driver/sfs/multipart.h"
#include "driver/sfs/object.h"
#include "driver/sfs/sqlite/sqlite_versioned_objects.h"
#include "driver/sfs/types.h"
#include "rgw_sal_sfs.h"

#define dout_subsys ceph_subsys_rgw
Expand Down Expand Up @@ -52,16 +53,16 @@ std::unique_ptr<Object> SFSBucket::get_object(const rgw_obj_key& key) {

ldout(store->ceph_context(), 10)
<< "bucket::" << __func__ << ": key" << key << dendl;
std::lock_guard l(bucket->obj_map_lock);
auto it = bucket->objects.find(key.name);
if (it == bucket->objects.end()) {
try {
auto objref = bucket->get(key.name);
return _get_object(objref);
} catch (const sfs::UnknownObjectException& _) {
ldout(store->ceph_context(), 10)
<< "unable to find key " << key << " in bucket " << bucket->get_name()
<< dendl;
// possibly a copy, return a placeholder
return make_unique<SFSObject>(this->store, key, this, bucket);
}
return _get_object(it->second);
}

/**
Expand All @@ -76,27 +77,25 @@ int SFSBucket::list(
if (params.list_versions) {
return list_versions(dpp, params, max, results, y);
}

std::lock_guard l(bucket->obj_map_lock);
sfs::sqlite::SQLiteVersionedObjects db_versioned_objects(store->db_conn);
auto use_prefix = !params.prefix.empty();
for (const auto& [name, objref] : bucket->objects) {
if (use_prefix && name.rfind(params.prefix, 0) != 0) continue;
lsfs_dout(dpp, 10) << "object: " << name << dendl;
for (const auto& objref : bucket->get_all()) {
if (use_prefix && objref->name.rfind(params.prefix, 0) != 0) continue;
lsfs_dout(dpp, 10) << "object: " << objref->name << dendl;

auto last_version =
db_versioned_objects.get_last_versioned_object(objref->path.get_uuid());
if (last_version->object_state == rgw::sal::ObjectState::COMMITTED) {
// check for delimiter
if (check_add_common_prefix(dpp, name, params, 0, results, y)) {
if (check_add_common_prefix(dpp, objref->name, params, 0, results, y)) {
continue;
}
auto obj = _get_object(objref);
rgw_bucket_dir_entry dirent;
dirent.key = cls_rgw_obj_key(name, objref->instance);
dirent.key = cls_rgw_obj_key(objref->name, objref->instance);
dirent.meta.accounted_size = obj->get_obj_size();
dirent.meta.mtime = obj->get_mtime();
dirent.meta.etag = objref->meta.etag;
dirent.meta.etag = objref->get_meta().etag;
dirent.meta.owner_display_name = bucket->get_owner().display_name;
dirent.meta.owner = bucket->get_owner().user_id.id;
results.objs.push_back(dirent);
Expand All @@ -111,13 +110,12 @@ int SFSBucket::list_versions(
const DoutPrefixProvider* dpp, ListParams& params, int,
ListResults& results, optional_yield y
) {
std::lock_guard l(bucket->obj_map_lock);
auto use_prefix = !params.prefix.empty();
for (const auto& [name, objref] : bucket->objects) {
if (use_prefix && name.rfind(params.prefix, 0) != 0) continue;
lsfs_dout(dpp, 10) << "object: " << name << dendl;
for (const auto& objref : bucket->get_all()) {
if (use_prefix && objref->name.rfind(params.prefix, 0) != 0) continue;
lsfs_dout(dpp, 10) << "object: " << objref->name << dendl;
// check for delimiter
if (check_add_common_prefix(dpp, name, params, 0, results, y)) {
if (check_add_common_prefix(dpp, objref->name, params, 0, results, y)) {
continue;
}
// get all available versions from db
Expand Down Expand Up @@ -173,7 +171,6 @@ int SFSBucket::remove_bucket(
const DoutPrefixProvider* dpp, bool delete_children, bool forward_to_master,
req_info* req_info, optional_yield y
) {
std::lock_guard l(bucket->obj_map_lock);
if (!delete_children) {
if (check_empty(dpp, y)) {
return -ENOENT;
Expand Down
9 changes: 5 additions & 4 deletions src/rgw/driver/sfs/multipart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::unique_ptr<rgw::sal::Object> SFSMultipartUpload::get_meta_obj() {
);
mmo->set_attrs(mp->attrs);
mmo->set_object_ref(mp->objref);
mp->objref->meta.attrs = mp->attrs;
mp->objref->update_attrs(mp->attrs);
return mmo;
}

Expand Down Expand Up @@ -237,11 +237,12 @@ int SFSMultipartUpload::complete(
<< ", accounted: " << accounted_size << ", offset: " << ofs
<< ", etag: " << etag << dendl;

sfs::Object::Meta& meta = outobj->meta;
sfs::Object::Meta meta = outobj->get_meta();
meta.size = accounted_size;
meta.etag = etag;
meta.mtime = ceph::real_clock::now();
meta.attrs = mp->attrs;
outobj->update_meta(meta);
outobj->update_attrs(mp->attrs);

// remove all multipart objects. This should be done lazily in the future.
for (const auto& [n, part] : parts) {
Expand Down Expand Up @@ -284,7 +285,7 @@ int SFSMultipartUpload::get_info(
}

if (attrs) {
*attrs = mp->objref->meta.attrs;
*attrs = mp->objref->get_attrs();
}

return 0;
Expand Down
42 changes: 22 additions & 20 deletions src/rgw/driver/sfs/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "driver/sfs/multipart.h"
#include "driver/sfs/sqlite/sqlite_versioned_objects.h"
#include "driver/sfs/types.h"
#include "rgw_sal_sfs.h"

#define dout_subsys ceph_subsys_rgw
Expand Down Expand Up @@ -240,8 +241,10 @@ int SFSObject::copy_object(
return -EIO;
}

dstref->meta = objref->meta;
dstref->meta.mtime = ceph::real_clock::now();
auto dest_meta = objref->get_meta();
dest_meta.mtime = ceph::real_clock::now();
dstref->update_attrs(objref->get_attrs());
dstref->update_meta(dest_meta);
dstref->metadata_finish(store);

return 0;
Expand Down Expand Up @@ -290,22 +293,21 @@ int SFSObject::set_obj_attrs(
optional_yield y
) {
ceph_assert(objref);
auto& meta = objref->meta;
map<string, bufferlist>::iterator iter;

if (delattrs) {
for (iter = delattrs->begin(); iter != delattrs->end(); ++iter) {
meta.attrs.erase(iter->first);
objref->del_attr(iter->first);
}
}
if (setattrs) {
for (iter = setattrs->begin(); iter != setattrs->end(); ++iter) {
meta.attrs[iter->first] = iter->second;
objref->set_attr(iter->first, iter->second);
}
}

//synch attrs caches
state.attrset = meta.attrs;
state.attrset = objref->get_attrs();
state.has_attrs = true;

objref->metadata_flush_attrs(store);
Expand All @@ -324,11 +326,10 @@ int SFSObject::modify_obj_attrs(
return 0;
}
ceph_assert(objref);
auto& meta = objref->meta;
meta.attrs[attr_name] = attr_val;
objref->set_attr(attr_name, attr_val);

//synch attrs caches
state.attrset = meta.attrs;
state.attrset = objref->get_attrs();
state.has_attrs = true;

objref->metadata_flush_attrs(store);
Expand All @@ -342,10 +343,9 @@ int SFSObject::delete_obj_attrs(
return 0;
}
ceph_assert(objref);
auto& meta = objref->meta;
if (meta.attrs.erase(attr_name)) {
if (objref->del_attr(attr_name)) {
//synch attrs caches
state.attrset = meta.attrs;
state.attrset = objref->get_attrs();
state.has_attrs = true;

objref->metadata_flush_attrs(store);
Expand Down Expand Up @@ -458,18 +458,20 @@ void SFSObject::_refresh_meta_from_object() {
if (db_version.has_value()) {
auto uuid = objref->path.get_uuid();
auto deleted = db_version->object_state == ObjectState::DELETED;
objref = std::make_shared<sfs::Object>(get_name(), uuid, deleted);
objref->version_id = db_version->id;
objref.reset(sfs::Object::create_for_query(
get_name(), uuid, deleted, db_version->id
));
set_obj_size(db_version->size);
objref->meta.attrs = db_version->attrs;
objref->meta.etag = db_version->etag;
objref->update_attrs(db_version->attrs);
auto meta = objref->get_meta();
meta.etag = db_version->etag;
objref->update_meta(meta);
}
} else {
set_obj_size(objref->meta.size);
set_obj_size(objref->get_meta().size);
}
auto& meta = objref->meta;
set_attrs(meta.attrs);
state.mtime = meta.mtime;
set_attrs(objref->get_attrs());
state.mtime = objref->get_meta().mtime;
}

} // namespace rgw::sal
33 changes: 18 additions & 15 deletions src/rgw/driver/sfs/sfs_gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
#include "sfs_gc.h"

#include "driver/sfs/types.h"
#include "rgw/driver/sfs/sqlite/sqlite_objects.h"

namespace rgw::sal::sfs {
Expand Down Expand Up @@ -94,19 +95,22 @@ void SFSGC::delete_objects(const std::string& bucket_id) {
break;
}
auto obj_instance =
std::make_shared<Object>(object.name, object.uuid, true);
delete_object(obj_instance);
std::unique_ptr<Object>(Object::create_for_immediate_deletion(object));
delete_object(*obj_instance.get());
}
}

void SFSGC::delete_versioned_objects(const std::shared_ptr<Object>& object) {
void SFSGC::delete_versioned_objects(const Object& object) {
sqlite::SQLiteVersionedObjects db_ver_objs(store->db_conn);
auto versions = db_ver_objs.get_versioned_objects(object->path.get_uuid());
auto versions = db_ver_objs.get_versioned_objects(object.path.get_uuid());
for (auto const& version : versions) {
if (max_objects <= 0) {
break;
}
delete_versioned_object(object, version.id);

Object to_be_deleted(object);
to_be_deleted.version_id = version.id;
delete_versioned_object(to_be_deleted);
}
}

Expand All @@ -121,24 +125,23 @@ void SFSGC::delete_bucket(const std::string& bucket_id) {
}
}

void SFSGC::delete_object(const std::shared_ptr<Object>& object) {
void SFSGC::delete_object(const Object& object) {
// delete its versions first
delete_versioned_objects(object);
if (max_objects > 0) {
object->delete_object(store);
lsfs_dout(this, 30) << "Deleted object: " << object->path.get_uuid()
object.delete_object_metadata(store);
object.delete_object_data(store, true);
lsfs_dout(this, 30) << "Deleted object: " << object.path.get_uuid()
<< dendl;
--max_objects;
}
}

void SFSGC::delete_versioned_object(
const std::shared_ptr<Object>& object, uint id
) {
object->version_id = id;
object->delete_object_version(store);
lsfs_dout(this, 30) << "Deleted version: (" << object->path.get_uuid() << ","
<< id << ")" << dendl;
void SFSGC::delete_versioned_object(const Object& object) {
object.delete_object_version(store);
object.delete_object_data(store, false);
lsfs_dout(this, 30) << "Deleted version: (" << object.path.get_uuid() << ","
<< object.version_id << ")" << dendl;
--max_objects;
}

Expand Down
6 changes: 3 additions & 3 deletions src/rgw/driver/sfs/sfs_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ class SFSGC : public DoutPrefixProvider {
void process_deleted_buckets();

void delete_objects(const std::string& bucket_id);
void delete_versioned_objects(const std::shared_ptr<Object>& object);
void delete_versioned_objects(const Object& object);

void delete_bucket(const std::string& bucket_id);
void delete_object(const std::shared_ptr<Object>& object);
void delete_versioned_object(const std::shared_ptr<Object>& object, uint id);
void delete_object(const Object& object);
void delete_versioned_object(const Object& object);
};

} // namespace rgw::sal::sfs
Loading

0 comments on commit 256ad80

Please sign in to comment.