Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Rewrite StatusStream with rxcpp #1541

Merged
merged 8 commits into from
Jul 13, 2018
Merged

Conversation

lebdron
Copy link
Contributor

@lebdron lebdron commented Jul 5, 2018

Signed-off-by: Andrei Lebedev lebdron@gmail.com

Description of the Change

Rewrite StatusStream method without manual synchronization with condition variables and mutexes using rxcpp

Benefits

Separate status mapping and transport logic

Possible Drawbacks

Custom rxcpp timeout operator

Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
@lebdron lebdron requested review from muratovv and vdrobnyi July 5, 2018 14:20
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>

# Conflicts:
#	irohad/torii/impl/command_service.cpp
@l4l l4l added needs-review pr awaits review from maintainers refactoring internal stuff, that are changed/removed that doesn't affect client code labels Jul 6, 2018
@l4l l4l self-requested a review July 6, 2018 15:46
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
response_writer.Write(resp_sub);
}
rxcpp::observable<
std::shared_ptr<shared_model::interface::TransactionResponse>>
Copy link
Contributor

Choose a reason for hiding this comment

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

This type used multiple times, maybe create alias, e.g using Response = std::shared_ptr<shared_model::interface::TransactionResponse>;

: 2 * proposal_delay_;
},
current_thread))
.take_while([=](const auto &) { return not context->IsCancelled(); })
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be useful to add logging here as well

/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess there should be one more license

typedef typename coordination_type::coordinator_type coordinator_type;
typedef rxcpp::util::decay_t<Selector> select_type;
typedef decltype(
(*(select_type *)nullptr)(*(source_value_type *)nullptr)) value_type;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it used?
Also declval might be applicable

if (selectedWork.empty()) {
return;
}
localState->worker.schedule(selectedWork.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe invert if above and move this line up?

std::mutex notifier_mutex_;
rxcpp::subjects::subject<
std::shared_ptr<shared_model::interface::TransactionResponse>>
notifier_;
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is not so meaningful, maybe rename or add some documentation.

@@ -44,9 +46,15 @@ namespace torii {
proposal_delay_(proposal_delay),
start_tx_processing_duration_(1s),
cache_(std::make_shared<CacheType>()),
// merge with mutex, since notifications can be made from different
// threads
responses_(tx_processor_->transactionNotifier().merge(
Copy link
Contributor

Choose a reason for hiding this comment

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

Pls, add TODO about event bus rework.

return responses_.start_with(initial_status)
.filter(
[&](auto response) { return response->transactionHash() == hash; })
.lift<std::shared_ptr<shared_model::interface::TransactionResponse>>(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, better to add some comments about what happened here.

return response.tx_status()
== iroha::protocol::TxStatus::NOT_RECEIVED
? start_tx_processing_duration_
: 2 * proposal_delay_;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move out of here configuration logic?

.subscribe(
subscription,
[&](iroha::protocol::ToriiResponse response) {
log_->debug("writing status");
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the debug after Write method.

request_hash->hex());
// run loop while subscription is active or there are pending events in the
// queue
while (subscription.is_subscribed() or not rl.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

better to wrap this function with an inline method for the improving readability.

namespace torii {

/**
* Return an observable that terminates with timeout_error if a particular
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to write here about "This class is copypaste of ..." for reducing misleading usages of code as an example.


#include <rxcpp/operators/rx-timeout.hpp>

namespace torii {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move this file to lib for sharing usage?

@lebdron lebdron dismissed muratovv’s stale review July 11, 2018 17:06

Fixes are attempted

@lebdron lebdron requested a review from muratovv July 11, 2018 17:06
.take_while([=](const auto &) {
auto is_cancelled = context->IsCancelled();
if (is_cancelled) {
log_->debug("client unsubscribed");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe specify here some identify information about a client?

log_->debug("writing status");
response_writer->Write(response);
if (response_writer->Write(response)) {
log_->debug("status written");
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

@lebdron lebdron merged commit 9958bc9 into develop Jul 13, 2018
@lebdron lebdron deleted the refactor/torii-statusstream-rxcpp branch July 13, 2018 09:42
l4l pushed a commit that referenced this pull request Jul 25, 2018
* Rewrite StatusStream with rxcpp

* Minor fixes for types and logger calls

* Review fixes; fix irohad_test using wrong example path

* Fix tx hash setter in stateless valid case

* Add client id to debug log

Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
l4l pushed a commit that referenced this pull request Jul 25, 2018
* Rewrite StatusStream with rxcpp

* Minor fixes for types and logger calls

* Review fixes; fix irohad_test using wrong example path

* Fix tx hash setter in stateless valid case

* Add client id to debug log

Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
l4l pushed a commit that referenced this pull request Jul 25, 2018
* Rewrite StatusStream with rxcpp

* Minor fixes for types and logger calls

* Review fixes; fix irohad_test using wrong example path

* Fix tx hash setter in stateless valid case

* Add client id to debug log

Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
l4l pushed a commit that referenced this pull request Jul 25, 2018
* Rewrite StatusStream with rxcpp

* Minor fixes for types and logger calls

* Review fixes; fix irohad_test using wrong example path

* Fix tx hash setter in stateless valid case

* Add client id to debug log

Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
l4l pushed a commit that referenced this pull request Jul 25, 2018
* Rewrite StatusStream with rxcpp

* Minor fixes for types and logger calls

* Review fixes; fix irohad_test using wrong example path

* Fix tx hash setter in stateless valid case

* Add client id to debug log

Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-review pr awaits review from maintainers refactoring internal stuff, that are changed/removed that doesn't affect client code
Development

Successfully merging this pull request may close these issues.

None yet

3 participants