Skip to content

Commit 8d8c7df

Browse files
zhaoxianhuagithubgxll
authored andcommitted
[fix][dingospeed] Fix that the proxy address is empty
1 parent 4a2e5d1 commit 8d8c7df

5 files changed

Lines changed: 42 additions & 9 deletions

File tree

config/config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ server:
1717

1818
scheduler:
1919
mode: cluster #运行的两种模式:standalone&cluster,default:standalone
20-
addr: 10.230.204.102:19091 # 调度器地址 10.230.204.102:19091
20+
addr: 10.230.203.240:19091 # 调度器地址 10.230.204.102:19091
2121
strategy: #在cluster模型下,文件调度策略
2222
minimumFileSize: 0 # 文件参与调度最小值,单位字节
2323
syncProcessInterval: 100 # 同步下载进度的间隔,默认是100个块同步1次。
2424
discovery: #在cluster模型下,服务上报到scheduler的信息
2525
instanceId: hd-01
26-
host: 10.230.204.102
26+
host: 10.230.203.240
2727
port: 8090
2828
heartbeatPeriod: 5 # 心跳周期,单位秒
2929
publicDomain: http://hfmirror.mas.zetyun.cn:8082
@@ -68,9 +68,9 @@ diskClean:
6868
collectTimePeriod: 1 #定期检测磁盘使用量时间周期,单位小时(H)
6969

7070
dynamicProxy:
71-
enabled: true #是否启用动态代理,当hfNetLoc配置的地址访问异常时,会自动切换到bpHfNetLoc。
72-
httpProxy: http://127.0.0.1:7890 #http://127.0.0.1:7890,科学上网代理地址
73-
httpProxyConnTest: true
71+
enabled: false #是否启用动态代理,当hfNetLoc配置的地址访问异常时,会自动切换到bpHfNetLoc。
72+
httpProxy: "" #http://127.0.0.1:7890,科学上网代理地址
73+
httpProxyConnTest: false #定时检测翻墙代理是否可用
7474
httpProxyName: "马鞍山服务器"
7575
timePeriod: 60 #定期检测代理是否可用时间周期,单位秒(S)
7676
maxContinuousFails: 5 #连续失败次数超过该值,则认为代理不可用

internal/service/task/mount_cache_task.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,15 @@ func (m *MountCacheTask) DoTask() {
4949
}
5050
defer logF.Close()
5151
hfEndpoint := fmt.Sprintf("http://%s:%d", config.SysConfig.Server.Host, config.SysConfig.Server.Port)
52-
cmd := exec.Command("hf", "download", "--repo-type",
53-
repoType, orgRepo, "--local-dir", localModelDir, "--token", getToken(m.Authorization))
52+
token := getToken(m.Authorization)
53+
var cmd *exec.Cmd
54+
if token != "" {
55+
cmd = exec.Command("hf", "download", "--repo-type",
56+
repoType, orgRepo, "--local-dir", localModelDir, "--token", token)
57+
} else {
58+
cmd = exec.Command("hf", "download", "--repo-type",
59+
repoType, orgRepo, "--local-dir", localModelDir)
60+
}
5461
cmd.Env = append(os.Environ(), fmt.Sprintf("HF_ENDPOINT=%s", hfEndpoint))
5562
cmd.Stdout = logF
5663
cmd.Stderr = logF

pkg/common/pool.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Pool struct {
4444
persist bool
4545
size int
4646
wg sync.WaitGroup
47+
mu sync.Mutex
4748
}
4849

4950
// NewPool 创建新协程池
@@ -80,12 +81,21 @@ func (p *Pool) worker() {
8081
}
8182
}
8283

84+
func (p *Pool) exist(taskNo int) bool {
85+
return p.taskMap.Exist(taskNo)
86+
}
87+
8388
func (p *Pool) GetTask(taskNo int) (Task, bool) {
8489
return p.taskMap.Get(taskNo)
8590
}
8691

8792
// Submit 提交任务
8893
func (p *Pool) Submit(ctx context.Context, task Task) error {
94+
p.mu.Lock()
95+
defer p.mu.Unlock()
96+
if p.persist && p.exist(task.GetTaskNo()) {
97+
return nil
98+
}
8999
select {
90100
case p.taskChan <- task:
91101
if p.persist {
@@ -98,6 +108,11 @@ func (p *Pool) Submit(ctx context.Context, task Task) error {
98108
}
99109

100110
func (p *Pool) SubmitForTimeout(ctx context.Context, task Task) error {
111+
p.mu.Lock()
112+
defer p.mu.Unlock()
113+
if p.persist && p.exist(task.GetTaskNo()) {
114+
return nil
115+
}
101116
select {
102117
case p.taskChan <- task:
103118
if p.persist {

pkg/common/safe_map.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ func (sm *SafeMap[K, V]) Get(key K) (V, bool) {
4040
return value, exists
4141
}
4242

43+
func (sm *SafeMap[K, V]) Exist(key K) bool {
44+
sm.mu.RLock()
45+
defer sm.mu.RUnlock()
46+
_, exists := sm.m[key]
47+
return exists
48+
}
49+
4350
func (sm *SafeMap[K, V]) Delete(key K) {
4451
sm.mu.Lock()
4552
defer sm.mu.Unlock()

pkg/util/http_util.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ func NewHTTPClientWithProxy(method string) (*http.Client, error) {
9999
return http.ErrUseLastResponse // 阻止跟随重定向
100100
},
101101
Timeout: config.SysConfig.GetReqTimeOut()}
102-
proxyHeadClient.Transport = transport
102+
if transport != nil {
103+
proxyHeadClient.Transport = transport
104+
}
103105
return proxyHeadClient, nil
104106
}
105107
proxyOnce.Do(func() {
106108
proxyClient = &http.Client{Timeout: config.SysConfig.GetReqTimeOut()}
107-
proxyClient.Transport = transport
109+
if transport != nil {
110+
proxyClient.Transport = transport
111+
}
108112
})
109113
return proxyClient, nil
110114
}

0 commit comments

Comments
 (0)