Skip to content

Commit 8711108

Browse files
authored
feat: store persistent cache host by announce host api (#3640)
Signed-off-by: Gaius <gaius.qi@gmail.com>
1 parent 071ab91 commit 8711108

File tree

6 files changed

+872
-189
lines changed

6 files changed

+872
-189
lines changed

scheduler/resource/persistentcache/host.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,19 @@ import (
2121

2222
logger "d7y.io/dragonfly/v2/internal/dflog"
2323
"d7y.io/dragonfly/v2/pkg/types"
24+
"d7y.io/dragonfly/v2/scheduler/config"
2425
)
2526

27+
// HostOption is a functional option for configuring the persistent cache host.
28+
type HostOption func(h *Host)
29+
30+
// WithConcurrentUploadLimit sets persistent cache host's ConcurrentUploadLimit.
31+
func WithConcurrentUploadLimit(limit int32) HostOption {
32+
return func(h *Host) {
33+
h.ConcurrentUploadLimit = limit
34+
}
35+
}
36+
2637
// Host contains content for host.
2738
type Host struct {
2839
// ID is host id.
@@ -248,11 +259,17 @@ type Disk struct {
248259

249260
// New host instance.
250261
func NewHost(
251-
id, hostname, ip, os, platform, platformFamily, platformVersion, kernelVersion string, port, downloadPort, concurrentUploadLimit, concurrentUploadCount int32,
262+
id, hostname, ip, os, platform, platformFamily, platformVersion, kernelVersion string, port, downloadPort, concurrentUploadCount int32,
252263
UploadCount, UploadFailedCount int64, disableShared bool, typ types.HostType, cpu CPU, memory Memory, network Network, disk Disk,
253-
build Build, announceInterval time.Duration, createdAt, updatedAt time.Time, log *logger.SugaredLoggerOnWith,
264+
build Build, announceInterval time.Duration, createdAt, updatedAt time.Time, log *logger.SugaredLoggerOnWith, options ...HostOption,
254265
) *Host {
255-
return &Host{
266+
// Calculate default of the concurrent upload limit by host type.
267+
concurrentUploadLimit := config.DefaultSeedPeerConcurrentUploadLimit
268+
if typ == types.HostTypeNormal {
269+
concurrentUploadLimit = config.DefaultPeerConcurrentUploadLimit
270+
}
271+
272+
h := &Host{
256273
ID: id,
257274
Type: types.HostType(typ),
258275
Hostname: hostname,
@@ -271,12 +288,18 @@ func NewHost(
271288
Disk: disk,
272289
Build: build,
273290
AnnounceInterval: announceInterval,
274-
ConcurrentUploadLimit: concurrentUploadLimit,
291+
ConcurrentUploadLimit: int32(concurrentUploadLimit),
275292
ConcurrentUploadCount: concurrentUploadCount,
276293
UploadCount: UploadCount,
277294
UploadFailedCount: UploadFailedCount,
278295
CreatedAt: createdAt,
279296
UpdatedAt: updatedAt,
280297
Log: logger.WithHost(id, hostname, ip),
281298
}
299+
300+
for _, opt := range options {
301+
opt(h)
302+
}
303+
304+
return h
282305
}

scheduler/resource/persistentcache/host_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ func (t *hostManager) Load(ctx context.Context, hostID string) (*Host, bool) {
408408
rawHost["kernel_version"],
409409
int32(port),
410410
int32(downloadPort),
411-
int32(concurrentUploadLimit),
412411
int32(concurrentUploadCount),
413412
uploadCount,
414413
uploadFailedCount,
@@ -423,6 +422,7 @@ func (t *hostManager) Load(ctx context.Context, hostID string) (*Host, bool) {
423422
createdAt,
424423
updatedAt,
425424
logger.WithHost(rawHost["id"], rawHost["hostname"], rawHost["ip"]),
425+
WithConcurrentUploadLimit(int32(concurrentUploadLimit)),
426426
), true
427427
}
428428

scheduler/resource/persistentcache/task_manager_mock.go

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

scheduler/service/service_v1_test.go

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ import (
3333
"time"
3434

3535
"github.com/stretchr/testify/assert"
36-
"go.uber.org/atomic"
3736
"go.uber.org/mock/gomock"
3837
"google.golang.org/grpc/codes"
3938
"google.golang.org/grpc/status"
40-
"google.golang.org/protobuf/types/known/durationpb"
4139

4240
commonv1 "d7y.io/api/v2/pkg/apis/common/v1"
4341
commonv2 "d7y.io/api/v2/pkg/apis/common/v2"
@@ -76,103 +74,6 @@ var (
7674
TaskDownloadTimeout: 1 * time.Hour,
7775
}
7876

79-
mockRawHost = resource.Host{
80-
ID: mockHostID,
81-
Type: pkgtypes.HostTypeNormal,
82-
Hostname: "foo",
83-
IP: "127.0.0.1",
84-
Port: 8003,
85-
DownloadPort: 8001,
86-
OS: "darwin",
87-
Platform: "darwin",
88-
PlatformFamily: "Standalone Workstation",
89-
PlatformVersion: "11.1",
90-
KernelVersion: "20.2.0",
91-
CPU: mockCPU,
92-
Memory: mockMemory,
93-
Network: mockNetwork,
94-
Disk: mockDisk,
95-
Build: mockBuild,
96-
CreatedAt: atomic.NewTime(time.Now()),
97-
UpdatedAt: atomic.NewTime(time.Now()),
98-
}
99-
100-
mockRawSeedHost = resource.Host{
101-
ID: mockSeedHostID,
102-
Type: pkgtypes.HostTypeSuperSeed,
103-
Hostname: "bar",
104-
IP: "127.0.0.1",
105-
Port: 8003,
106-
DownloadPort: 8001,
107-
OS: "darwin",
108-
Platform: "darwin",
109-
PlatformFamily: "Standalone Workstation",
110-
PlatformVersion: "11.1",
111-
KernelVersion: "20.2.0",
112-
CPU: mockCPU,
113-
Memory: mockMemory,
114-
Network: mockNetwork,
115-
Disk: mockDisk,
116-
Build: mockBuild,
117-
CreatedAt: atomic.NewTime(time.Now()),
118-
UpdatedAt: atomic.NewTime(time.Now()),
119-
}
120-
121-
mockCPU = resource.CPU{
122-
LogicalCount: 4,
123-
PhysicalCount: 2,
124-
Percent: 1,
125-
ProcessPercent: 0.5,
126-
Times: resource.CPUTimes{
127-
User: 240662.2,
128-
System: 317950.1,
129-
Idle: 3393691.3,
130-
Nice: 0,
131-
Iowait: 0,
132-
Irq: 0,
133-
Softirq: 0,
134-
Steal: 0,
135-
Guest: 0,
136-
GuestNice: 0,
137-
},
138-
}
139-
140-
mockMemory = resource.Memory{
141-
Total: 17179869184,
142-
Available: 5962813440,
143-
Used: 11217055744,
144-
UsedPercent: 65.291858,
145-
ProcessUsedPercent: 41.525125,
146-
Free: 2749598908,
147-
}
148-
149-
mockNetwork = resource.Network{
150-
TCPConnectionCount: 10,
151-
UploadTCPConnectionCount: 1,
152-
Location: mockHostLocation,
153-
IDC: mockHostIDC,
154-
}
155-
156-
mockDisk = resource.Disk{
157-
Total: 499963174912,
158-
Free: 37226479616,
159-
Used: 423809622016,
160-
UsedPercent: 91.92547406065952,
161-
InodesTotal: 4882452880,
162-
InodesUsed: 7835772,
163-
InodesFree: 4874617108,
164-
InodesUsedPercent: 0.1604884305611568,
165-
}
166-
167-
mockBuild = resource.Build{
168-
GitVersion: "v1.0.0",
169-
GitCommit: "221176b117c6d59366d68f2b34d38be50c935883",
170-
GoVersion: "1.18",
171-
Platform: "darwin",
172-
}
173-
174-
mockInterval = durationpb.New(5 * time.Minute).AsDuration()
175-
17677
mockPeerHost = &schedulerv1.PeerHost{
17778
Id: mockHostID,
17879
Ip: "127.0.0.1",

0 commit comments

Comments
 (0)