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

pageserver: make BufferedWriter do double-buffering #9693

Merged
merged 40 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dd1c45e
eliminate size_tracking_writer
yliang412 Nov 7, 2024
224cbb4
change OwnedAsyncWriter trait to use write_all_at
yliang412 Nov 8, 2024
f0efc90
use Arc around W: OwnedAsyncWriter
yliang412 Nov 8, 2024
26c8b50
implement non-generic flush handle & bg task
yliang412 Nov 9, 2024
4599804
make flush handle & task generic
yliang412 Nov 10, 2024
bdffc35
use background flush for write path; read path broken
yliang412 Nov 10, 2024
e0848c2
make InMemory read aware of mutable & maybe_flushed
yliang412 Nov 11, 2024
e5bb85d
fix clippy
yliang412 Nov 11, 2024
7b34e73
fix tests
yliang412 Nov 11, 2024
b0d7fc7
fix IoBufferMut::extend_from_slice
yliang412 Nov 11, 2024
ce7cd36
add IoBufAligned marker
yliang412 Nov 12, 2024
20e6a0c
use open_with_options_v2 (O_DIRECT) for ephemeral file
yliang412 Nov 12, 2024
d6d8a16
Merge branch 'main' into yuchen/double-buffered-writer
yliang412 Nov 12, 2024
ffd88ed
fix clippy
yliang412 Nov 12, 2024
6844b5f
add comments; make read buffering works with write_buffered (owned ve…
yliang412 Nov 12, 2024
990bc65
review: https://github.com/neondatabase/neon/pull/9693#discussion_r18…
yliang412 Nov 15, 2024
5acc61b
move duplex to utils; make flush behavior controllable in test
yliang412 Nov 18, 2024
9db6b1e
fix clippy
yliang412 Nov 19, 2024
826e239
add comments
yliang412 Nov 19, 2024
78a17a7
improve FullSlice semantics
yliang412 Nov 19, 2024
77801fe
Merge branch 'main' into yuchen/double-buffered-writer
yliang412 Nov 19, 2024
0f63c95
document and reorder flush background task invokation sequence
yliang412 Nov 20, 2024
54d253d
review: change IoMode default back to Buffered
yliang412 Nov 25, 2024
e5bf2be
remove write_buffered; add notes for bypass-aligned-part-of-write
yliang412 Nov 25, 2024
28718bf
review: simplify FlushControl by using ZST for not(test)
yliang412 Nov 25, 2024
76f0e4f
review: remove save_buf_for_read
yliang412 Nov 25, 2024
d4ebd5c
use CheapCloneForRead trait to prevent efficiency bugs
yliang412 Nov 25, 2024
8a37f41
remove resolved todos
yliang412 Nov 25, 2024
4284fcd
fix docs clippy
yliang412 Nov 25, 2024
c3302ad
Merge branch 'main' into yuchen/double-buffered-writer
yliang412 Nov 25, 2024
b54764b
hold timeline open in background task using gate guard (#9825)
yliang412 Nov 27, 2024
b6a2516
Merge branch 'main' into yuchen/double-buffered-writer
yliang412 Nov 27, 2024
9f384a8
review: remove unused impl Buffer for BytesMut
yliang412 Dec 2, 2024
bf9a6d0
review: follow Buffer::extend_from_slice trait definition
yliang412 Dec 2, 2024
fac4269
review: fix CheapCloneForRead for FullSlice
yliang412 Dec 2, 2024
a439d57
review: cleanup comments + expect_err
yliang412 Dec 2, 2024
6a1aa52
review: move FlushHandle::handle_error right after ::flush
yliang412 Dec 2, 2024
21ca0c4
review: set channel buffer size to 1
yliang412 Dec 2, 2024
9d1821a
Merge branch 'main' into yuchen/double-buffered-writer
yliang412 Dec 2, 2024
1da4028
fix clippy
yliang412 Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/utils/src/sync.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod heavier_once_cell;

pub mod duplex;
pub mod gate;
1 change: 1 addition & 0 deletions libs/utils/src/sync/duplex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod mpsc;
36 changes: 36 additions & 0 deletions libs/utils/src/sync/duplex/mpsc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use tokio::sync::mpsc;

/// A bi-directional channel.
pub struct Duplex<S, R> {
pub tx: mpsc::Sender<S>,
pub rx: mpsc::Receiver<R>,
}

/// Creates a bi-directional channel.
///
/// The channel will buffer up to the provided number of messages. Once the buffer is full,
/// attempts to send new messages will wait until a message is received from the channel.
/// The provided buffer capacity must be at least 1.
pub fn channel<A: Send, B: Send>(buffer: usize) -> (Duplex<A, B>, Duplex<B, A>) {
let (tx_a, rx_a) = mpsc::channel::<A>(buffer);
let (tx_b, rx_b) = mpsc::channel::<B>(buffer);

(Duplex { tx: tx_a, rx: rx_b }, Duplex { tx: tx_b, rx: rx_a })
}

impl<S: Send, R: Send> Duplex<S, R> {
/// Sends a value, waiting until there is capacity.
///
/// A successful send occurs when it is determined that the other end of the channel has not hung up already.
pub async fn send(&self, x: S) -> Result<(), mpsc::error::SendError<S>> {
self.tx.send(x).await
}

/// Receives the next value for this receiver.
///
/// This method returns `None` if the channel has been closed and there are
/// no remaining messages in the channel's buffer.
pub async fn recv(&mut self) -> Option<R> {
self.rx.recv().await
}
}
4 changes: 1 addition & 3 deletions pageserver/benches/bench_ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ async fn ingest(
let ctx = RequestContext::new(TaskKind::DebugTool, DownloadBehavior::Error);

let gate = utils::sync::gate::Gate::default();
let entered = gate.enter().unwrap();

let layer =
InMemoryLayer::create(conf, timeline_id, tenant_shard_id, lsn, entered, &ctx).await?;
let layer = InMemoryLayer::create(conf, timeline_id, tenant_shard_id, lsn, &gate, &ctx).await?;

let data = Value::Image(Bytes::from(vec![0u8; put_size]));
let data_ser_size = data.serialized_size().unwrap() as usize;
Expand Down
Loading
Loading