@@ -364,6 +364,12 @@ impl Inner {
364364 }
365365
366366 fn bootstrap_system_table ( & mut self , schema : TableSchema ) -> Result < ( ) , DBError > {
367+ // Reset the row count metric for this system table
368+ DB_METRICS
369+ . rdb_num_table_rows
370+ . with_label_values ( & self . database_address , & schema. table_id . into ( ) )
371+ . set ( 0 ) ;
372+
367373 let table_id = schema. table_id ;
368374
369375 // Insert the table row into st_tables, creating st_tables if it's missing
@@ -380,6 +386,12 @@ impl Inner {
380386 let data_key = row. to_data_key ( ) ;
381387 st_tables. rows . insert ( RowId ( data_key) , row) ;
382388
389+ // Increment row count for st_tables
390+ DB_METRICS
391+ . rdb_num_table_rows
392+ . with_label_values ( & self . database_address , & ST_TABLES_ID . into ( ) )
393+ . inc ( ) ;
394+
383395 // Insert the columns into st_columns
384396 let first_col_id = schema. columns . first ( ) . unwrap ( ) . col_id ;
385397 for ( i, col) in schema. columns . into_iter ( ) . enumerate ( ) {
@@ -399,6 +411,11 @@ impl Inner {
399411 self . committed_state
400412 . get_or_create_table ( ST_COLUMNS_ID , & ST_COLUMNS_ROW_TYPE , & st_columns_schema ( ) ) ;
401413 st_columns. rows . insert ( RowId ( data_key) , row) ;
414+ // Increment row count for st_columns
415+ DB_METRICS
416+ . rdb_num_table_rows
417+ . with_label_values ( & self . database_address , & ST_COLUMNS_ID . into ( ) )
418+ . inc ( ) ;
402419 }
403420
404421 // If any columns are auto incrementing, we need to create a sequence
@@ -435,6 +452,11 @@ impl Inner {
435452 let row = ProductValue :: from ( row) ;
436453 let data_key = row. to_data_key ( ) ;
437454 st_sequences. rows . insert ( RowId ( data_key) , row) ;
455+ // Increment row count for st_sequences
456+ DB_METRICS
457+ . rdb_num_table_rows
458+ . with_label_values ( & self . database_address , & ST_SEQUENCES_ID . into ( ) )
459+ . inc ( ) ;
438460 }
439461 }
440462
@@ -463,6 +485,12 @@ impl Inner {
463485 let data_key = row. to_data_key ( ) ;
464486 st_constraints. rows . insert ( RowId ( data_key) , row) ;
465487
488+ // Increment row count for st_constraints
489+ DB_METRICS
490+ . rdb_num_table_rows
491+ . with_label_values ( & self . database_address , & ST_CONSTRAINTS_ID . into ( ) )
492+ . inc ( ) ;
493+
466494 //Check if add an index:
467495 match constraint. kind {
468496 x if x. is_unique ( ) => IndexSchema {
@@ -498,6 +526,12 @@ impl Inner {
498526 let row = ProductValue :: from ( row) ;
499527 let data_key = row. to_data_key ( ) ;
500528 st_indexes. rows . insert ( RowId ( data_key) , row) ;
529+
530+ // Increment row count for st_indexes
531+ DB_METRICS
532+ . rdb_num_table_rows
533+ . with_label_values ( & self . database_address , & ST_INDEXES_ID . into ( ) )
534+ . inc ( ) ;
501535 }
502536
503537 Ok ( ( ) )
@@ -1640,6 +1674,10 @@ impl Locking {
16401674 match write. operation {
16411675 Operation :: Delete => {
16421676 Self :: table_rows ( & mut inner, table_id, schema, row_type) . remove ( & RowId ( write. data_key ) ) ;
1677+ DB_METRICS
1678+ . rdb_num_table_rows
1679+ . with_label_values ( & inner. database_address , & table_id. into ( ) )
1680+ . dec ( ) ;
16431681 }
16441682 Operation :: Insert => {
16451683 let product_value = match write. data_key {
@@ -1657,6 +1695,10 @@ impl Locking {
16571695 } ;
16581696 Self :: table_rows ( & mut inner, table_id, schema, row_type)
16591697 . insert ( RowId ( write. data_key ) , product_value) ;
1698+ DB_METRICS
1699+ . rdb_num_table_rows
1700+ . with_label_values ( & inner. database_address , & table_id. into ( ) )
1701+ . inc ( ) ;
16601702 }
16611703 }
16621704 }
0 commit comments