Skip to content

Commit

Permalink
fix(storage): fix race condition between pin version and new shared-b…
Browse files Browse the repository at this point in the history
…uffer (#3651)

* fix

Signed-off-by: Little-Wallace <[email protected]>

* fix warn

Signed-off-by: Little-Wallace <[email protected]>
  • Loading branch information
Little-Wallace authored Jul 5, 2022
1 parent 0efa4dd commit 480010f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/storage/src/hummock/local_version_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::time::Duration;
use bytes::Bytes;
use futures::future::{join_all, try_join_all};
use itertools::Itertools;
use parking_lot::{RwLock, RwLockWriteGuard};
use parking_lot::{RwLock, RwLockUpgradableReadGuard, RwLockWriteGuard};
use risingwave_common::config::StorageConfig;
use risingwave_hummock_sdk::key::FullKey;
use risingwave_hummock_sdk::{CompactionGroupId, LocalSstableInfo};
Expand Down Expand Up @@ -221,7 +221,7 @@ impl LocalVersionManager {
}
}

let old_version = self.local_version.read().clone();
let old_version = self.local_version.upgradable_read();
if old_version.pinned_version().id() >= new_version_id {
return false;
}
Expand All @@ -230,10 +230,10 @@ impl LocalVersionManager {
conflict_detector.set_watermark(newly_pinned_version.max_committed_epoch);
}

let mut new_version = old_version;
let mut new_version = old_version.clone();
new_version.set_pinned_version(newly_pinned_version);
{
let mut guard = self.local_version.write();
let mut guard = RwLockUpgradableReadGuard::upgrade(old_version);
*guard = new_version;
RwLockWriteGuard::unlock_fair(guard);
}
Expand Down

0 comments on commit 480010f

Please sign in to comment.