Use Aliyun OSS offloader with Pulsar

This chapter guides you through every step of installing and configuring the Aliyun Object Storage Service (OSS) offloader and using it with Pulsar.

Installation

Follow the steps below to install the Aliyun OSS offloader.

Prerequisite

  • Pulsar: 2.8.0 or later versions

Step

This example uses Pulsar 2.8.0.

  1. Download the Pulsar tarball, see here.

  2. Download and untar the Pulsar offloaders package, then copy the Pulsar offloaders as offloaders in the Pulsar directory, see here.

    Output

    As shown from the output, Pulsar uses Apache jclouds to support AWS S3, GCS, Azure, and Aliyun OSS for long-term storage.

    1. tiered-storage-file-system-2.8.0.nar
    2. tiered-storage-jcloud-2.8.0.nar
  1. ##### note
  2. - If you are running Pulsar in a bare-metal cluster, make sure that `offloaders` tarball is unzipped in every broker's Pulsar directory.
  3. - If you are running Pulsar in Docker or deploying Pulsar using a Docker image (such as K8s and DCOS), you can use the `apachepulsar/pulsar-all` image. The `apachepulsar/pulsar-all` image has already bundled tiered storage offloaders.

Configuration

note

Before offloading data from BookKeeper to Aliyun OSS, you need to configure some properties of the Aliyun OSS offload driver.

Besides, you can also configure the Aliyun OSS offloader to run it automatically or trigger it manually.

Configure Aliyun OSS offloader driver

You can configure the Aliyun OSS offloader driver in the configuration file broker.conf or standalone.conf.

  • Required configurations are as below.

    Required configurationDescriptionExample value
    managedLedgerOffloadDriverOffloader driver name, which is case-insensitive.aliyun-oss
    offloadersDirectoryOffloader directoryoffloaders
    managedLedgerOffloadBucketBucketpulsar-topic-offload
    managedLedgerOffloadServiceEndpointEndpointhttp://oss-cn-hongkong.aliyuncs.com
  • Optional configurations are as below.

    OptionalDescriptionExample value
    managedLedgerOffloadReadBufferSizeInBytesSize of block read1 MB
    managedLedgerOffloadMaxBlockSizeInBytesSize of block write64 MB
    managedLedgerMinLedgerRolloverTimeMinutesMinimum time between ledger rollover for a topic

    Note: it is not recommended that you set this configuration in the production environment.
    2
    managedLedgerMaxEntriesPerLedgerMaximum number of entries to append to a ledger before triggering a rollover.

    Note: it is not recommended that you set this configuration in the production environment.
    5000

Bucket (required)

A bucket is a basic container that holds your data. Everything you store in Aliyun OSS must be contained in a bucket. You can use a bucket to organize your data and control access to your data, but unlike directory and folder, you cannot nest a bucket.

Example

This example names the bucket as pulsar-topic-offload.

  1. managedLedgerOffloadBucket=pulsar-topic-offload

Endpoint (required)

The endpoint is the region where a bucket is located.

tip

For more information about Aliyun OSS regions and endpoints, see International website or Chinese website.

Example

This example sets the endpoint as oss-us-west-1-internal.

  1. managedLedgerOffloadServiceEndpoint=http://oss-us-west-1-internal.aliyuncs.com

Authentication (required)

To be able to access Aliyun OSS, you need to authenticate with Aliyun OSS.

Set the environment variables ALIYUN_OSS_ACCESS_KEY_ID and ALIYUN_OSS_ACCESS_KEY_SECRET in conf/pulsar_env.sh.

“export” is important so that the variables are made available in the environment of spawned processes.

  1. export ALIYUN_OSS_ACCESS_KEY_ID=ABC123456789
  2. export ALIYUN_OSS_ACCESS_KEY_SECRET=ded7db27a4558e2ea8bbf0bf37ae0e8521618f366c

Size of block read/write

You can configure the size of a request sent to or read from Aliyun OSS in the configuration file broker.conf or standalone.conf.

ConfigurationDescriptionDefault value
managedLedgerOffloadReadBufferSizeInBytesBlock size for each individual read when reading back data from Aliyun OSS.1 MB
managedLedgerOffloadMaxBlockSizeInBytesMaximum size of a “part” sent during a multipart upload to Aliyun OSS. It cannot be smaller than 5 MB.64 MB

