block manager: refactor and fix monitoring/statistics
This commit is contained in:
parent
f38a31b330
commit
99ed18350f
@ -491,8 +491,6 @@ impl BlockManager {
|
|||||||
pub(crate) async fn write_block(&self, hash: &Hash, data: &DataBlock) -> Result<(), Error> {
|
pub(crate) async fn write_block(&self, hash: &Hash, data: &DataBlock) -> Result<(), Error> {
|
||||||
let tracer = opentelemetry::global::tracer("garage");
|
let tracer = opentelemetry::global::tracer("garage");
|
||||||
|
|
||||||
let write_size = data.inner_buffer().len() as u64;
|
|
||||||
|
|
||||||
self.lock_mutate(hash)
|
self.lock_mutate(hash)
|
||||||
.await
|
.await
|
||||||
.write_block(hash, data, self)
|
.write_block(hash, data, self)
|
||||||
@ -502,8 +500,6 @@ impl BlockManager {
|
|||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.metrics.bytes_written.add(write_size);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,19 +526,8 @@ impl BlockManager {
|
|||||||
|
|
||||||
/// Read block from disk, verifying it's integrity
|
/// Read block from disk, verifying it's integrity
|
||||||
pub(crate) async fn read_block(&self, hash: &Hash) -> Result<DataBlock, Error> {
|
pub(crate) async fn read_block(&self, hash: &Hash) -> Result<DataBlock, Error> {
|
||||||
let data = self
|
let tracer = opentelemetry::global::tracer("garage");
|
||||||
.read_block_internal(hash)
|
async {
|
||||||
.bound_record_duration(&self.metrics.block_read_duration)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
self.metrics
|
|
||||||
.bytes_read
|
|
||||||
.add(data.inner_buffer().len() as u64);
|
|
||||||
|
|
||||||
Ok(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read_block_internal(&self, hash: &Hash) -> Result<DataBlock, Error> {
|
|
||||||
match self.find_block(hash).await {
|
match self.find_block(hash).await {
|
||||||
Some(p) => self.read_block_from(hash, &p).await,
|
Some(p) => self.read_block_from(hash, &p).await,
|
||||||
None => {
|
None => {
|
||||||
@ -556,6 +541,12 @@ impl BlockManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.bound_record_duration(&self.metrics.block_read_duration)
|
||||||
|
.with_context(Context::current_with_span(
|
||||||
|
tracer.start("BlockManager::read_block"),
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn read_block_from(
|
pub(crate) async fn read_block_from(
|
||||||
&self,
|
&self,
|
||||||
@ -570,6 +561,7 @@ impl BlockManager {
|
|||||||
let mut f = fs::File::open(&path).await?;
|
let mut f = fs::File::open(&path).await?;
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
f.read_to_end(&mut data).await?;
|
f.read_to_end(&mut data).await?;
|
||||||
|
self.metrics.bytes_read.add(data.len() as u64);
|
||||||
drop(f);
|
drop(f);
|
||||||
|
|
||||||
let data = if compressed {
|
let data = if compressed {
|
||||||
@ -731,6 +723,7 @@ impl BlockManagerLocked {
|
|||||||
|
|
||||||
let mut f = fs::File::create(&path_tmp).await?;
|
let mut f = fs::File::create(&path_tmp).await?;
|
||||||
f.write_all(data).await?;
|
f.write_all(data).await?;
|
||||||
|
mgr.metrics.bytes_written.add(data.len() as u64);
|
||||||
|
|
||||||
if mgr.data_fsync {
|
if mgr.data_fsync {
|
||||||
f.sync_all().await?;
|
f.sync_all().await?;
|
||||||
|
Loading…
Reference in New Issue
Block a user