@@ -533,43 +533,45 @@ func OpenWith(path string, vLogs []appendable.Appendable, txLog, cLog appendable
533533 precommittedAlh := committedAlh
534534 precommittedTxLogSize := committedTxLogSize
535535
536- // read pre-committed txs from txLog and insert into cLogBuf to continue with the commit process
537- // txLog may be partially written, precommitted transactions loading is terminated if an inconsistency is found
538- txReader := appendable .NewReaderFrom (txLog , precommittedTxLogSize , multiapp .DefaultReadBufferSize )
536+ if ! opts .SkipPrecommittedTransactions {
537+ // read pre-committed txs from txLog and insert into cLogBuf to continue with the commit process
538+ // txLog may be partially written, precommitted transactions loading is terminated if an inconsistency is found
539+ txReader := appendable .NewReaderFrom (txLog , precommittedTxLogSize , multiapp .DefaultReadBufferSize )
539540
540- tx , _ := txPool .Alloc ()
541+ tx , _ := txPool .Alloc ()
541542
542- for {
543- err = tx .readFrom (txReader , false )
544- if errors .Is (err , io .EOF ) {
545- break
546- }
547- if err != nil {
548- opts .logger .Infof ("%v: discarding pre-committed transaction: %d" , err , precommittedTxID + 1 )
549- break
550- }
543+ for {
544+ err = tx .readFrom (txReader , false )
545+ if errors .Is (err , io .EOF ) {
546+ break
547+ }
548+ if err != nil {
549+ opts .logger .Infof ("%v: discarding pre-committed transaction: %d" , err , precommittedTxID + 1 )
550+ break
551+ }
551552
552- if tx .header .ID != precommittedTxID + 1 || tx .header .PrevAlh != precommittedAlh {
553- opts .logger .Infof ("%v: discarding pre-committed transaction: %d" , ErrCorruptedData , precommittedTxID + 1 )
554- break
555- }
553+ if tx .header .ID != precommittedTxID + 1 || tx .header .PrevAlh != precommittedAlh {
554+ opts .logger .Infof ("%v: discarding pre-committed transaction: %d" , ErrCorruptedData , precommittedTxID + 1 )
555+ break
556+ }
556557
557- precommittedTxID ++
558- precommittedAlh = tx .header .Alh ()
558+ precommittedTxID ++
559+ precommittedAlh = tx .header .Alh ()
559560
560- txSize := int (txReader .ReadCount () - (precommittedTxLogSize - committedTxLogSize ))
561+ txSize := int (txReader .ReadCount () - (precommittedTxLogSize - committedTxLogSize ))
561562
562- err = cLogBuf .put (precommittedTxID , precommittedAlh , precommittedTxLogSize , txSize )
563- if err != nil {
564- txPool .Release (tx )
565- return nil , fmt .Errorf ("%v: while loading pre-committed transaction: %v" , err , precommittedTxID + 1 )
563+ err = cLogBuf .put (precommittedTxID , precommittedAlh , precommittedTxLogSize , txSize )
564+ if err != nil {
565+ txPool .Release (tx )
566+ return nil , fmt .Errorf ("%v: while loading pre-committed transaction: %v" , err , precommittedTxID + 1 )
567+ }
568+
569+ precommittedTxLogSize += int64 (txSize )
566570 }
567571
568- precommittedTxLogSize += int64 ( txSize )
572+ txPool . Release ( tx )
569573 }
570574
571- txPool .Release (tx )
572-
573575 vLogsMap := make (map [byte ]* refVLog , len (vLogs ))
574576 vLogUnlockedList := list .New ()
575577
0 commit comments