This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from ceph/ceph
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rgw/sfs: sqlite_modern_cpp blobs, users and objects changes
Adds another step on moving the sqlite code to sqlite_modern_cpp. Adds the code to store/retrieve ceph types as blobs. Adds a new mechanism to declare when a type that has encode and decode functions needs to be stored as a blob. In order to add a new type, simple add the type to the following tuple. ```c++ using BlobTypes = std::tuple< rgw::sal::Attrs, ACLOwner, rgw_placement_rule, std::map<std::string, RGWAccessKey>, std::map<std::string, RGWSubUser>, RGWUserCaps, std::list<std::string>, std::map<int, std::string>, RGWQuotaInfo, std::set<std::string>, RGWBucketWebsiteConf, std::map<std::string, uint32_t>, RGWObjectLock, rgw_sync_policy_info> ``` Adds a new header (`dbabpi_type_wrapper.h`) file that should be included when declaring type bindings for `sqlite_modern_cpp`. We need this to avoid circular dependencies with the `bind_col_in_db` function from `sqlite_moden_cpp`. This (from the main `sqlite_modern_cpp.h` file): ```c++ template<typename T> database_binder &operator<<(database_binder& db, index_binding_helper<T> val) { db._next_index(); --db._inx; int result = bind_col_in_db(db._stmt.get(), val.index, std::forward<T>(val.value)); if(result != SQLITE_OK) exceptions::throw_sqlite_error(result, db.sql(), sqlite3_errmsg(db._db.get())); return db; } ``` calls `bind_col_in_db`, but the function specialisation needs to be declared first. So, when declaring type bindings we should only include `sqlite_modern_cpp/type_wrapper.h` Changes all BLOB types in Users to the binding types. Changes all functions in `sqlite_users` to use `sqlite_modern_cpp`. Deletes the conversions files for Users. (conversion is still needed because we need to create the `RGWUserInfo` object needed for SAL layer, the conversion required is only db->SAL ) Changes all funcions in `sqlite_objects` to use `sqlite_modern_cpp` Signed-off-by: Xavi Garcia <[email protected]>
- Loading branch information
Showing
15 changed files
with
397 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <sqlite3.h> | ||
|
||
namespace rgw::sal::sfs::dbapi { | ||
|
||
#include "sqlite_modern_cpp/hdr/sqlite_modern_cpp/type_wrapper.h" | ||
|
||
} // namespace rgw::sal::sfs::dbapi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t | ||
// vim: ts=8 sw=2 smarttab ft=cpp | ||
/* | ||
* Ceph - scalable distributed file system | ||
* SFS SAL implementation | ||
* | ||
* Copyright (C) 2023 SUSE LLC | ||
* | ||
* This is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License version 2.1, as published by the Free Software | ||
* Foundation. See file COPYING. | ||
*/ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "common/Formatter.h" | ||
#include "rgw/driver/sfs/sqlite/dbapi.h" | ||
|
||
namespace rgw::sal::sfs::sqlite { | ||
|
||
// Helper to return a vector with all the objects in a given table | ||
// This needs that Target has a constructor with a tuple listing all the | ||
// columns. | ||
// TODO See if we can do this in a more elegant way without investing too much | ||
// time. | ||
template <typename Target> | ||
inline std::vector<Target> GetSQLiteObjects( | ||
dbapi::sqlite::database db, const std::string& table_name | ||
) { | ||
auto rows = db << fmt::format("SELECT * FROM {};", table_name); | ||
std::vector<Target> ret; | ||
for (auto&& row : rows) { | ||
ret.emplace_back(Target(row)); | ||
} | ||
return ret; | ||
} | ||
|
||
// Helper to get a vector with all the objects in a given table with a single | ||
// condition. | ||
template <typename Target, typename ColumWhereType> | ||
inline std::vector<Target> GetSQLiteObjectsWhere( | ||
dbapi::sqlite::database db, const std::string& table_name, | ||
const std::string& column_name, const ColumWhereType& column_value | ||
) { | ||
auto rows = | ||
db << fmt::format( | ||
"SELECT * FROM {} WHERE {} = ?;", table_name, column_name | ||
) | ||
<< column_value; | ||
std::vector<Target> ret; | ||
for (auto&& row : rows) { | ||
ret.emplace_back(Target(row)); | ||
} | ||
return ret; | ||
} | ||
|
||
// Helper to get a single object from a table | ||
template <typename Target, typename KeyType> | ||
inline std::optional<Target> GetSQLiteSingleObject( | ||
dbapi::sqlite::database db, const std::string& table_name, | ||
const std::string& key_name, const KeyType& key_value | ||
) { | ||
auto rows = | ||
db << fmt::format("SELECT * FROM {} WHERE {} = ?;", table_name, key_name) | ||
<< key_value; | ||
std::optional<Target> ret; | ||
for (auto&& row : rows) { | ||
ret = Target(row); | ||
break; // looking for a single object, it should return 0 or 1 entries. | ||
// TODO Return an error in there are more than 1 entry? | ||
} | ||
return ret; | ||
} | ||
} // namespace rgw::sal::sfs::sqlite |
Oops, something went wrong.