Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

results removal #270

Merged
merged 16 commits into from
Dec 15, 2023
Merged

results removal #270

merged 16 commits into from
Dec 15, 2023

Conversation

OrangeSmokingJacket
Copy link
Collaborator

@OrangeSmokingJacket OrangeSmokingJacket commented Nov 28, 2023

Functionality of components::result::result_t has been moved to components::cursor::cursor_t.
dispatcher_t and other associated structures now return and receive cursor_t_ptr, which can carry operation status(success or failure), error with description (if there was one) and changes to a collection

ctests and pytests are working properly

Copy link
Collaborator

@SergeiNA SergeiNA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more like cosmetic notes (except explicit for ctor). Also could you plz add describtion into your PR? Looks like we just moved from multiple result types to one cursor type.

components/cursor/cursor.hpp Outdated Show resolved Hide resolved
components/cursor/cursor.cpp Show resolved Hide resolved
components/cursor/cursor.cpp Show resolved Hide resolved
components/cursor/cursor.cpp Outdated Show resolved Hide resolved
components/cursor/cursor.cpp Outdated Show resolved Hide resolved
components/cursor/cursor.cpp Outdated Show resolved Hide resolved
@kotbegemot kotbegemot changed the title results removal WIP results removal Nov 29, 2023
components/cursor/cursor.hpp Outdated Show resolved Hide resolved
components/cursor/cursor.cpp Outdated Show resolved Hide resolved
@SergeiNA
Copy link
Collaborator

SergeiNA commented Dec 4, 2023

Looks fine to me, but wait @kotbegemot approve plz.

@@ -124,7 +124,7 @@ namespace services {
bool memory_storage_t::check_database_(components::session::session_id_t& session, const database_name_t& name) {
if (!is_exists_database_(name)) {
actor_zeta::send(current_message()->sender(), this->address(), handler_id(route::execute_plan_finish), session,
make_error(error_code_t::database_not_exists, "database not exists"));
make_error(actor_zeta::detail::pmr::get_default_resource(), error_code_t::database_not_exists, "database not exists"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we can use namespace alias here? @kotbegemot WDYT?
namespace az_res = actor_zeta::detail::pmr

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this actor_zeta::detail::pmr::get_default_resource() @kotbegemot why don't just wrap this function and place in in some memory utils?

For example in core::pmr?

std::pmr::memory_resource* default_resource(){
   return actor_zeta::detail::pmr::get_default_resource();
}

and usage:

make_error(core::pmr::get_default_resource(), error_code_t::database_not_exists, "database not exists"));

I don't like an idea of usage function from detail namespace of other library. Usually this namespace means "for internal usage".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though, I thinl it'll better to create aliase fot this, if we want in a future chanege it to something else it will be much easier to do in one place.

@@ -211,7 +210,7 @@ namespace services::dispatcher {
}

if (ql->type() == statement_type::create_collection) {
collection_address_book_.emplace(collection_full_name_t(ql->database_, ql->collection_), result.get<result_address_t>().address);
collection_address_book_.emplace(collection_full_name_t(ql->database_, ql->collection_), result->begin()->get()->address());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result->begin()->get()->address() @kotbegemot is it expected? I mean result->begin() looks quite strange to me and not logical at first glance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to cover in some method and just call
result->get_address();

@SergeiNA
Copy link
Collaborator

SergeiNA commented Dec 4, 2023

@OrangeSmokingJacket @kotbegemot What is selection logic to use
make_error();
or
make_cursor(..., operation_status_t::failure));
On what stage we start to use make_cursor(..., operation_status_t::failure));?

remove_session(session_to_address_, session);
}
actor_zeta::send(s.address(), dispatcher_t::address(), handler_id(route::execute_ql_finish), session, result);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OrangeSmokingJacket please pay attention while rebase on the latest commit with inserts. This operation should be valid only for non mutable or from wal operations.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -124,7 +124,7 @@ namespace services {
bool memory_storage_t::check_database_(components::session::session_id_t& session, const database_name_t& name) {
if (!is_exists_database_(name)) {
actor_zeta::send(current_message()->sender(), this->address(), handler_id(route::execute_plan_finish), session,
make_error(error_code_t::database_not_exists, "database not exists"));
make_error(actor_zeta::detail::pmr::get_default_resource(), error_code_t::database_not_exists, "database not exists"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this actor_zeta::detail::pmr::get_default_resource() @kotbegemot why don't just wrap this function and place in in some memory utils?

For example in core::pmr?

std::pmr::memory_resource* default_resource(){
   return actor_zeta::detail::pmr::get_default_resource();
}

and usage:

make_error(core::pmr::get_default_resource(), error_code_t::database_not_exists, "database not exists"));

I don't like an idea of usage function from detail namespace of other library. Usually this namespace means "for internal usage".

@@ -211,7 +210,7 @@ namespace services::dispatcher {
}

if (ql->type() == statement_type::create_collection) {
collection_address_book_.emplace(collection_full_name_t(ql->database_, ql->collection_), result.get<result_address_t>().address);
collection_address_book_.emplace(collection_full_name_t(ql->database_, ql->collection_), result->begin()->get()->address());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to cover in some method and just call
result->get_address();

@@ -263,11 +262,12 @@ namespace services::dispatcher {
auto logic_plan = create_logic_plan(statement).first;
actor_zeta::send(it_collection->second, dispatcher_t::address(), collection::handler_id(collection::route::insert_documents), session, logic_plan, components::ql::storage_parameters{});
} else {
actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::insert_finish), session, result_insert(resource_));
actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::insert_finish), session,
make_from_sub_cursor(actor_zeta::detail::pmr::get_default_resource(), new sub_cursor_t(resource_, address)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code hard to read, looks like 2 lines, lets create cursor before send and move it:

auto cursor = make_from_sub_cursor(actor_zeta::detail::pmr::get_default_resource(), new sub_cursor_t(resource_, address));
actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::insert_finish), session, std::move(cursor));

and you can do this for all similar cases.
@kotbegemot What is your opinion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dispatcher does not create cursors; the logic needs to be changed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kotbegemot you mean this line is not correct?

actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::insert_finish), session,
                             make_from_sub_cursor(actor_zeta::detail::pmr::get_default_resource(), new sub_cursor_t(resource_, address)));

