|
8 | 8 | // the Business Source License, use of this software will be governed |
9 | 9 | // by the Apache License, Version 2.0. |
10 | 10 |
|
11 | | -use std::sync::Arc; |
12 | | - |
13 | 11 | use futures::FutureExt; |
14 | 12 | use pin_project::pin_project; |
15 | 13 | use restate_types::logs::Record; |
16 | | -use tokio::sync::{Notify, mpsc, oneshot}; |
| 14 | +use tokio::sync::{mpsc, oneshot}; |
17 | 15 | use tracing::{trace, warn}; |
18 | 16 |
|
19 | 17 | use restate_core::{ShutdownError, TaskCenter, TaskHandle, cancellation_watcher}; |
@@ -130,8 +128,8 @@ where |
130 | 128 | batch.push(record); |
131 | 129 | notif_buffer.push(tx); |
132 | 130 | } |
133 | | - AppendOperation::Canary(notify) => { |
134 | | - notify.notify_one(); |
| 131 | + AppendOperation::Canary(tx) => { |
| 132 | + notif_buffer.push(tx); |
135 | 133 | } |
136 | 134 | AppendOperation::MarkAsPreferred => { |
137 | 135 | appender.mark_as_preferred(); |
@@ -357,19 +355,18 @@ impl<T: StorageEncode> LogSender<T> { |
357 | 355 | /// |
358 | 356 | /// Not cancellation safe. Every call will attempt to acquire capacity on the channel and send |
359 | 357 | /// a new message to the appender. |
360 | | - pub async fn notify_committed(&self) -> Result<(), EnqueueError<()>> { |
| 358 | + pub async fn notify_committed(&self) -> Result<CommitToken, EnqueueError<()>> { |
361 | 359 | let Ok(permit) = self.tx.reserve().await else { |
362 | 360 | // channel is closed, this should happen the appender is draining or has been darained |
363 | 361 | // already |
364 | 362 | return Err(EnqueueError::Closed(())); |
365 | 363 | }; |
366 | 364 |
|
367 | | - let notify = Arc::new(Notify::new()); |
368 | | - let canary = AppendOperation::Canary(notify.clone()); |
| 365 | + let (tx, rx) = oneshot::channel(); |
| 366 | + let canary = AppendOperation::Canary(tx); |
369 | 367 | permit.send(canary); |
370 | 368 |
|
371 | | - notify.notified().await; |
372 | | - Ok(()) |
| 369 | + Ok(CommitToken { rx }) |
373 | 370 | } |
374 | 371 |
|
375 | 372 | /// Marks this node as a preferred writer for the underlying log |
@@ -422,7 +419,7 @@ enum AppendOperation { |
422 | 419 | EnqueueWithNotification(Record, oneshot::Sender<()>), |
423 | 420 | // A message denoting a request to be notified when it's processed by the appender. |
424 | 421 | // It's used to check if previously enqueued appends have been committed or not |
425 | | - Canary(Arc<Notify>), |
| 422 | + Canary(oneshot::Sender<()>), |
426 | 423 | /// Let's bifrost know that this node is the preferred writer of this log |
427 | 424 | MarkAsPreferred, |
428 | 425 | /// Let's bifrost know that this node might not be the preferred writer of this log |
|
0 commit comments