-
Notifications
You must be signed in to change notification settings - Fork 296
Conversation
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
* Initial SOCI integration to CMake build * Add download step for SOCI * Replace pqxx with soci in dockerfiles * Enable packaging for SOCI * Fix new directory path when downloading * Fix pg_config and include not found by SOCI when pq not installed * Fix docs, snapcraft; remove pqxx include * Remove extra ; and add missing link library Signed-off-by: Andrei Lebedev <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
…nto feature/soci
+ transaction_.quote(command.assetId()) + ", " | ||
+ transaction_.quote(index) + ");"); | ||
status &= res != boost::none; | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to put all SQL queries into a separate function to avoid try-catch on any query
@@ -68,18 +65,19 @@ namespace iroha { | |||
auto ids = {account_id, | |||
command.srcAccountId(), | |||
command.destAccountId()}; | |||
auto asset_id = command.assetId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use reference?
sql_ << "SELECT height FROM height_by_hash WHERE hash = :hash", | ||
soci::into(block_str), soci::use(hash_str); | ||
if (block_str) { | ||
blockId = std::stoull(block_str.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use row::get to retrieve?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fails. Height is stored as a string in postgres. Maybe it's better to store it as an integer?
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
st.exchange(soci::use(account_id, "account_id")); | ||
st.exchange(soci::use(perm_str, "perm")); | ||
|
||
auto msg = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make that into a lambda. We do not want to instantiate error message in the successful path.
st.exchange(soci::use(account_id, "account_id")); | ||
st.exchange(soci::use(perm_str, "perm")); | ||
|
||
auto msg = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make that into a lambda so it is evaluated only when we fail to perform the query.
PostgresWsvQuery(std::unique_ptr<pqxx::lazyconnection> connection, | ||
std::unique_ptr<pqxx::nontransaction> transaction); | ||
explicit PostgresWsvQuery(soci::session &sql); | ||
PostgresWsvQuery(std::unique_ptr<soci::session> sql_ptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it explicit since it accepts single parameter now
Signed-off-by: Victor Drobny <[email protected]>
.template as<shared_model::interface::types::HeightType>(); | ||
}); | ||
}; | ||
std::vector<shared_model::interface::types::HeightType> result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sequence of statements is repeated when you select several rows from the database, maybe refactor it to a separate function?
PostgresBlockQuery(std::unique_ptr<pqxx::lazyconnection> connection, | ||
std::unique_ptr<pqxx::nontransaction> transaction, | ||
PostgresBlockQuery(soci::session &sql, KeyValueStorage &file_store); | ||
PostgresBlockQuery(std::unique_ptr<soci::session> sql_ptr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make explicit
return (boost::format("failed to insert role permissions, role " | ||
"id: '%s', permissions: [%s]") | ||
% role_id % perm_debug_str) | ||
% role_id % perm_str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to print perm_debug_str here
* @param transform_func - function which transforms result row to T | ||
* @return vector of target type | ||
*/ | ||
template <typename T, typename Operator> | ||
std::vector<T> transform(const pqxx::result &result, | ||
std::vector<T> transform(const soci::rowset<soci::row> &result, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these functions out of command executor
} | ||
|
||
template <typename T, typename Operator> | ||
std::vector<T> transform(const std::vector<soci::row> &result, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this function is supposed to do?
scripts/local-develop.sh
Outdated
@@ -36,6 +36,8 @@ pghost=127.0.0.1 | |||
|
|||
pgid=$(docker run -p $pghost:$pgport:$pgport --rm --name $pgname -e POSTGRES_USER=$user -e POSTGRES_PASSSWORD=$password -d postgres:9.5) | |||
|
|||
docker run -p 127.0.0.1:5432:5432 --rm --name postgrestestimage -e POSTGRES_USER=postgres -e POSTGRES_PASSSWORD=mysecretpassword -d postgres:9.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the operator ,
isn't used for statements? E.g
sql << "SELECT * FROM table", into(val);
+ transaction_.quote(command.assetId()) + ", " | ||
+ transaction_.quote(index) + ");"); | ||
status &= res != boost::none; | ||
soci::statement st = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn' the =
operator have the lowest priority? I mean the braces around prepare seems redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, comma has lower priority
@@ -94,26 +106,31 @@ namespace iroha { | |||
block.transactions() | boost::adaptors::indexed(0), | |||
[&](const auto &tx) { | |||
const auto &creator_id = tx.value().creatorAccountId(); | |||
const auto &hash = tx.value().hash().blob(); | |||
const auto &hash = tx.value().hash().hex(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using soci::blob
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blob in postgres is designed for large files. I'm not sure that it is necessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That fixes changes schema and should be considered (if necessary) in other pr at least. It better to minimize the fixes here
: transaction_(transaction), | ||
log_(logger::log("PostgresBlockIndex")), | ||
execute_{makeExecuteOptional(transaction_, log_)} {} | ||
bool executeSOCI(soci::statement &st) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
executeSoci
please
@@ -106,43 +80,81 @@ namespace iroha { | |||
} | |||
} | |||
|
|||
template <typename Function, typename ParamType> | |||
void processSOCI(soci::statement &st, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, processSoci
*sql_ << "CREATE TABLE IF NOT EXISTS ordering_service_state " | ||
"(proposal_height bigserial)"; | ||
*sql_ << "INSERT INTO ordering_service_state VALUES (2)"; | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about false case? Same for the following
.build(); | ||
}); | ||
} | ||
|
||
static inline shared_model::builder::BuilderResult< | ||
shared_model::interface::AccountAsset> | ||
makeAccountAsset(const pqxx::row &row) noexcept { | ||
makeAccountAsset(const soci::row &row) noexcept { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better change the signature as well: pass 3 strings
Or maybe all similar function can use soci::row
Anyway that inconsistency should be resolved
processSOCI(st, ind, row, [&assets, &account_id](soci::row &row) { | ||
auto result = fromResult(makeAccountAsset( | ||
account_id, row.get<std::string>(1), row.get<std::string>(2))); | ||
if (result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
monadic bind?
soci::into(size), soci::use(name); | ||
|
||
if (size == 0) { | ||
std::string query = "CREATE DATABASE "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CREATE DATABASE :dbname
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason it does not work
@@ -57,6 +57,5 @@ target_link_libraries(postgres_options_test | |||
|
|||
add_library(ametsuchi_fixture INTERFACE) | |||
target_link_libraries(ametsuchi_fixture INTERFACE | |||
pqxx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems soci still need to be here
@@ -20,9 +20,10 @@ | |||
|
|||
#include "ametsuchi/storage.hpp" | |||
|
|||
#include <soci/postgresql/soci-postgresql.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
sql_ << "SELECT height FROM height_by_hash WHERE hash = :hash", | ||
soci::into(block_str), soci::use(hash_str); | ||
if (block_str) { | ||
blockId = std::stoull(block_str.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fails. Height is stored as a string in postgres. Maybe it's better to store it as an integer?
+ transaction_.quote(command.assetId()) + ", " | ||
+ transaction_.quote(index) + ");"); | ||
status &= res != boost::none; | ||
soci::statement st = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, comma has lower priority
@@ -94,26 +106,31 @@ namespace iroha { | |||
block.transactions() | boost::adaptors::indexed(0), | |||
[&](const auto &tx) { | |||
const auto &creator_id = tx.value().creatorAccountId(); | |||
const auto &hash = tx.value().hash().blob(); | |||
const auto &hash = tx.value().hash().hex(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blob in postgres is designed for large files. I'm not sure that it is necessary here.
@@ -151,24 +163,24 @@ namespace iroha { | |||
|
|||
static inline shared_model::builder::BuilderResult< | |||
shared_model::interface::Peer> | |||
makePeer(const pqxx::row &row) noexcept { | |||
makePeer(const soci::row &row) noexcept { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It simplifies code in getPeers() in wsv query, but it is not possible to use soci::row everywhere here.
soci::into(size), soci::use(name); | ||
|
||
if (size == 0) { | ||
std::string query = "CREATE DATABASE "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason it does not work
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
const auto &str = | ||
shared_model::proto::permissions::toString(permissions); | ||
const auto perm_debug_str = | ||
std::accumulate(str.begin(), str.end(), std::string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be barely readable because it doesn't have spaces, e.g would look like "can_add_peercan_create_domaincan_create_user"
st.exchange(soci::use(empty_json)); | ||
st.exchange(soci::use(filled_json)); | ||
st.exchange(soci::use(value)); | ||
st.exchange(soci::use(std::string("{" + creator_account_id + "}"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
operator""s
might be handy, anyway for now is also ok
return result; | ||
*sql_ <<"SAVEPOINT savepoint_"; | ||
|
||
return apply_function(tx, *wsv_) | [this, &execute_command, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks unformatted for me
[&cmd_error]( | ||
expected::Error<validation::CommandError> | ||
&error) { | ||
cmd_error = error.error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use std::move
return false; | ||
}); | ||
*sql_ << "DROP TABLE IF EXISTS ordering_service_state"; | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
False case again
*sql_ << "DELETE FROM ordering_service_state"; | ||
*sql_ << "INSERT INTO ordering_service_state VALUES (:height)", | ||
soci::use(height); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
False case again
Signed-off-by: Victor Drobny <[email protected]>
@@ -17,22 +17,40 @@ | |||
|
|||
#include "ametsuchi/impl/postgres_ordering_service_persistent_state.hpp" | |||
|
|||
#include <soci/postgresql/soci-postgresql.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be below :(
std::accumulate(str.begin(), str.end(), std::string()); | ||
std::string perm_debug_str; | ||
std::for_each( | ||
str.begin(), str.end(), [&perm_debug_str](const auto &elem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use std::string perm_debug_str = std::acumulate(str.begin(), str.end(), std::string(), [](auto acc, const auto &elem) { return acc + " " + elem; });
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have failing test, please update the branch, maybe it will help
The following tests FAILED:
3 - module_wsv_query_command_test (Failed)
7 - module_kv_storage_test (Failed)
118 - integration_grant_permission_test (Failed)
126 - integration_set_account_detail_test (Failed)
Signed-off-by: Victor Drobny <[email protected]>
Signed-off-by: Victor Drobny <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Andrei Lebedev <[email protected]>
SonarQube analysis reported 7 issues
|
Pqxx replaced by SOCI. Some bugs are fixed by Andrei Signed-off-by: Victor Drobny <[email protected]>
Pqxx replaced by SOCI. Some bugs are fixed by Andrei Signed-off-by: Victor Drobny <[email protected]>
Pqxx replaced by SOCI. Some bugs are fixed by Andrei Signed-off-by: Victor Drobny <[email protected]>
Pqxx replaced by SOCI. Some bugs are fixed by Andrei Signed-off-by: Victor Drobny <[email protected]>
Pqxx replaced by SOCI. Some bugs are fixed by Andrei Signed-off-by: Victor Drobny <[email protected]>
Pqxx replaced by SOCI. Some bugs are fixed by Andrei Signed-off-by: victordrobny <[email protected]>
Description of the Change
SOCI instead of pqxx.