Alluxio
ProductsLanguageHome
  • Alluxio概览
  • 用户指南
    • 快速上手指南
    • 架构
    • FAQ
    • 作业服务器
    • 应用场景
  • 核心功能
    • 缓存
    • 统一命名空间
  • 部署 Alluxio
    • 在Kubernetes上部署Alluxio
    • 本地运行Alluxio
    • 在集群上独立运行Alluxio
    • 在Docker上运行Alluxio
    • 在具有HA的群集上部署Alluxio
    • 使用Docker部署AlluxioFuse加速深度学习训练(试验)
    • 基本要求
  • 云源生
    • Tencent EMR
  • 计算应用
    • Apache Spark
    • Presto
    • Spark on Kubernetes
    • Apache Flink
    • Apache Hadoop MapReduce
    • Presto on Iceberg (Experimental)
    • Trino
    • Apache Hive
    • 深度学习框架
    • Tensorflow
  • 底层存储系统
    • Alluxio集成Amazon AWS S3作为底层存储
    • Alluxio集成GCS作为底层存储
    • Alluxio集成Azure Blob Store作为底层存储
    • Azure Data Lake Storage Gen2
    • Azure 数据湖存储
    • Alluxio集成HDFS作为底层存储
    • Alluxio集成COS作为底层存储
    • Alluxio集成COSN作为底层存储
    • Alluxio集成Ceph Object Storage作为底层存储
    • Alluxio集成NFS作为底层存储
    • Alluxio集成Kodo作为底层存储
    • Alluxio集成Swift作为底层存储
    • Alluxio集成WEB作为底层存储
    • Alluxio集成Minio作为底层存储
    • 阿里云对象存储服务
    • Alluxio集成Ozone作为底层存储
    • Alluxio集成CephFS作为底层存储
  • 安全设置
    • 安全性
  • 运维指南
    • 配置项设置
    • 命令行接口
    • 管理员命令行接口
    • Web界面
    • 日志
    • 度量指标系统
    • 远程记录日志
  • 管理
    • 升级
    • 异常诊断与调试
  • APIs
    • Filesystem API
    • S3 Client
    • POSIX API
    • REST API
    • Python Client
    • 兼容Hadoop的Java
    • Go 客户端
  • 开发者资源
    • 编译Alluxio源代码
    • 开发指南
    • 代码规范
    • 如何开发单元测试
    • 文档规范
  • 参考
    • 配置项列表
    • List of Metrics
  • REST API
    • Master REST API
    • Worker REST API
    • Proxy REST API
    • Job REST API
  • Javadoc
Powered by GitBook
On this page
  • Go 客户端
  • Alluxio 代理依赖
  • 安装Go语言客户端相关库
  • 示例使用程序
  1. APIs

Go 客户端

Last updated 6 months ago

Go 客户端

Alluxio有一个, 此客户端通过 和Alluxio进行交互。Go 客户端提供一个和相似的API。 查看 获取所有可用接口的详细信息,godoc包括如何下载,上传Alluxio中的文件,检查文件是否 存在,列出文件状态等信息。

Alluxio 代理依赖

Go 语言客户端通过Alluxio代理提供的REST API和Alluxio进行交互。

Alluxio代理是一个独立运行的server,可通过命令${ALLUXIO_HOME}/bin/alluxio-start.sh proxy启动, ${ALLUXIO_HOME}/bin/alluxio-stop.sh proxy停止服务,默认情况下,REST API使用端口39999。

使用HTTP代理会影响性能,尤其是在使用代理时会增加一个额外的跳计数,所以推荐让代理服务和一个Alluxio worker运行在一个计算节点上。

安装Go语言客户端相关库

$ go get -d github.com/Alluxio/alluxio-go

示例使用程序

如果本地没有Alluxio代理在运行,将下面的"localhost"替换为代理的主机名。

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"strings"
	"time"

	alluxio "github.com/alluxio/alluxio-go"
	"github.com/alluxio/alluxio-go/option"
)

func write(fs *alluxio.Client, path, s string) error {
	id, err := fs.CreateFile(path, &option.CreateFile{})
	if err != nil {
		return err
	}
	defer fs.Close(id)
	_, err = fs.Write(id, strings.NewReader(s))
	return err
}

func read(fs *alluxio.Client, path string) (string, error) {
	id, err := fs.OpenFile(path, &option.OpenFile{})
	if err != nil {
		return "", err
	}
	defer fs.Close(id)
	r, err := fs.Read(id)
	if err != nil {
		return "", err
	}
	defer r.Close()
	content, err := ioutil.ReadAll(r)
	if err != nil {
		return "", err
	}
	return string(content), err
}

func main() {
	fs := alluxio.NewClient("localhost", 39999, 10*time.Second)
	path := "/test_path"
	exists, err := fs.Exists(path, &option.Exists{})
	if err != nil {
		log.Fatal(err)
	}
	if exists {
		if err := fs.Delete(path, &option.Delete{}); err != nil {
			log.Fatal(err)
		}
	}
	if err := write(fs, path, "Success"); err != nil {
		log.Fatal(err)
	}
	content, err := read(fs, path)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Result: %v\n", content)
}
Go 语言客户端
REST API
原生文件系统Java客户端
godoc