-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change ShardTracker interface (#4668)
* change ShardTracker interface * fix csv-to-json * fix merge * make shard tracker work when shard layout changes and add test for that * revert change on client config. Now this PR does not change config format * fix CI * comments and CI * Fix CI * address comments * fix AppendOnlyMap * add comments and fix fmt * move AppendOnlyMap to a separate file * create TrackedConfig
- Loading branch information
Showing
18 changed files
with
358 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::collections::HashMap; | ||
use std::hash::Hash; | ||
use std::sync::{Arc, RwLock}; | ||
|
||
const POISONED_LOCK_ERR: &str = "The lock was poisoned."; | ||
|
||
pub struct AppendOnlyMap<K, V> { | ||
map: RwLock<HashMap<K, Arc<V>>>, | ||
} | ||
|
||
impl<K, V> AppendOnlyMap<K, V> | ||
where | ||
K: Eq + Hash + Clone, | ||
{ | ||
pub fn new() -> Self { | ||
Self { map: RwLock::new(HashMap::new()) } | ||
} | ||
|
||
pub fn get_or_insert<F: FnOnce() -> V>(&self, key: &K, value: F) -> Arc<V> { | ||
let mut map = self.map.write().expect(POISONED_LOCK_ERR); | ||
if !map.contains_key(key) { | ||
map.insert(key.clone(), Arc::new(value())); | ||
} | ||
map.get(key).unwrap().clone() | ||
} | ||
} |
Oops, something went wrong.