Skip to content

Commit 7aec4fc

Browse files
authored
Merge pull request #164 from anyproto/GO-6138-batch-file-add
GO-6138 batch file add
2 parents 4271c1d + db6cba9 commit 7aec4fc

6 files changed

Lines changed: 158 additions & 71 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ vendor
2424

2525
# database
2626
# db
27+
N*.yml
2728

2829
# artefacts for Intelli-J fleet
2930
.fleet

filenode/rpchandler.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
const (
16-
cidSizeLimit = 2 << 20 // 2 Mb
16+
cidSizeLimit = 4 << 20 // 4 Mb
1717
fileInfoReqLimit = 1000
1818
)
1919

@@ -95,6 +95,58 @@ func (r rpcHandler) BlockPush(ctx context.Context, req *fileproto.BlockPushReque
9595
return &fileproto.Ok{}, nil
9696
}
9797

98+
func (r rpcHandler) BlockPushMany(ctx context.Context, req *fileproto.BlockPushManyRequest) (resp *fileproto.Ok, err error) {
99+
var (
100+
st = time.Now()
101+
dataSum int
102+
cidCount int
103+
fileCount int
104+
)
105+
defer func() {
106+
r.f.metric.RequestLog(ctx,
107+
"file.blockPushMany",
108+
metric.TotalDur(time.Since(st)),
109+
metric.Size(dataSum),
110+
zap.Int("cidCount", cidCount),
111+
zap.Int("fileCount", fileCount),
112+
zap.Error(err),
113+
)
114+
}()
115+
116+
for _, fileBlock := range req.FileBlocks {
117+
bs := make([]blocks.Block, 0, len(fileBlock.Blocks))
118+
for _, block := range fileBlock.Blocks {
119+
var c cid.Cid
120+
c, err = cid.Cast(block.Cid)
121+
if err != nil {
122+
return nil, err
123+
}
124+
b, err := blocks.NewBlockWithCid(block.Data, c)
125+
if err != nil {
126+
return nil, err
127+
}
128+
chkc, err := c.Prefix().Sum(block.Data)
129+
if err != nil {
130+
return nil, err
131+
}
132+
if !chkc.Equals(c) {
133+
return nil, ErrWrongHash
134+
}
135+
dataSum += len(b.RawData())
136+
if dataSum > fileInfoReqLimit {
137+
return nil, fileprotoerr.ErrQuerySizeExceeded
138+
}
139+
bs = append(bs, b)
140+
cidCount++
141+
}
142+
if err = r.f.Add(ctx, fileBlock.SpaceId, fileBlock.FileId, bs); err != nil {
143+
return nil, err
144+
}
145+
fileCount++
146+
}
147+
return &fileproto.Ok{}, nil
148+
}
149+
98150
func (r rpcHandler) BlocksCheck(ctx context.Context, req *fileproto.BlocksCheckRequest) (resp *fileproto.BlocksCheckResponse, err error) {
99151
st := time.Now()
100152
defer func() {

go.mod

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
module github.com/anyproto/any-sync-filenode
22

3-
go 1.23.10
4-
5-
toolchain go1.24.0
3+
go 1.24.0
64

75
require (
86
github.com/OneOfOne/xxhash v1.2.8
97
github.com/ahmetb/govvv v0.3.0
10-
github.com/anyproto/any-sync v0.9.6
8+
github.com/anyproto/any-store v0.3.5
9+
github.com/anyproto/any-sync v0.10.0
1110
github.com/aws/aws-sdk-go v1.55.8
1211
github.com/cespare/xxhash/v2 v2.3.0
1312
github.com/go-redsync/redsync/v4 v4.13.0
@@ -16,16 +15,15 @@ require (
1615
github.com/ipfs/go-block-format v0.2.2
1716
github.com/ipfs/go-cid v0.5.0
1817
github.com/redis/go-redis/v9 v9.12.0
19-
github.com/stretchr/testify v1.10.0
20-
go.uber.org/mock v0.5.2
18+
github.com/stretchr/testify v1.11.1
19+
go.uber.org/mock v0.6.0
2120
go.uber.org/zap v1.27.0
22-
golang.org/x/sync v0.16.0
21+
golang.org/x/sync v0.17.0
2322
gopkg.in/yaml.v3 v3.0.1
2423
)
2524

2625
require (
2726
filippo.io/edwards25519 v1.1.0 // indirect
28-
github.com/anyproto/any-store v0.3.3 // indirect
2927
github.com/anyproto/go-chash v0.1.0 // indirect
3028
github.com/anyproto/go-slip10 v1.0.0 // indirect
3129
github.com/anyproto/go-slip21 v1.0.0 // indirect
@@ -52,7 +50,7 @@ require (
5250
github.com/jmespath/go-jmespath v0.4.0 // indirect
5351
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
5452
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
55-
github.com/libp2p/go-libp2p v0.42.1 // indirect
53+
github.com/libp2p/go-libp2p v0.43.0 // indirect
5654
github.com/mattn/go-isatty v0.0.20 // indirect
5755
github.com/minio/sha256-simd v1.0.1 // indirect
5856
github.com/mr-tron/base58 v1.2.0 // indirect
@@ -68,9 +66,9 @@ require (
6866
github.com/ncruces/go-strftime v0.1.9 // indirect
6967
github.com/planetscale/vtprotobuf v0.6.0 // indirect
7068
github.com/pmezard/go-difflib v1.0.0 // indirect
71-
github.com/prometheus/client_golang v1.23.0 // indirect
69+
github.com/prometheus/client_golang v1.23.2 // indirect
7270
github.com/prometheus/client_model v0.6.2 // indirect
73-
github.com/prometheus/common v0.65.0 // indirect
71+
github.com/prometheus/common v0.66.1 // indirect
7472
github.com/prometheus/procfs v0.16.1 // indirect
7573
github.com/quic-go/quic-go v0.54.0 // indirect
7674
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
@@ -80,16 +78,17 @@ require (
8078
github.com/zeebo/errs v1.3.0 // indirect
8179
go.uber.org/atomic v1.11.0 // indirect
8280
go.uber.org/multierr v1.11.0 // indirect
83-
golang.org/x/crypto v0.40.0 // indirect
84-
golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 // indirect
85-
golang.org/x/mod v0.26.0 // indirect
86-
golang.org/x/net v0.42.0 // indirect
87-
golang.org/x/sys v0.34.0 // indirect
88-
golang.org/x/time v0.12.0 // indirect
89-
golang.org/x/tools v0.35.0 // indirect
90-
google.golang.org/protobuf v1.36.6 // indirect
81+
go.yaml.in/yaml/v2 v2.4.2 // indirect
82+
golang.org/x/crypto v0.42.0 // indirect
83+
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect
84+
golang.org/x/mod v0.27.0 // indirect
85+
golang.org/x/net v0.43.0 // indirect
86+
golang.org/x/sys v0.36.0 // indirect
87+
golang.org/x/time v0.13.0 // indirect
88+
golang.org/x/tools v0.36.0 // indirect
89+
google.golang.org/protobuf v1.36.8 // indirect
9190
lukechampine.com/blake3 v1.4.1 // indirect
92-
modernc.org/libc v1.66.3 // indirect
91+
modernc.org/libc v1.66.8 // indirect
9392
modernc.org/mathutil v1.7.1 // indirect
9493
modernc.org/memory v1.11.0 // indirect
9594
modernc.org/sqlite v1.38.0 // indirect

0 commit comments

Comments
 (0)