feat: Upload collab limit (#160)
* chore: add logs * feat: update upload collab limit
This commit is contained in:
parent
c7e90eb24b
commit
04989e9485
|
|
@ -6,7 +6,7 @@ use std::sync::{Arc, Weak};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::collab_sync::pending_msg::{MessageState, PendingMsgQueue};
|
use crate::collab_sync::pending_msg::{MessageState, PendingMsgQueue};
|
||||||
use crate::collab_sync::{SyncError, DEFAULT_SYNC_TIMEOUT};
|
use crate::collab_sync::{SyncError, SyncObject, DEFAULT_SYNC_TIMEOUT};
|
||||||
use futures_util::SinkExt;
|
use futures_util::SinkExt;
|
||||||
|
|
||||||
use realtime_entity::collab_msg::{CollabSinkMessage, MsgId};
|
use realtime_entity::collab_msg::{CollabSinkMessage, MsgId};
|
||||||
|
|
@ -41,7 +41,7 @@ pub struct CollabSink<Sink, Msg> {
|
||||||
/// The [PendingMsgQueue] is used to queue the messages that are waiting to be sent to the
|
/// The [PendingMsgQueue] is used to queue the messages that are waiting to be sent to the
|
||||||
/// remote. It will merge the messages if possible.
|
/// remote. It will merge the messages if possible.
|
||||||
pending_msg_queue: Arc<parking_lot::Mutex<PendingMsgQueue<Msg>>>,
|
pending_msg_queue: Arc<parking_lot::Mutex<PendingMsgQueue<Msg>>>,
|
||||||
msg_id_counter: Arc<dyn MsgIdCounter>,
|
msg_id_counter: Arc<DefaultMsgIdCounter>,
|
||||||
|
|
||||||
/// The [watch::Sender] is used to notify the [CollabSinkRunner] to process the pending messages.
|
/// The [watch::Sender] is used to notify the [CollabSinkRunner] to process the pending messages.
|
||||||
/// Sending `false` will stop the [CollabSinkRunner].
|
/// Sending `false` will stop the [CollabSinkRunner].
|
||||||
|
|
@ -49,7 +49,6 @@ pub struct CollabSink<Sink, Msg> {
|
||||||
config: SinkConfig,
|
config: SinkConfig,
|
||||||
|
|
||||||
/// Stop the [IntervalRunner] if the sink strategy is [SinkStrategy::FixInterval].
|
/// Stop the [IntervalRunner] if the sink strategy is [SinkStrategy::FixInterval].
|
||||||
#[allow(dead_code)]
|
|
||||||
interval_runner_stop_tx: Option<mpsc::Sender<()>>,
|
interval_runner_stop_tx: Option<mpsc::Sender<()>>,
|
||||||
|
|
||||||
/// Used to calculate the time interval between two messages. Only used when the sink strategy
|
/// Used to calculate the time interval between two messages. Only used when the sink strategy
|
||||||
|
|
@ -57,10 +56,17 @@ pub struct CollabSink<Sink, Msg> {
|
||||||
instant: Mutex<Instant>,
|
instant: Mutex<Instant>,
|
||||||
state_notifier: Arc<watch::Sender<SinkState>>,
|
state_notifier: Arc<watch::Sender<SinkState>>,
|
||||||
pause: AtomicBool,
|
pause: AtomicBool,
|
||||||
|
object: SyncObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Sink, Msg> Drop for CollabSink<Sink, Msg> {
|
impl<Sink, Msg> Drop for CollabSink<Sink, Msg> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
trace!("Drop CollabSink {}", self.object.object_id);
|
||||||
|
if let Some(stop_tx) = self.interval_runner_stop_tx.take() {
|
||||||
|
spawn(async move {
|
||||||
|
let _ = stop_tx.send(()).await;
|
||||||
|
});
|
||||||
|
}
|
||||||
let _ = self.notifier.send(true);
|
let _ = self.notifier.send(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -71,18 +77,16 @@ where
|
||||||
Sink: SinkExt<Msg, Error = E> + Send + Sync + Unpin + 'static,
|
Sink: SinkExt<Msg, Error = E> + Send + Sync + Unpin + 'static,
|
||||||
Msg: CollabSinkMessage,
|
Msg: CollabSinkMessage,
|
||||||
{
|
{
|
||||||
pub fn new<C>(
|
pub fn new(
|
||||||
uid: i64,
|
uid: i64,
|
||||||
|
object: SyncObject,
|
||||||
sink: Sink,
|
sink: Sink,
|
||||||
notifier: watch::Sender<bool>,
|
notifier: watch::Sender<bool>,
|
||||||
sync_state_tx: watch::Sender<SinkState>,
|
sync_state_tx: watch::Sender<SinkState>,
|
||||||
msg_id_counter: C,
|
|
||||||
config: SinkConfig,
|
config: SinkConfig,
|
||||||
pause: bool,
|
pause: bool,
|
||||||
) -> Self
|
) -> Self {
|
||||||
where
|
let msg_id_counter = DefaultMsgIdCounter::new();
|
||||||
C: MsgIdCounter,
|
|
||||||
{
|
|
||||||
let notifier = Arc::new(notifier);
|
let notifier = Arc::new(notifier);
|
||||||
let state_notifier = Arc::new(sync_state_tx);
|
let state_notifier = Arc::new(sync_state_tx);
|
||||||
let sender = Arc::new(Mutex::new(sink));
|
let sender = Arc::new(Mutex::new(sink));
|
||||||
|
|
@ -109,6 +113,7 @@ where
|
||||||
instant,
|
instant,
|
||||||
interval_runner_stop_tx,
|
interval_runner_stop_tx,
|
||||||
pause: AtomicBool::new(pause),
|
pause: AtomicBool::new(pause),
|
||||||
|
object,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -312,7 +317,7 @@ where
|
||||||
|
|
||||||
match self.sender.try_lock() {
|
match self.sender.try_lock() {
|
||||||
Ok(mut sender) => {
|
Ok(mut sender) => {
|
||||||
debug!("ending {}", collab_msg);
|
debug!("Sending {}", collab_msg);
|
||||||
sender.send(collab_msg).await.ok()?;
|
sender.send(collab_msg).await.ok()?;
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
@ -362,12 +367,6 @@ where
|
||||||
pub(crate) fn notify(&self) {
|
pub(crate) fn notify(&self) {
|
||||||
let _ = self.notifier.send(false);
|
let _ = self.notifier.send(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stop the sink.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn stop(&self) {
|
|
||||||
let _ = self.notifier.send(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retry_later(weak_notifier: Weak<watch::Sender<bool>>) {
|
fn retry_later(weak_notifier: Weak<watch::Sender<bool>>) {
|
||||||
|
|
@ -491,9 +490,6 @@ impl DefaultMsgIdCounter {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl MsgIdCounter for DefaultMsgIdCounter {
|
|
||||||
fn next(&self) -> MsgId {
|
fn next(&self) -> MsgId {
|
||||||
self.0.fetch_add(1, Ordering::SeqCst)
|
self.0.fetch_add(1, Ordering::SeqCst)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::collab_sync::{
|
use crate::collab_sync::{
|
||||||
CollabSink, CollabSinkRunner, DefaultMsgIdCounter, SinkConfig, SinkState, SyncError, SyncObject,
|
CollabSink, CollabSinkRunner, SinkConfig, SinkState, SyncError, SyncObject,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use collab::core::collab::MutexCollab;
|
use collab::core::collab::MutexCollab;
|
||||||
|
|
@ -67,10 +67,10 @@ where
|
||||||
|
|
||||||
let sink = Arc::new(CollabSink::new(
|
let sink = Arc::new(CollabSink::new(
|
||||||
origin.client_user_id().unwrap_or(0),
|
origin.client_user_id().unwrap_or(0),
|
||||||
|
object.clone(),
|
||||||
sink,
|
sink,
|
||||||
notifier,
|
notifier,
|
||||||
sync_state_tx,
|
sync_state_tx,
|
||||||
DefaultMsgIdCounter::new(),
|
|
||||||
config,
|
config,
|
||||||
pause,
|
pause,
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ pub fn workspace_scope() -> Scope {
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("{workspace_id}/collab/{object_id}")
|
web::resource("{workspace_id}/collab/{object_id}")
|
||||||
|
.app_data(
|
||||||
|
PayloadConfig::new(5 * 1024 * 1024), // 10 MB
|
||||||
|
)
|
||||||
.route(web::post().to(create_collab_handler))
|
.route(web::post().to(create_collab_handler))
|
||||||
.route(web::get().to(get_collab_handler))
|
.route(web::get().to(get_collab_handler))
|
||||||
.route(web::put().to(update_collab_handler))
|
.route(web::put().to(update_collab_handler))
|
||||||
|
|
@ -68,7 +71,7 @@ pub fn collab_scope() -> Scope {
|
||||||
web::scope("/api/realtime").service(
|
web::scope("/api/realtime").service(
|
||||||
web::resource("post")
|
web::resource("post")
|
||||||
.app_data(
|
.app_data(
|
||||||
PayloadConfig::new(10 * 1024 * 1024), // 10 MB
|
PayloadConfig::new(5 * 1024 * 1024), // 10 MB
|
||||||
)
|
)
|
||||||
.route(web::post().to(post_realtime_message_handler)),
|
.route(web::post().to(post_realtime_message_handler)),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue