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

Support running in background #72

Merged
merged 1 commit into from
Feb 16, 2023
Merged

Support running in background #72

merged 1 commit into from
Feb 16, 2023

Conversation

monthonk
Copy link
Contributor

@monthonk monthonk commented Feb 7, 2023

This change allows the file connector to run in background and it will be running there by default. Users can change this behavior by passing in mount option --foreground or -f to run it in foreground instead.

I'm still figuring out how we can create some tests for this change. Any ideas are welcome. Another thing is that the logs are currently writing to the stdout directly even if the process is running in background. It's a bit annoying but I think that would be a part of PR that addresses #39.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@monthonk monthonk force-pushed the running_in_background branch from 3939a18 to 147d0bd Compare February 7, 2023 16:23
@dannycjones dannycjones self-requested a review February 8, 2023 18:04
@monthonk monthonk force-pushed the running_in_background branch 3 times, most recently from e308c2f to 9b7b556 Compare February 9, 2023 14:14
@monthonk
Copy link
Contributor Author

monthonk commented Feb 9, 2023

From this PR, I think AutoUnmount should be set as a default config, otherwise the mount state would be left hanging when we kill the background process.

@monthonk monthonk force-pushed the running_in_background branch 4 times, most recently from 707c137 to 56f2f9e Compare February 9, 2023 16:39
@monthonk
Copy link
Contributor Author

monthonk commented Feb 9, 2023

ASan is not happy with the tests. Any thoughts?

s3-file-connector/Cargo.toml Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/tests/common/mod.rs Outdated Show resolved Hide resolved
s3-file-connector/tests/cli.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/tests/cli.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/tests/cli.rs Outdated Show resolved Hide resolved
s3-file-connector/tests/cli.rs Outdated Show resolved Hide resolved
s3-file-connector/tests/cli.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
@monthonk monthonk force-pushed the running_in_background branch 11 times, most recently from 131cb22 to 9817ad8 Compare February 13, 2023 10:08
Makefile Outdated Show resolved Hide resolved
@monthonk monthonk force-pushed the running_in_background branch from 43703f5 to fdc740d Compare February 13, 2023 12:02
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
init_tracing_subscriber();

let (interrupt_tx, interrupt_rx) = crossbeam::channel::unbounded();
std::thread::spawn(move || await_interrupt(interrupt_tx));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a risk this happens too late? What if the mount completes in the child thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not likely to happen for success case due to network latency. Could be possible in some error cases that send the signal very soon. I'm not sure we should move this to before forking because I think the child process would copy the channel too. @jamesbornholt do you have any suggestions here?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeah, this is unlikely but we should do it properly. That means creating a pipe (pipe2) before the fork, writing a character into the write side of the pipe when the child wants to send its status (probably File::from_raw_fd), and reading a character off the read side of the pipe in the parent to check the status (same). Doing timeouts will be more annoying this way, since you can't configure a timeout for file/pipe reads. Might need to spawn a thread to do it.

