mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 12:57:20 +00:00
fix: do not set peer id with max (#491)
This commit is contained in:
parent
a93efd5f51
commit
b1e03d914e
3 changed files with 17 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
use std::error;
|
||||
|
||||
use serde_columnar::ColumnarError;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -90,6 +92,8 @@ pub enum LoroError {
|
|||
"The container {container} is deleted. You cannot apply the op on a deleted container."
|
||||
)]
|
||||
ContainerDeleted { container: Box<ContainerID> },
|
||||
#[error("You cannot set the `PeerID` with `PeerID::MAX`, which is an internal specific value")]
|
||||
InvalidPeerID,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug, PartialEq)]
|
||||
|
|
|
@ -261,6 +261,9 @@ impl LoroDoc {
|
|||
|
||||
#[inline(always)]
|
||||
pub fn set_peer_id(&self, peer: PeerID) -> LoroResult<()> {
|
||||
if peer == PeerID::MAX {
|
||||
return Err(LoroError::InvalidPeerID);
|
||||
}
|
||||
let next_id = self.oplog.try_lock().unwrap().next_id(peer);
|
||||
if self.auto_commit.load(Acquire) {
|
||||
let doc_state = self.state.try_lock().unwrap();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::{atomic::AtomicBool, Arc, Mutex};
|
||||
|
||||
use fxhash::FxHashMap;
|
||||
use loro_common::{ContainerID, ContainerType, LoroResult, LoroValue, ID};
|
||||
use loro_common::{ContainerID, ContainerType, LoroError, LoroResult, LoroValue, PeerID, ID};
|
||||
use loro_internal::{
|
||||
delta::ResolvedMapValue,
|
||||
event::{Diff, EventTriggerKind},
|
||||
|
@ -1262,3 +1262,12 @@ fn test_map_contains_key() {
|
|||
map.delete("bro").unwrap();
|
||||
assert!(!map.contains_key("bro"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_max_peer_id() {
|
||||
let doc = LoroDoc::new_auto_commit();
|
||||
assert_eq!(
|
||||
doc.set_peer_id(PeerID::MAX),
|
||||
Result::Err(LoroError::InvalidPeerID)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue