Skip to content

Commit 232731e

Browse files
adds more metrics to blockstore insert shreds stats (backport solana-labs#20701) (solana-labs#20751)
* adds more metrics to blockstore insert shreds stats (solana-labs#20701) (cherry picked from commit 231b58b) # Conflicts: # ledger/src/blockstore.rs * removes backport merge conflicts * removes error logs Co-authored-by: behzad nouri <behzadnouri@gmail.com>
1 parent 63835ec commit 232731e

File tree

1 file changed

+70
-11
lines changed

1 file changed

+70
-11
lines changed

ledger/src/blockstore.rs

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use {
4646
borrow::Cow,
4747
cell::RefCell,
4848
cmp,
49-
collections::{BTreeMap, HashMap, HashSet},
49+
collections::{hash_map::Entry as HashMapEntry, BTreeMap, HashMap, HashSet},
5050
convert::TryInto,
5151
fs,
5252
io::{Error as IoError, ErrorKind},
@@ -216,11 +216,19 @@ pub struct BlockstoreInsertionMetrics {
216216
pub num_inserted: u64,
217217
pub num_repair: u64,
218218
pub num_recovered: usize,
219+
num_recovered_blockstore_error: usize,
219220
pub num_recovered_inserted: usize,
220221
pub num_recovered_failed_sig: usize,
221222
pub num_recovered_failed_invalid: usize,
222223
pub num_recovered_exists: usize,
223224
pub index_meta_time: u64,
225+
num_data_shreds_exists: usize,
226+
num_data_shreds_invalid: usize,
227+
num_data_shreds_blockstore_error: usize,
228+
num_coding_shreds_exists: usize,
229+
num_coding_shreds_invalid: usize,
230+
num_coding_shreds_invalid_erasure_config: usize,
231+
num_coding_shreds_inserted: usize,
224232
}
225233

226234
impl SlotMetaWorkingSetEntry {
@@ -280,6 +288,38 @@ impl BlockstoreInsertionMetrics {
280288
self.num_recovered_exists as i64,
281289
i64
282290
),
291+
(
292+
"num_recovered_blockstore_error",
293+
self.num_recovered_blockstore_error,
294+
i64
295+
),
296+
("num_data_shreds_exists", self.num_data_shreds_exists, i64),
297+
("num_data_shreds_invalid", self.num_data_shreds_invalid, i64),
298+
(
299+
"num_data_shreds_blockstore_error",
300+
self.num_data_shreds_blockstore_error,
301+
i64
302+
),
303+
(
304+
"num_coding_shreds_exists",
305+
self.num_coding_shreds_exists,
306+
i64
307+
),
308+
(
309+
"num_coding_shreds_invalid",
310+
self.num_coding_shreds_invalid,
311+
i64
312+
),
313+
(
314+
"num_coding_shreds_invalid_erasure_config",
315+
self.num_coding_shreds_invalid_erasure_config,
316+
i64
317+
),
318+
(
319+
"num_coding_shreds_inserted",
320+
self.num_coding_shreds_inserted,
321+
i64
322+
),
283323
);
284324
}
285325
}
@@ -841,7 +881,7 @@ impl Blockstore {
841881
} else {
842882
ShredSource::Turbine
843883
};
844-
if let Ok(completed_data_sets) = self.check_insert_data_shred(
884+
match self.check_insert_data_shred(
845885
shred,
846886
&mut erasure_metas,
847887
&mut index_working_set,
@@ -854,10 +894,17 @@ impl Blockstore {
854894
leader_schedule,
855895
shred_source,
856896
) {
857-
newly_completed_data_sets.extend(completed_data_sets);
858-
inserted_indices.push(i);
859-
metrics.num_inserted += 1;
860-
}
897+
Err(InsertDataShredError::Exists) => metrics.num_data_shreds_exists += 1,
898+
Err(InsertDataShredError::InvalidShred) => metrics.num_data_shreds_invalid += 1,
899+
Err(InsertDataShredError::BlockstoreError(_)) => {
900+
metrics.num_data_shreds_blockstore_error += 1;
901+
}
902+
Ok(completed_data_sets) => {
903+
newly_completed_data_sets.extend(completed_data_sets);
904+
inserted_indices.push(i);
905+
metrics.num_inserted += 1;
906+
}
907+
};
861908
} else if shred.is_code() {
862909
self.check_cache_coding_shred(
863910
shred,
@@ -868,6 +915,7 @@ impl Blockstore {
868915
handle_duplicate,
869916
is_trusted,
870917
is_repaired,
918+
metrics,
871919
);
872920
} else {
873921
panic!("There should be no other case");
@@ -917,7 +965,10 @@ impl Blockstore {
917965
metrics.num_recovered_failed_invalid += 1;
918966
None
919967
}
920-
Err(InsertDataShredError::BlockstoreError(_)) => None,
968+
Err(InsertDataShredError::BlockstoreError(_)) => {
969+
metrics.num_recovered_blockstore_error += 1;
970+
None
971+
}
921972
Ok(completed_data_sets) => {
922973
newly_completed_data_sets.extend(completed_data_sets);
923974
metrics.num_recovered_inserted += 1;
@@ -1062,6 +1113,7 @@ impl Blockstore {
10621113
|| shred1.coding_header.num_data_shreds != shred2.coding_header.num_data_shreds
10631114
}
10641115

1116+
#[allow(clippy::too_many_arguments)]
10651117
fn check_cache_coding_shred<F>(
10661118
&self,
10671119
shred: Shred,
@@ -1072,6 +1124,7 @@ impl Blockstore {
10721124
handle_duplicate: &F,
10731125
is_trusted: bool,
10741126
is_repaired: bool,
1127+
metrics: &mut BlockstoreInsertionMetrics,
10751128
) -> bool
10761129
where
10771130
F: Fn(Shred),
@@ -1089,11 +1142,13 @@ impl Blockstore {
10891142

10901143
if !is_trusted {
10911144
if index_meta.coding().is_present(shred_index) {
1145+
metrics.num_coding_shreds_exists += 1;
10921146
handle_duplicate(shred);
10931147
return false;
10941148
}
10951149

10961150
if !Blockstore::should_insert_coding_shred(&shred, &self.last_root) {
1151+
metrics.num_coding_shreds_invalid += 1;
10971152
return false;
10981153
}
10991154
}
@@ -1112,6 +1167,7 @@ impl Blockstore {
11121167
});
11131168

11141169
if erasure_config != erasure_meta.config {
1170+
metrics.num_coding_shreds_invalid_erasure_config += 1;
11151171
let conflicting_shred = self.find_conflicting_coding_shred(
11161172
&shred,
11171173
slot,
@@ -1152,10 +1208,11 @@ impl Blockstore {
11521208
// committed
11531209
index_meta.coding_mut().set_present(shred_index, true);
11541210

1155-
just_received_coding_shreds
1156-
.entry((slot, shred_index))
1157-
.or_insert_with(|| shred);
1158-
1211+
if let HashMapEntry::Vacant(entry) = just_received_coding_shreds.entry((slot, shred_index))
1212+
{
1213+
metrics.num_coding_shreds_inserted += 1;
1214+
entry.insert(shred);
1215+
}
11591216
true
11601217
}
11611218

@@ -5673,6 +5730,7 @@ pub mod tests {
56735730
},
56745731
false,
56755732
false,
5733+
&mut BlockstoreInsertionMetrics::default(),
56765734
));
56775735

56785736
// insert again fails on dupe
@@ -5689,6 +5747,7 @@ pub mod tests {
56895747
},
56905748
false,
56915749
false,
5750+
&mut BlockstoreInsertionMetrics::default(),
56925751
));
56935752
assert_eq!(counter.load(Ordering::Relaxed), 1);
56945753
}

0 commit comments

Comments
 (0)