# Tencent COS

This guide describes how to configure Alluxio with Tencent [COS](https://cloud.tencent.com/product/cos) (Cloud Object Storage) as the under storage system.\
Tencent Cloud Object Storage (COS) is a distributed storage service offered by Tencent Cloud for massive data and accessible via HTTP/HTTPS protocols. It can store massive amounts of data and features imperceptible bandwidth and capacity expansion, making it a perfect data pool for big data computation and analytics.

## Prerequisites

Alluxio runs on multiple machines in cluster mode so its binary package needs to be deployed on the machines.

Before using COS with Alluxio, either create a new bucket or use an existing one. Additionally, identify the directory you wish to use within that bucket, whether by creating a new directory or selecting an existing one. For this guide, the COS bucket name is `COS_BUCKET`, the directory within the bucket is `COS_DATA`, and the bucket region is `COS_REGION`.

## Basic Setup

For the general mount mechanism and `UnderFileSystem` CR field reference, see [Underlying Storage](https://documentation.alluxio.io/ee-ai-en/ufs/..#basic-mount-setup).

{% tabs %}
{% tab title="Kubernetes (Operator)" %}
An example `ufs.yaml` to create a COS mount point with the operator:

```yaml
apiVersion: k8s-operator.alluxio.com/v1
kind: UnderFileSystem
metadata:
  name: alluxio-cos
  namespace: alx-ns
spec:
  alluxioCluster: alluxio-cluster
  path: cos://<COS_BUCKET>/<COS_DIRECTORY>
  mountPath: /cos
  mountOptions:
    fs.cos.access.key: <COS_ACCESS_KEY>
    fs.cos.secret.key: <COS_ACCESS_KEY_SECRET>
    fs.cos.region: <COS_REGION>
    fs.cos.app.id: <COS_APP_ID>
```

{% endtab %}

{% tab title="Docker / Bare-Metal" %}
An example command to mount `cos://<COS_ALLUXIO_BUCKET>/<COS_DATA>` to `/cos` if not using the operator:

```shell
bin/alluxio mount add --path /cos/ --ufs-uri cos://<COS_BUCKET>/<COS_DATA> \
  --option fs.cos.access.key=<COS_SECRET_ID> --option fs.cos.secret.key=<COS_SECRET_KEY> \
  --option fs.cos.region=<COS_REGION> --option fs.cos.app.id=<COS_APP_ID>
```

Note that if you want to mount the root of the COS bucket, add a trailing slash after the bucket name (e.g. `cos://COS_BUCKET/`).
{% endtab %}
{% endtabs %}

{% hint style="info" %}
The full name of a COS bucket is `<COS_BUCKET>-<COS_APP_ID>`. The value of the `path` should only include the `<COS_BUCKET>` portion with the `<COS_APP_ID>` part omitted, resulting in `cos://<COS_BUCKET>/<COS_DIRECTORY>`. Make sure to set `fs.cos.app.id` to `<COS_APP_ID>`.
{% endhint %}

## Advanced Setup

Note that configuration options can be specified as mount options or as configuration properties in `conf/alluxio-site.properties`.\
The following sections will describe how to set configurations as properties, but they can also be set as mount options via `--option <key>=<value>`.

### Enabling HTTPS

To enable the use of the HTTPS protocol for secure communication with COS with an additional layer of security for data transfers, configure the following setting in conf/alluxio-site.properties:

```properties
alluxio.underfs.cos.secure.http.enabled=true
```

### COS multipart upload

We use multipart-upload method to upload one file by multiple parts, every part will be uploaded in one thread. It won't generate any temporary files while uploading.

There are other parameters you can specify in `conf/alluxio-site.properties` to potentially speed up the upload.

```properties
# Timeout for uploading part when using multipart upload.
alluxio.underfs.object.store.multipart.upload.timeout

# Thread pool size for COS multipart upload.
alluxio.underfs.cos.multipart.upload.threads

# Multipart upload partition size for COS. The default partition size is 16MB.
alluxio.underfs.cos.multipart.upload.part.size
```

Disable COS multipart upload, the upload method uploads one file completely from start to end in one go. you need to modify `conf/alluxio-site.properties` to include:

```properties
alluxio.underfs.cos.multipart.upload.enabled=false
```

### Setting Request Retry Policy

For retry configuration that applies to all object store UFS types, see [Request Retry Policy](https://documentation.alluxio.io/ee-ai-en/ufs/..#request-retry-policy) in the UFS overview.