s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
Comment on lines 155 to 162
match session {
Ok(_) => {
let _ = nix::sys::signal::kill(parent_pid, Signal::SIGCONT);
thread::park();

return Ok(());
Copy link
Member

Choose a reason for hiding this comment

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

This is kind of subtle and we should be more explicit -- the session stays running because its lifetime is bound to the match statement, so doesn't drop until after the park. Probably we should write Ok(_session) and put a comment above the park explaining this.

s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/tests/common/mod.rs Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
@monthonk monthonk force-pushed the running_in_background branch from fdc740d to 88d87ab Compare February 13, 2023 17:59
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
init_tracing_subscriber();

let (interrupt_tx, interrupt_rx) = crossbeam::channel::unbounded();
std::thread::spawn(move || await_interrupt(interrupt_tx));
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeah, this is unlikely but we should do it properly. That means creating a pipe (pipe2) before the fork, writing a character into the write side of the pipe when the child wants to send its status (probably File::from_raw_fd), and reading a character off the read side of the pipe in the parent to check the status (same). Doing timeouts will be more annoying this way, since you can't configure a timeout for file/pipe reads. Might need to spawn a thread to do it.

@monthonk monthonk force-pushed the running_in_background branch from 88d87ab to d6dc79c Compare February 14, 2023 10:04
Copy link
Contributor

@dannycjones dannycjones left a comment

Choose a reason for hiding this comment

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

I'm a little uneasy on some of the multi-process logic, not that I understand the area well at this point.

Also, I expect the logic to change anyway with the pipe change.

s3-file-connector/src/main.rs Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
@monthonk monthonk force-pushed the running_in_background branch 5 times, most recently from 00ac0ea to 67cedc7 Compare February 15, 2023 14:48
@monthonk monthonk force-pushed the running_in_background branch from 67cedc7 to 6e52bb5 Compare February 15, 2023 16:22
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
Comment on lines +177 to +182
// also `park()` does not guarantee to remain parked forever. so, we put it inside a loop.
loop {
thread::park();
}
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 we need some kind of stopping condition.

When we receive SIGINT, we should exit. Maybe another thread waits for SIGINT, and sets an atomic bool?

Does this sound right, @jamesbornholt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the standard library already handle that. I have tested this by running kill -2 {pid} which send SIGINT to the running child process and it works just fine.

Copy link
Member

Choose a reason for hiding this comment

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

We need to figure something different out here, otherwise the process runs forever even if the user unmounts it. But we can do that as a followup, I think, because we'll probably have to make fuser changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that is existing problem, it keep running forever even for foreground process. It's just less visible when run in the background. Let's do it as a follow up.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's open an issue and then we can resolve this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened #93.

s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
@monthonk monthonk force-pushed the running_in_background branch from 6e52bb5 to d465085 Compare February 15, 2023 18:19
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
Comment on lines +177 to +182
// also `park()` does not guarantee to remain parked forever. so, we put it inside a loop.
loop {
thread::park();
}
Copy link
Member

Choose a reason for hiding this comment

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

We need to figure something different out here, otherwise the process runs forever even if the user unmounts it. But we can do that as a followup, I think, because we'll probably have to make fuser changes.

s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
s3-file-connector/src/main.rs Outdated Show resolved Hide resolved
Comment on lines 198 to 199
// SAFETY: `read_fd` is a valid file descriptor.
let mut f = unsafe { File::from_raw_fd(read_fd) };
Copy link
Member

Choose a reason for hiding this comment

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

Maybe do this conversion outside the thread and right below closing the write_fd, to make clearer the fate of the pipe (and give f a better name)

This change allows the file connector to run in background and it will be running there by default.
Users can change this behavior by passing in mount option `--foreground` or `-f` to run it in foreground instead.

Signed-off-by: Monthon Klongklaew <[email protected]>
@monthonk monthonk force-pushed the running_in_background branch from d465085 to 17b1af2 Compare February 16, 2023 10:47
Copy link
Contributor

@dannycjones dannycjones left a comment

Choose a reason for hiding this comment

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

LGTM, pending new issue to follow up on failing to exit if unmounted.

@jamesbornholt jamesbornholt merged commit f6e936f into main Feb 16, 2023
@jamesbornholt jamesbornholt deleted the running_in_background branch February 16, 2023 15:42
@monthonk monthonk mentioned this pull request Feb 16, 2023
monthonk added a commit that referenced this pull request Feb 16, 2023
After #72, our file connector will be running in background by default.
This breaks the benchmark clean up process because we're now using the
wrong pid to kill the process after unmount.

Technically, running in background should not be a problem but because
of #93 we will have to use `--foreground` flag until we have it fixed.

Signed-off-by: Monthon Klongklaew <[email protected]>
monthonk added a commit that referenced this pull request Feb 16, 2023
* Fix benchmark script
After #72, our file connector will be running in background by default.
This breaks the benchmark clean up process because we're now using the
wrong pid to kill the process after unmount.

Technically, running in background should not be a problem but because
of #93 we will have to use `--foreground` flag until we have it fixed.

Signed-off-by: Monthon Klongklaew <[email protected]>

* Update file system name in bench script

Signed-off-by: Monthon Klongklaew <[email protected]>

---------

Signed-off-by: Monthon Klongklaew <[email protected]>
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.

3 participants