Run Aliyun OSS offloader automatically

Namespace policy can be configured to offload data automatically once a threshold is reached. The threshold is based on the size of data that a topic has stored on a Pulsar cluster. Once the topic reaches the threshold, an offloading operation is triggered automatically.

Threshold valueAction
> 0It triggers the offloading operation if the topic storage reaches its threshold.
= 0It causes a broker to offload data as soon as possible.
< 0It disables automatic offloading operation.

Automatic offloading runs when a new segment is added to a topic log. If you set the threshold on a namespace, but few messages are being produced to the topic, the offloader does not work until the current segment is full.

You can configure the threshold size using CLI tools, such as pulsar-admin.

The offload configurations in broker.conf and standalone.conf are used for the namespaces that do not have namespace level offload policies. Each namespace can have its own offload policy. If you want to set offload policy for each namespace, use the command pulsar-admin namespaces set-offload-policies options command.

Example

This example sets the Aliyun OSS offloader threshold size to 10 MB using pulsar-admin.

  1. bin/pulsar-admin namespaces set-offload-threshold --size 10M my-tenant/my-namespace
tip

For more information about the pulsar-admin namespaces set-offload-threshold options command, including flags, descriptions, and default values, see here.

Run Aliyun OSS offloader manually

For individual topics, you can trigger the Aliyun OSS offloader manually using one of the following methods:

  • Use REST endpoint.

  • Use CLI tools (such as pulsar-admin).

    To trigger it via CLI tools, you need to specify the maximum amount of data (threshold) that should be retained on a Pulsar cluster for a topic. If the size of the topic data on the Pulsar cluster exceeds this threshold, segments from the topic are moved to Aliyun OSS until the threshold is no longer exceeded. Older segments are moved first.

Example

  • This example triggers the Aliyun OSS offloader to run manually using pulsar-admin.

    1. bin/pulsar-admin topics offload --size-threshold 10M my-tenant/my-namespace/topic1
  1. **Output**
  2. ```
  3. Offload triggered for persistent://my-tenant/my-namespace/topic1 for messages before 2:0:-1
  4. ```
  5. ##### tip
  6. For more information about the `pulsar-admin topics offload options` command, including flags, descriptions, and default values, see [here](https://pulsar.apache.org/tools/pulsar-admin/2.6.0-SNAPSHOT/#-em-offload-em-).
  • This example checks the Aliyun OSS offloader status using pulsar-admin.

    1. bin/pulsar-admin topics offload-status persistent://my-tenant/my-namespace/topic1
  1. **Output**
  2. ```
  3. Offload is currently running
  4. ```
  5. To wait for the Aliyun OSS offloader to complete the job, add the `-w` flag.
  6. ```
  7. bin/pulsar-admin topics offload-status -w persistent://my-tenant/my-namespace/topic1
  8. ```
  9. **Output**
  10. ```
  11. Offload was a success
  12. ```
  13. If there is an error in offloading, the error is propagated to the `pulsar-admin topics offload-status` command.
  14. ```
  15. bin/pulsar-admin topics offload-status persistent://my-tenant/my-namespace/topic1
  16. ```
  17. **Output**
  18. ```
  19. Error in offload
  20. null
  21. Reason: Error offloading: org.apache.bookkeeper.mledger.ManagedLedgerException: java.util.concurrent.CompletionException: com.amazonaws.services.s3.model.AmazonS3Exception: Anonymous users cannot initiate multipart uploads. Please authenticate. (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: 798758DE3F1776DF; S3 Extended Request ID: dhBFz/lZm1oiG/oBEepeNlhrtsDlzoOhocuYMpKihQGXe6EG8puRGOkK6UwqzVrMXTWBxxHcS+g=), S3 Extended Request ID: dhBFz/lZm1oiG/oBEepeNlhrtsDlzoOhocuYMpKihQGXe6EG8puRGOkK6UwqzVrMXTWBxxHcS+g=
  22. ```
  23. ##### tip
  24. For more information about the `pulsar-admin topics offload-status options` command, including flags, descriptions, and default values, see [here](https://pulsar.apache.org/tools/pulsar-admin/2.6.0-SNAPSHOT/#-em-offload-status-em-).