diff options
author | Alex Auvolat <alex@adnab.me> | 2022-12-13 14:23:45 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-12-13 14:23:45 +0100 |
commit | 687660b27f904422c689e09d2457293e5313d325 (patch) | |
tree | dd63404f4d49dc7c146d90e39f855c10db031417 /src/block/manager.rs | |
parent | 9d82196945f751c825621573657cfead992b356b (diff) | |
download | garage-687660b27f904422c689e09d2457293e5313d325.tar.gz garage-687660b27f904422c689e09d2457293e5313d325.zip |
Implement `block list-errors` and `block info`
Diffstat (limited to 'src/block/manager.rs')
-rw-r--r-- | src/block/manager.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/block/manager.rs b/src/block/manager.rs index 7f439b96..26e15bf5 100644 --- a/src/block/manager.rs +++ b/src/block/manager.rs @@ -90,6 +90,15 @@ pub struct BlockManager { tx_scrub_command: mpsc::Sender<ScrubWorkerCommand>, } +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct BlockResyncErrorInfo { + pub hash: Hash, + pub refcount: u64, + pub error_count: u64, + pub last_try: u64, + pub next_try: u64, +} + // This custom struct contains functions that must only be ran // when the lock is held. We ensure that it is the case by storing // it INSIDE a Mutex. @@ -314,6 +323,31 @@ impl BlockManager { let _ = self.tx_scrub_command.send(cmd).await; } + /// Get the reference count of a block + pub fn get_block_rc(&self, hash: &Hash) -> Result<u64, Error> { + Ok(self.rc.get_block_rc(hash)?.as_u64()) + } + + /// List all resync errors + pub fn list_resync_errors(&self) -> Result<Vec<BlockResyncErrorInfo>, Error> { + let mut blocks = Vec::with_capacity(self.resync.errors.len()); + for ent in self.resync.errors.iter()? { + let (hash, cnt) = ent?; + let cnt = ErrorCounter::decode(&cnt); + blocks.push(BlockResyncErrorInfo { + hash: Hash::try_from(&hash).unwrap(), + refcount: 0, + error_count: cnt.errors, + last_try: cnt.last_try, + next_try: cnt.next_try(), + }); + } + for block in blocks.iter_mut() { + block.refcount = self.get_block_rc(&block.hash)?; + } + Ok(blocks) + } + //// ----- Managing the reference counter ---- /// Increment the number of time a block is used, putting it to resynchronization if it is |