@@ -298,11 +298,12 @@ namespace services::dispatcher {
auto logic_plan = create_logic_plan(statement);
actor_zeta::send(it_collection->second, dispatcher_t::address(), collection::handler_id(collection::route::delete_documents), session, std::move(logic_plan.first), std::move(logic_plan.second));
} else {
actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::delete_finish), session, result_delete(resource_));
actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::delete_finish), session,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split

@@ -333,11 +334,12 @@ namespace services::dispatcher {
auto logic_plan = create_logic_plan(statement);
actor_zeta::send(it_collection->second, dispatcher_t::address(), collection::handler_id(collection::route::update_documents), session, std::move(logic_plan.first), std::move(logic_plan.second));
} else {
actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::update_finish), session, result_update(resource_));
actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::update_finish), session,
make_from_sub_cursor(actor_zeta::detail::pmr::get_default_resource(), new sub_cursor_t(resource_, address)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split

@@ -263,11 +262,12 @@ namespace services::dispatcher {
auto logic_plan = create_logic_plan(statement).first;
actor_zeta::send(it_collection->second, dispatcher_t::address(), collection::handler_id(collection::route::insert_documents), session, logic_plan, components::ql::storage_parameters{});
} else {
actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::insert_finish), session, result_insert(resource_));
actor_zeta::send(address, dispatcher_t::address(), collection::handler_id(collection::route::insert_finish), session,
make_from_sub_cursor(actor_zeta::detail::pmr::get_default_resource(), new sub_cursor_t(resource_, address)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note, no need to fix. @kotbegemot are you ok with new here? if it throw exception, actor_zeta::detail::pmr::get_default_resource() will be released?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dispatcher does not create cursors; the logic needs to be changed.
for now please use
https://en.cppreference.com/w/cpp/memory/get_default_resource

Copy link
Collaborator

@SergeiNA SergeiNA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general looks fine, well done!
I have only one question about default resource, why in memory_manegment we use std::prm but in collections actor_zeta::prm::detail

if (ql->type() == statement_type::create_collection) {
trace(log_, "dispatcher_t::execute_ql_finish: create_collection");
collection_address_book_.emplace(collection_full_name_t(ql->database_, ql->collection_), result.get<result_address_t>().address);
collection_address_book_.emplace(collection_full_name_t(ql->database_, ql->collection_), last_collection_.at(session));
last_collection_.erase(session);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OrangeSmokingJacket Can you give some comments why we need this?


namespace services {

using namespace services::memory_storage;

std::pmr::memory_resource* default_resource(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad but I recommend to place it in core directory and use it everywhere instead of std::pmr::get_default_resource()


cursor_t_ptr make_cursor(std::pmr::memory_resource* resource, operation_status_t op_status);
cursor_t_ptr make_cursor(std::pmr::memory_resource* resource);
cursor_t_ptr make_cursor(std::pmr::memory_resource* resource, error_code_t type, const std::string& what = std::string());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OrangeSmokingJacket @kotbegemot this function designed only for error cursor, so might be we can rename it into
make_error_cursor
or
make_error
in this case much easier to read code when we return an error.

@@ -44,7 +44,8 @@ namespace services::collection {
void collection_t::create_index(const session_id_t& session, create_index_t& index) {
debug(log(), "collection::create_index : {} {} {}", name_.to_string(), name_index_type(index.index_type_), keys_index(index.keys_)); //todo: maybe delete
if (dropped_) {
actor_zeta::send(current_message()->sender(), address(), handler_id(route::create_index_finish), session, result_create_index(false));
actor_zeta::send(current_message()->sender(), address(), handler_id(route::create_index_finish), session,
make_cursor(actor_zeta::detail::pmr::get_default_resource(), error_code_t::collection_dropped));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OrangeSmokingJacket @kotbegemot sorry I don't get, for actors we use actor_zeta::detail::pmr::get_default_resource() in make_cursor ? Not std::prm::get_default_resource() ?

@@ -132,7 +136,7 @@ namespace services {
if (check_database_(session, name.database)) {
if (!is_exists_collection_(name)) {
actor_zeta::send(current_message()->sender(), this->address(), handler_id(route::execute_plan_finish), session,
make_error(error_code_t::collection_not_exists, "collection not exists"));
make_cursor(default_resource(), error_code_t::collection_not_exists, "collection not exists"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In collection we still use default_resource() from actor_zeta, why?

actor_zeta::send(dispatcher, address(), handler_id(route::size_finish), session,
make_cursor(context_->resource(), error_code_t::collection_dropped));
} else {
auto* sub_cursor = new sub_cursor_t(context_->resource(), address());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kotbegemot This place(how we add docs into cursor) looks like can be improvement in the future. For now we can leave it as it is.

REQUIRE(cursor->is_success());
REQUIRE(!cursor->is_error());
}
INFO("error cursor") {
std::string description = "error description";
auto cursor = components::cursor::make_cursor(actor_zeta::detail::pmr::get_default_resource(), components::cursor::error_code_t::other_error, description);
auto cursor = components::cursor::make_cursor(std::pmr::get_default_resource(), components::cursor::error_code_t::other_error, description);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use default_resource() function

@SergeiNA SergeiNA self-requested a review December 15, 2023 19:07
@kotbegemot kotbegemot merged commit 10f54ab into duckstax:develop Dec 15, 2023
16 checks passed
@kotbegemot kotbegemot added enhancement New feature or request refactoring labels Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactoring: Substitute result_t/insert/delete/e.t.c with cursor_t
3 participants