@@ -4,7 +4,7 @@ use std::{
44 sync:: Arc ,
55} ;
66
7- use slog:: { warn , Logger } ;
7+ use slog:: Logger ;
88
99use crate :: {
1010 blockchain:: { block_stream:: FirehoseCursor , BlockPtr , BlockTime } ,
@@ -340,33 +340,22 @@ impl LastMod {
340340#[ derive( Debug , CacheWeight ) ]
341341pub struct RowGroup {
342342 pub entity_type : EntityType ,
343+
343344 /// All changes for this entity type, ordered by block; i.e., if `i < j`
344345 /// then `rows[i].block() <= rows[j].block()`. Several methods on this
345346 /// struct rely on the fact that this ordering is observed.
346347 rows : Vec < EntityModification > ,
347348
348- immutable : bool ,
349- skip_duplicates : bool ,
350- logger : Logger ,
351-
352349 /// Map the `key.entity_id` of all entries in `rows` to the index with
353350 /// the most recent entry for that id to speed up lookups.
354351 last_mod : LastMod ,
355352}
356353
357354impl RowGroup {
358- pub fn new (
359- entity_type : EntityType ,
360- immutable : bool ,
361- skip_duplicates : bool ,
362- logger : Logger ,
363- ) -> Self {
355+ pub fn new ( entity_type : EntityType ) -> Self {
364356 Self {
365357 entity_type,
366358 rows : Vec :: new ( ) ,
367- immutable,
368- skip_duplicates,
369- logger,
370359 last_mod : LastMod :: new ( ) ,
371360 }
372361 }
@@ -482,7 +471,7 @@ impl RowGroup {
482471 /// Append `row` to `self.rows` by combining it with a previously
483472 /// existing row, if that is possible
484473 fn append_row ( & mut self , row : EntityModification ) -> Result < ( ) , StoreError > {
485- if self . immutable {
474+ if self . entity_type . is_immutable ( ) {
486475 match row {
487476 EntityModification :: Insert { .. } => {
488477 // Check if this is an attempt to overwrite an immutable
@@ -499,11 +488,7 @@ impl RowGroup {
499488 . and_then ( |& idx| self . rows . get ( idx) )
500489 {
501490 Some ( prev) if prev. block ( ) != row. block ( ) => {
502- if self . skip_duplicates {
503- warn ! ( self . logger, "Skipping duplicate insert for immutable entity" ;
504- "entity" => row. key( ) . to_string( ) ,
505- "block" => row. block( ) ,
506- "previous_block" => prev. block( ) ) ;
491+ if self . entity_type . skip_duplicates ( ) {
507492 return Ok ( ( ) ) ;
508493 }
509494 return Err ( StoreError :: Input (
@@ -516,10 +501,7 @@ impl RowGroup {
516501 self . push_row ( row) ;
517502 }
518503 EntityModification :: Overwrite { .. } | EntityModification :: Remove { .. } => {
519- if self . skip_duplicates {
520- warn ! ( self . logger, "Skipping unsupported operation for immutable entity" ;
521- "entity_type" => self . entity_type. to_string( ) ,
522- "operation" => format!( "{:?}" , row) ) ;
504+ if self . entity_type . skip_duplicates ( ) {
523505 return Ok ( ( ) ) ;
524506 }
525507 return Err ( internal_error ! (
@@ -628,18 +610,8 @@ impl RowGroup {
628610pub struct RowGroupForPerfTest ( RowGroup ) ;
629611
630612impl RowGroupForPerfTest {
631- pub fn new (
632- entity_type : EntityType ,
633- immutable : bool ,
634- skip_duplicates : bool ,
635- logger : Logger ,
636- ) -> Self {
637- Self ( RowGroup :: new (
638- entity_type,
639- immutable,
640- skip_duplicates,
641- logger,
642- ) )
613+ pub fn new ( entity_type : EntityType ) -> Self {
614+ Self ( RowGroup :: new ( entity_type) )
643615 }
644616
645617 pub fn push ( & mut self , emod : EntityModification , block : BlockNumber ) -> Result < ( ) , StoreError > {
@@ -722,14 +694,7 @@ impl RowGroups {
722694 match pos {
723695 Some ( pos) => & mut self . groups [ pos] ,
724696 None => {
725- let immutable = entity_type. is_immutable ( ) ;
726- let skip_duplicates = entity_type. skip_duplicates ( ) ;
727- self . groups . push ( RowGroup :: new (
728- entity_type. clone ( ) ,
729- immutable,
730- skip_duplicates,
731- self . logger . clone ( ) ,
732- ) ) ;
697+ self . groups . push ( RowGroup :: new ( entity_type. clone ( ) ) ) ;
733698 // unwrap: we just pushed an entry
734699 self . groups . last_mut ( ) . unwrap ( )
735700 }
@@ -1092,8 +1057,6 @@ mod test {
10921057 } ;
10931058 use lazy_static:: lazy_static;
10941059
1095- use slog:: Logger ;
1096-
10971060 use super :: { LastMod , RowGroup } ;
10981061
10991062 #[ track_caller]
@@ -1125,9 +1088,6 @@ mod test {
11251088 let group = RowGroup {
11261089 entity_type : ENTRY_TYPE . clone ( ) ,
11271090 rows,
1128- immutable : false ,
1129- skip_duplicates : false ,
1130- logger : Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
11311091 last_mod,
11321092 } ;
11331093 let act = group
@@ -1239,12 +1199,7 @@ mod test {
12391199 impl Group {
12401200 fn new ( ) -> Self {
12411201 Self {
1242- group : RowGroup :: new (
1243- THING_TYPE . clone ( ) ,
1244- false ,
1245- false ,
1246- Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
1247- ) ,
1202+ group : RowGroup :: new ( THING_TYPE . clone ( ) ) ,
12481203 }
12491204 }
12501205
@@ -1379,13 +1334,9 @@ mod test {
13791334 }
13801335 }
13811336
1382- fn discard_logger ( ) -> Logger {
1383- Logger :: root ( slog:: Discard , slog:: o!( ) )
1384- }
1385-
13861337 #[ test]
13871338 fn append_row_immutable_default_rejects_cross_block_duplicate ( ) {
1388- let mut group = RowGroup :: new ( IMM_THING_TYPE . clone ( ) , true , false , discard_logger ( ) ) ;
1339+ let mut group = RowGroup :: new ( IMM_THING_TYPE . clone ( ) ) ;
13891340 let res = group. push ( make_insert ( & IMM_THING_TYPE , "one" , 1 ) , 1 ) ;
13901341 assert ! ( res. is_ok( ) ) ;
13911342 let res = group. push ( make_insert ( & IMM_THING_TYPE , "one" , 2 ) , 2 ) ;
@@ -1394,7 +1345,7 @@ mod test {
13941345
13951346 #[ test]
13961347 fn append_row_skip_duplicates_allows_cross_block_duplicate ( ) {
1397- let mut group = RowGroup :: new ( SKIP_DUP_THING_TYPE . clone ( ) , true , true , discard_logger ( ) ) ;
1348+ let mut group = RowGroup :: new ( SKIP_DUP_THING_TYPE . clone ( ) ) ;
13981349 let res = group. push ( make_insert ( & SKIP_DUP_THING_TYPE , "one" , 1 ) , 1 ) ;
13991350 assert ! ( res. is_ok( ) ) ;
14001351 let res = group. push ( make_insert ( & SKIP_DUP_THING_TYPE , "one" , 2 ) , 2 ) ;
@@ -1404,21 +1355,21 @@ mod test {
14041355
14051356 #[ test]
14061357 fn append_row_skip_duplicates_allows_overwrite ( ) {
1407- let mut group = RowGroup :: new ( SKIP_DUP_THING_TYPE . clone ( ) , true , true , discard_logger ( ) ) ;
1358+ let mut group = RowGroup :: new ( SKIP_DUP_THING_TYPE . clone ( ) ) ;
14081359 let res = group. append_row ( make_overwrite ( & SKIP_DUP_THING_TYPE , "one" , 1 ) ) ;
14091360 assert ! ( res. is_ok( ) ) ;
14101361 }
14111362
14121363 #[ test]
14131364 fn append_row_skip_duplicates_allows_remove ( ) {
1414- let mut group = RowGroup :: new ( SKIP_DUP_THING_TYPE . clone ( ) , true , true , discard_logger ( ) ) ;
1365+ let mut group = RowGroup :: new ( SKIP_DUP_THING_TYPE . clone ( ) ) ;
14151366 let res = group. append_row ( make_remove ( & SKIP_DUP_THING_TYPE , "one" , 1 ) ) ;
14161367 assert ! ( res. is_ok( ) ) ;
14171368 }
14181369
14191370 #[ test]
14201371 fn append_row_skip_duplicates_same_block_still_pushes ( ) {
1421- let mut group = RowGroup :: new ( SKIP_DUP_THING_TYPE . clone ( ) , true , true , discard_logger ( ) ) ;
1372+ let mut group = RowGroup :: new ( SKIP_DUP_THING_TYPE . clone ( ) ) ;
14221373 let res = group. push ( make_insert ( & SKIP_DUP_THING_TYPE , "one" , 1 ) , 1 ) ;
14231374 assert ! ( res. is_ok( ) ) ;
14241375 let res = group. push ( make_insert ( & SKIP_DUP_THING_TYPE , "one" , 1 ) , 1 ) ;
0 commit comments