dragonflyoss / Dragonfly2

Dragonfly is an open source P2P-based file distribution and image acceleration system. It is hosted by the Cloud Native Computing Foundation (CNCF) as an Incubating Level Project.
https://d7y.io
Apache License 2.0
2.21k stars 281 forks source link

拉取hdfs失败 #881

Closed wciq1208 closed 2 years ago

wciq1208 commented 2 years ago

Bug report:

按照群内指引将 https://github.com/dragonflyoss/Dragonfly2/blob/v2.0.1/cmd/cdn/main.go 代码改为

/*
 *     Copyright 2020 The Dragonfly Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package main

import (
    "d7y.io/dragonfly/v2/cmd/cdn/cmd"

    // Register http client
    _ "d7y.io/dragonfly/v2/pkg/source/httpprotocol"

    // Register oss client
    _ "d7y.io/dragonfly/v2/pkg/source/ossprotocol"

    // Register hdfs client
    _ "d7y.io/dragonfly/v2/pkg/source/hdfsprotocol"
)

func main() {
    cmd.Execute()
}

重新编译后后运行还是拉取失败 运行命令

/data/app/k3-server/dragonfly/bin/dfget --url 'hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user' --console --show-progress -O test --limit 1K --disable-back-source --totallimit 1K -n --verbose 

dfget日志:

2021-12-07T13:48:37.153+0800    ERROR   dfdaemon/dfdaemon_grpc.pb.go:64 client receive a message: *dfdaemon.DownResult error: [1500]can not find client for supporting url hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user, clients:map[http:0xc00011e0c8 https:0xc00011e0c8 oss:0xc000130960] for method: /dfdaemon.Daemon/Download target: unix:///usr/local/dragonfly/daemon.sock connState: READY
d7y.io/dragonfly/v2/pkg/rpc/dfdaemon.(*daemonDownloadClient).Recv
    /mnt/sdb1/Dragonfly2/pkg/rpc/dfdaemon/dfdaemon_grpc.pb.go:64
d7y.io/dragonfly/v2/pkg/rpc/dfdaemon/client.(*DownResultStream).Recv
    /mnt/sdb1/Dragonfly2/pkg/rpc/dfdaemon/client/down_result_stream.go:100
d7y.io/dragonfly/v2/client/dfget.download
    /mnt/sdb1/Dragonfly2/client/dfget/dfget.go:96
d7y.io/dragonfly/v2/client/dfget.Download.func1
    /mnt/sdb1/Dragonfly2/client/dfget/dfget.go:63
2021-12-07T13:48:37.154+0800    WARN    dfget/dfget.go:120  daemon downloads file error: [1500]can not find client for supporting url hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user, clients:map[http:0xc00011e0c8 https:0xc00011e0c8 oss:0xc000130960]  {"url": "hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user"}
d7y.io/dragonfly/v2/client/dfget.download
    /mnt/sdb1/Dragonfly2/client/dfget/dfget.go:120
d7y.io/dragonfly/v2/client/dfget.Download.func1
    /mnt/sdb1/Dragonfly2/client/dfget/dfget.go:63
daemon downloads file error: [1500]can not find client for supporting url hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user, clients:map[http:0xc00011e0c8 https:0xc00011e0c8 oss:0xc000130960]
2021-12-07T13:48:37.154+0800    INFO    dfget/dfget.go:142  try to download from source and ignore rate limit   {"url": "hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user"}
try to download from source and ignore rate limit
2021-12-07T13:48:37.154+0800    DEBUG   source/source_client.go:223 current clients: map[string]source.ResourceClient{"http":(*httpprotocol.httpSourceClient)(0xc00011e200), "https":(*httpprotocol.httpSourceClient)(0xc00011e200), "oss":(*ossprotocol.ossSourceClient)(0xc00045cdc0)}
2021-12-07T13:48:37.154+0800    DEBUG   source/plugin.go:32 try to load source plugin: hdfs
2021-12-07T13:48:37.154+0800    ERROR   source/plugin.go:35 load source plugin error: plugin: not implemented
d7y.io/dragonfly/v2/pkg/source.LoadPlugin
    /mnt/sdb1/Dragonfly2/pkg/source/plugin.go:35
d7y.io/dragonfly/v2/pkg/source.(*clientManager).loadSourcePlugin
    /mnt/sdb1/Dragonfly2/pkg/source/source_client.go:250
d7y.io/dragonfly/v2/pkg/source.(*clientManager).getSourceClient
    /mnt/sdb1/Dragonfly2/pkg/source/source_client.go:232
d7y.io/dragonfly/v2/pkg/source.(*clientManager).Download
    /mnt/sdb1/Dragonfly2/pkg/source/source_client.go:115
d7y.io/dragonfly/v2/pkg/source.Download
    /mnt/sdb1/Dragonfly2/pkg/source/source_client.go:201
d7y.io/dragonfly/v2/client/dfget.downloadFromSource
    /mnt/sdb1/Dragonfly2/client/dfget/dfget.go:151
d7y.io/dragonfly/v2/client/dfget.download
    /mnt/sdb1/Dragonfly2/client/dfget/dfget.go:122
d7y.io/dragonfly/v2/client/dfget.Download.func1
    /mnt/sdb1/Dragonfly2/client/dfget/dfget.go:63
2021-12-07T13:48:37.154+0800    INFO    dependency/dependency.go:133    do 0 monitor finalizer
2021-12-07T13:48:37.154+0800    INFO    cmd/root.go:98  download success: false cost: 8 ms error: can not find client for supporting url hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user, clients:map[http:0xc00011e200 https:0xc00011e200 oss:0xc00045cdc0]   {"url": "hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user"}
download success: false cost: 8 ms error: can not find client for supporting url hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user, clients:map[http:0xc00011e200 https:0xc00011e200 oss:0xc00045cdc0]
Error: download url: hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user: can not find client for supporting url hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user, clients:map[http:0xc00011e200 https:0xc00011e200 oss:0xc00045cdc0]

daemon日志:

{"level":"debug","ts":"2021-12-07 13:39:33.895","caller":"source/source_client.go:223","msg":"current clients: map[string]source.ResourceClient{\"http\":(*httpprotocol.httpSourceClient)(0xc00011e0c8), \"https\":(*httpprotocol.httpSourceClient)(0xc00011e0c8), \"oss\":(*ossprotocol.ossSourceClient)(0xc000130960)}"}
{"level":"debug","ts":"2021-12-07 13:39:33.895","caller":"source/plugin.go:32","msg":"try to load source plugin: hdfs"}
{"level":"error","ts":"2021-12-07 13:39:33.895","caller":"source/plugin.go:35","msg":"load source plugin error: plugin: not implemented","stacktrace":"d7y.io/dragonfly/v2/pkg/source.LoadPlugin\n\t/mnt/sdb1/Dragonfly2/pkg/source/plugin.go:35\nd7y.io/dragonfly/v2/pkg/source.(*clientManager).loadSourcePlugin\n\t/mnt/sdb1/Dragonfly2/pkg/source/source_client.go:250\nd7y.io/dragonfly/v2/pkg/source.(*clientManager).getSourceClient\n\t/mnt/sdb1/Dragonfly2/pkg/source/source_client.go:232\nd7y.io/dragonfly/v2/pkg/source.(*clientManager).GetContentLength\n\t/mnt/sdb1/Dragonfly2/pkg/source/source_client.go:76\nd7y.io/dragonfly/v2/pkg/source.GetContentLength\n\t/mnt/sdb1/Dragonfly2/pkg/source/source_client.go:181\nd7y.io/dragonfly/v2/client/daemon/peer.(*pieceManager).DownloadSource\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/piece_manager.go:350\nd7y.io/dragonfly/v2/client/daemon/peer.(*filePeerTask).backSource\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_file.go:472\nd7y.io/dragonfly/v2/client/daemon/peer.(*peerTask).backSource\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_base.go:198\nd7y.io/dragonfly/v2/client/daemon/peer.(*peerTask).waitFirstPeerPacket\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_base.go:535\nd7y.io/dragonfly/v2/client/daemon/peer.(*peerTask).pullPiecesFromPeers\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_base.go:386"}
{"level":"warn","ts":"2021-12-07 13:39:33.895","caller":"peer/piece_manager.go:352","msg":"get content length error: can not find client for supporting url hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user, clients:map[http:0xc00011e0c8 https:0xc00011e0c8 oss:0xc000130960] for hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user","peer":"172.21.240.15-226-ac23083d-0109-4751-b119-51c2c00fc359","task":"a6ce04b1f88cf0d645140cd23c5b41823c7738c70f81d1529540911e19ba5b72","component":"filePeerTask","stacktrace":"d7y.io/dragonfly/v2/client/daemon/peer.(*pieceManager).DownloadSource\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/piece_manager.go:352\nd7y.io/dragonfly/v2/client/daemon/peer.(*filePeerTask).backSource\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_file.go:472\nd7y.io/dragonfly/v2/client/daemon/peer.(*peerTask).backSource\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_base.go:198\nd7y.io/dragonfly/v2/client/daemon/peer.(*peerTask).waitFirstPeerPacket\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_base.go:535\nd7y.io/dragonfly/v2/client/daemon/peer.(*peerTask).pullPiecesFromPeers\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_base.go:386"}
{"level":"warn","ts":"2021-12-07 13:39:33.895","caller":"peer/piece_manager.go:355","msg":"can not get content length for hdfs://jssz-bigdata-cluster/department/ai/recsys/online_data/paying_user","peer":"172.21.240.15-226-ac23083d-0109-4751-b119-51c2c00fc359","task":"a6ce04b1f88cf0d645140cd23c5b41823c7738c70f81d1529540911e19ba5b72","component":"filePeerTask","stacktrace":"d7y.io/dragonfly/v2/client/daemon/peer.(*pieceManager).DownloadSource\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/piece_manager.go:355\nd7y.io/dragonfly/v2/client/daemon/peer.(*filePeerTask).backSource\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_file.go:472\nd7y.io/dragonfly/v2/client/daemon/peer.(*peerTask).backSource\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_base.go:198\nd7y.io/dragonfly/v2/client/daemon/peer.(*peerTask).waitFirstPeerPacket\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_base.go:535\nd7y.io/dragonfly/v2/client/daemon/peer.(*peerTask).pullPiecesFromPeers\n\t/mnt/sdb1/Dragonfly2/client/daemon/peer/peertask_base.go:386"}
{"level":"debug","ts":"2021-12-07 13:39:33.895","caller":"peer/piece_manager.go:369","msg":"get content length: -1","peer":"172.21.240.15-226-ac23083d-0109-4751-b119-51c2c00fc359","task":"a6ce04b1f88cf0d645140cd23c5b41823c7738c70f81d1529540911e19ba5b72","component":"filePeerTask"}
{"level":"debug","ts":"2021-12-07 13:39:33.895","caller":"source/source_client.go:223","msg":"current clients: map[string]source.ResourceClient{\"http\":(*httpprotocol.httpSourceClient)(0xc00011e0c8), \"https\":(*httpprotocol.httpSourceClient)(0xc00011e0c8), \"oss\":(*ossprotocol.ossSourceClient)(0xc000130960)}"}

cdn上未看到报错

Expected behavior:

基于v2.0.1修改

How to reproduce it:

Environment:

wciq1208 commented 2 years ago

在dfget的入口也添加

_ "d7y.io/dragonfly/v2/pkg/source/hdfsprotocol"

后该错误解决


但是有了新的问题;我们的集群需要通过k8s的keytab认证登陆,看了代码似乎暂时不支持,只能自己魔改一下

jim3ma commented 2 years ago

在dfget的入口也添加

_ "d7y.io/dragonfly/v2/pkg/source/hdfsprotocol"

后该错误解决

但是有了新的问题;我们的集群需要通过k8s的keytab认证登陆,看了代码似乎暂时不支持,只能自己魔改一下

可以自己添加 keytab 认证的

wciq1208 commented 2 years ago

经过不懈努力,最后终于调通了 我对 https://github.com/dragonflyoss/Dragonfly2/blob/v2.0.1/pkg/source/hdfsprotocol/hdfs_source_client.go#L203 函数作了如下魔改:

  1. 由于go的hdfs库缺陷,不支持viewfs解析,所以找hadoop平台方调教了一个特供版的hadoop配置
  2. 使用keytab登陆
  3. 注释掉地址和用户的赋值代码

主要解决不知道集群地址和有权限验证的情况

    hadoopConfDir := os.Getenv("DRAGONFLY_HADOOP_CONF")
    if hadoopConfDir == "" {
        hadoopConfDir = "/etc/hadoop"
    }
    hadoopConf, err := hadoopconf.Load(hadoopConfDir)
    if err != nil {
        return nil, err
    }

    // create client option
    options := hdfs.ClientOptionsFromConf(hadoopConf)

    k8sCfg, err := k8s_config.Load("/etc/krb5.conf")
    if err != nil {
        return nil, err
    }
    k8sKey, err := keytab.Load("/home/ai/ai.keytab")
    if err != nil {
        return nil, err
    }
    var user = "ai"
    options.KerberosClient = k8s_client.NewWithKeytab(user, "BILIBILI.CO", k8sKey, k8sCfg)
    dialFunc := (&net.Dialer{
        Timeout:   10 * time.Second,
        KeepAlive: 120 * time.Second,
    }).DialContext
    options.NamenodeDialFunc = dialFunc
    options.DatanodeDialFunc = dialFunc
    err = options.KerberosClient.Login()
    if err != nil {
        return nil, err
    }

    /*options.Addresses = strings.Split(parse.Host, ",")
    u, err := user.Current()
    if err != nil {
        return nil, err
    }
    options.User = u.Username*/
jim3ma commented 2 years ago

这个版本应该不通用吧,所以我觉得可以用 plugin 的方式,实现一遍,参考地址:https://github.com/dragonflyoss/Dragonfly2/blob/main/docs/en/developer-guide/plugin.md,(接口有变更,注意修改,近期会更新一下最新文档)

gaius-qi commented 2 years ago

Please refer to https://d7y.netlify.app/docs/contribute/development-guide/plugin/