mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-18 13:59:26 +00:00
core/rawdb: capture open file error and fix resource leak (#33147)
This commit is contained in:
parent
5f4cc3f57d
commit
7368b34a4b
3 changed files with 13 additions and 5 deletions
|
|
@ -303,6 +303,7 @@ func (db *Store) openEraFile(epoch uint64) (*era.Era, error) {
|
||||||
}
|
}
|
||||||
// Sanity-check start block.
|
// Sanity-check start block.
|
||||||
if e.Start()%uint64(era.MaxEra1Size) != 0 {
|
if e.Start()%uint64(era.MaxEra1Size) != 0 {
|
||||||
|
e.Close()
|
||||||
return nil, fmt.Errorf("pre-merge era1 file has invalid boundary. %d %% %d != 0", e.Start(), era.MaxEra1Size)
|
return nil, fmt.Errorf("pre-merge era1 file has invalid boundary. %d %% %d != 0", e.Start(), era.MaxEra1Size)
|
||||||
}
|
}
|
||||||
log.Debug("Opened era1 file", "epoch", epoch)
|
log.Debug("Opened era1 file", "epoch", epoch)
|
||||||
|
|
|
||||||
|
|
@ -51,12 +51,18 @@ func newFreezerBatch(f *Freezer) *freezerBatch {
|
||||||
|
|
||||||
// Append adds an RLP-encoded item of the given kind.
|
// Append adds an RLP-encoded item of the given kind.
|
||||||
func (batch *freezerBatch) Append(kind string, num uint64, item interface{}) error {
|
func (batch *freezerBatch) Append(kind string, num uint64, item interface{}) error {
|
||||||
return batch.tables[kind].Append(num, item)
|
if table := batch.tables[kind]; table != nil {
|
||||||
|
return table.Append(num, item)
|
||||||
|
}
|
||||||
|
return errUnknownTable
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendRaw adds an item of the given kind.
|
// AppendRaw adds an item of the given kind.
|
||||||
func (batch *freezerBatch) AppendRaw(kind string, num uint64, item []byte) error {
|
func (batch *freezerBatch) AppendRaw(kind string, num uint64, item []byte) error {
|
||||||
return batch.tables[kind].AppendRaw(num, item)
|
if table := batch.tables[kind]; table != nil {
|
||||||
|
return table.AppendRaw(num, item)
|
||||||
|
}
|
||||||
|
return errUnknownTable
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset initializes the batch.
|
// reset initializes the batch.
|
||||||
|
|
|
||||||
|
|
@ -1196,8 +1196,7 @@ func (t *freezerTable) sizeNolock() (uint64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// advanceHead should be called when the current head file would outgrow the file limits,
|
// advanceHead should be called when the current head file would outgrow the file limits,
|
||||||
// and a new file must be opened. The caller of this method must hold the write-lock
|
// and a new file must be opened. This method acquires the write-lock internally.
|
||||||
// before calling this method.
|
|
||||||
func (t *freezerTable) advanceHead() error {
|
func (t *freezerTable) advanceHead() error {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
|
|
@ -1218,7 +1217,9 @@ func (t *freezerTable) advanceHead() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.releaseFile(t.headId)
|
t.releaseFile(t.headId)
|
||||||
t.openFile(t.headId, openFreezerFileForReadOnly)
|
if _, err := t.openFile(t.headId, openFreezerFileForReadOnly); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Swap out the current head.
|
// Swap out the current head.
|
||||||
t.head = newHead
|
t.head = newHead
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue