Skip to content

Commit 1694c70

Browse files
authored
Merge pull request #1399 from CortexFoundation/dev
core/rawdb: fsync head data file before closing it
2 parents 219877f + 04f1d74 commit 1694c70

File tree

8 files changed

+19
-13
lines changed

8 files changed

+19
-13
lines changed

core/rawdb/chain_freezer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ func (f *chainFreezer) Close() error {
8686
// This functionality is deliberately broken off from block importing to avoid
8787
// incurring additional data shuffling delays on block propagation.
8888
func (f *chainFreezer) freeze(db ctxcdb.KeyValueStore) {
89-
nfdb := &nofreezedb{KeyValueStore: db}
90-
9189
var (
9290
backoff bool
9391
triggered chan struct{} // Used in tests
92+
nfdb = &nofreezedb{KeyValueStore: db}
9493
)
9594

9695
timer := time.NewTimer(freezerRecheckInterval)
9796
defer timer.Stop()
97+
9898
for {
9999
select {
100100
case <-f.quit:

core/rawdb/freezer_table.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,11 @@ func (t *freezerTable) advanceHead() error {
860860
if err != nil {
861861
return err
862862
}
863-
864-
// Close old file, and reopen in RDONLY mode.
863+
// Commit the contents of the old file to stable storage and
864+
// tear it down. It will be re-opened in read-only mode.
865+
if err := t.head.Sync(); err != nil {
866+
return err
867+
}
865868
t.releaseFile(t.headId)
866869
t.openFile(t.headId, openFreezerFileForReadOnly)
867870

core/rawdb/freezer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func TestFreezerConcurrentModifyTruncate(t *testing.T) {
194194

195195
var item = make([]byte, 256)
196196

197-
for i := 0; i < 1000; i++ {
197+
for i := 0; i < 10; i++ {
198198
// First reset and write 100 items.
199199
if err := f.TruncateHead(0); err != nil {
200200
t.Fatal("truncate failed:", err)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.1
77
github.com/CortexFoundation/inference v1.0.2-0.20221114235728-985486629a61
88
github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
9-
github.com/CortexFoundation/torrentfs v1.0.35-0.20230112224026-33d896151830
9+
github.com/CortexFoundation/torrentfs v1.0.35-0.20230114014057-c7a532b00dfd
1010
github.com/VictoriaMetrics/fastcache v1.12.0
1111
github.com/arsham/figurine v1.3.0
1212
github.com/aws/aws-sdk-go-v2 v1.17.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66/go.mod h1:
8787
github.com/CortexFoundation/torrentfs v1.0.13-0.20200623060705-ce027f43f2f8/go.mod h1:Ma+tGhPPvz4CEZHaqEJQMOEGOfHeQBiAoNd1zyc/w3Q=
8888
github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.mod h1:qnb3YlIJmuetVBtC6Lsejr0Xru+1DNmDCdTqnwy7lhk=
8989
github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
90-
github.com/CortexFoundation/torrentfs v1.0.35-0.20230112224026-33d896151830 h1:HMwK8zr9r6NGcdlLH216FkKs3y42jytYR6bPASY2VQQ=
91-
github.com/CortexFoundation/torrentfs v1.0.35-0.20230112224026-33d896151830/go.mod h1:pzLgyzw0Su0ekjYCfTQ3T8aoTCpYULhbV7exUyUpV6w=
90+
github.com/CortexFoundation/torrentfs v1.0.35-0.20230114014057-c7a532b00dfd h1:Xg3SGG6slPdNSpP+ALcMmlU2+2PPnEk4eMQZycCaftA=
91+
github.com/CortexFoundation/torrentfs v1.0.35-0.20230114014057-c7a532b00dfd/go.mod h1:pzLgyzw0Su0ekjYCfTQ3T8aoTCpYULhbV7exUyUpV6w=
9292
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
9393
github.com/DATA-DOG/go-sqlmock v1.4.1 h1:ThlnYciV1iM/V0OSF/dtkqWb6xo5qITT1TJBG1MRDJM=
9494
github.com/HdrHistogram/hdrhistogram-go v1.1.0 h1:6dpdDPTRoo78HxAJ6T1HfMiKSnqhgRRqzCuPshRkQ7I=

vendor/github.com/CortexFoundation/torrentfs/Makefile

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/CortexFoundation/torrentfs/backend/handler.go

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ github.com/CortexFoundation/merkletree
5353
# github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
5454
## explicit; go 1.16
5555
github.com/CortexFoundation/statik
56-
# github.com/CortexFoundation/torrentfs v1.0.35-0.20230112224026-33d896151830
56+
# github.com/CortexFoundation/torrentfs v1.0.35-0.20230114014057-c7a532b00dfd
5757
## explicit; go 1.19
5858
github.com/CortexFoundation/torrentfs
5959
github.com/CortexFoundation/torrentfs/backend

0 commit comments

Comments
 (0)