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

WIP - Hypercore Clone & Sync - With spawn/channels #21

Merged
merged 27 commits into from
Jul 26, 2020
Merged

Conversation

bltavares
Copy link
Owner

@bltavares bltavares commented Jul 15, 2020

To compare the approach with #20, this PR rewrites the whole architecture to spawn background tasks and communicate data upstream using channels instead of build adapters around streams.

Closes #20

@bltavares bltavares marked this pull request as draft July 15, 2020 23:55
@bltavares bltavares mentioned this pull request Jul 16, 2020
5 tasks
@bltavares
Copy link
Owner Author

Clones a metadata and content feeds from a hypercore-daemon peer given a hash and ip:port

https://gist.github.com/bltavares/f37af663cb6f9fb4bd30ccabb1453a2a

@bltavares bltavares changed the title WIP - Hypercore Clone - With spawn/channels WIP - Hypercore Clone & Sync - With spawn/channels Jul 17, 2020
@bltavares
Copy link
Owner Author

bltavares commented Jul 19, 2020

This design has been validated to work with a daemon running replication in the background:

image

image

The relevant line is the colmeiad service, that starts a tide webserver and expose the hyperdrive feed block info over json, while the replication task runs in the background.

https://github.com/bltavares/colmeia/pull/21/files#diff-60f4d526c84e9c5bcfc049b851ba7891R69-R89

That is quite promising, and I think this is proving to be a better design that #20

Now we have to do some cleanup and try to find a better way to manage the internal state machine, which is the core of the replication logic, without having a 300-line long match.

I would also like to test if the service would be able to provide a single listener for all background tasks, so we could have multiple hyperdrives being served from a single hyperstack

Copy link
Owner Author

@bltavares bltavares left a comment

Choose a reason for hiding this comment

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

TODOs for next livestream

.expect("Could not start hyperdrive on the stack");
hyperstack.with_discovery(hyperstack.lan());

let job = task::spawn(hyperstack.replicate());
Copy link
Owner Author

Choose a reason for hiding this comment

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

We can now replicate the storage info in the background, while still holding a reference to the driver to use it on another task.

async fn main() -> Result<(), std::io::Error> {
env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init();

let key = name();
Copy link
Owner Author

Choose a reason for hiding this comment

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

Todo: use a better arguments parser with help messages


let content = match &driver.content {
Some(content) => {
let len = content.read().await.len();

This comment was marked as resolved.


async fn get_info<Storage>(req: Request<State<Storage>>) -> tide::Result<tide::Response>
where
Storage: random_access_storage::RandomAccess<Error = Box<dyn std::error::Error + Send + Sync>>
Copy link
Owner Author

Choose a reason for hiding this comment

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

TODO: Investigate datrs/hypercore#109 impact here - likely would be simpler to use a dyn Storage

.await;

match event {
HyperdriveEvents::Client(Ok(proto::Event::DiscoveryKey(message))) => {
Copy link
Owner Author

Choose a reason for hiding this comment

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

TODO: Can we write a simpler fn that is not 100s line long?

hyperdrive: Arc<RwLock<Hyperdrive<Storage>>>,
) where
C: AsyncRead + AsyncWrite + Send + Unpin + Clone + 'static,
Storage: random_access_storage::RandomAccess<Error = Box<dyn std::error::Error + Send + Sync>>
Copy link
Owner Author

Choose a reason for hiding this comment

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

let mut remote_length = 0;

while let Some(message) = channel.next().await {
match message {
Copy link
Owner Author

Choose a reason for hiding this comment

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

TODO: Can we have a fn that is not 100s line long?

mod schema;
mod utils;

pub use hyperdrive::*;

This comment was marked as resolved.

}
}
HyperdriveEvents::Client(Err(_)) => {
// TODO delete this branch

This comment was marked as resolved.

@bltavares bltavares marked this pull request as ready for review July 26, 2020 14:19
@bltavares bltavares merged commit d9f5a3a into master Jul 26, 2020
@bltavares bltavares deleted the use-spawn branch July 26, 2020 14:19
@bltavares bltavares mentioned this pull request Jul 26, 2020
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant