Use GCS offloader with Pulsar
Follow the steps below to install the GCS offloader.
- Pulsar: 2.4.2 or later versions
This example uses Pulsar 2.5.1.
Download the Pulsar tarball using one of the following ways:
Download from the
Download from the Pulsar download page
Use
Download and untar the Pulsar offloaders package.
tar xvfz apache-pulsar-offloaders-2.5.1-bin.tar.gz
Copy the Pulsar offloaders as
offloaders
in the Pulsar directory.mv apache-pulsar-offloaders-2.5.1/offloaders apache-pulsar-2.5.1/offloaders
ls offloaders
输出
As shown in the output, Pulsar uses Apache jclouds to support GCS and AWS S3 for long term storage.
```
tiered-storage-file-system-2.5.1.nar
tiered-storage-jcloud-2.5.1.nar
Note
Before offloading data from BookKeeper to GCS, you need to configure some properties of the GCS offloader driver.
Besides, you can also configure the GCS offloader to run it automatically or trigger it manually.
You can configure GCS offloader driver in the configuration file broker.conf
or standalone.conf
.
Required configurations are as below.
Required configuration | Description | Example value |—-|—-|—-
managedLedgerOffloadDriver
|Offloader driver name, which is case-insensitive.|google-cloud-storage |Offloader directory|offloadersgcsManagedLedgerOffloadBucket
|Bucket|pulsar-topic-offloadgcsManagedLedgerOffloadRegion
|Bucket region|europe-west3gcsManagedLedgerOffloadServiceAccountKeyFile
|Authentication |/Users/user-name/Downloads/project-804d5e6a6f33.jsonOptional configurations are as below.
Optional configuration|Description|Example value |—-|—-|—-
gcsManagedLedgerOffloadReadBufferSizeInBytes
|Size of block read|1 MBgcsManagedLedgerOffloadMaxBlockSizeInBytes
|Size of block write|64 MBmanagedLedgerMinLedgerRolloverTimeMinutes
|Minimum time between ledger rollover for a topic.|2managedLedgerMaxEntriesPerLedger
|The max number of entries to append to a ledger before triggering a rollover.|5000
Bucket (required)
A bucket is a basic container that holds your data. Everything you store in GCS 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 can not nest a bucket.
示例
This example names the bucket as pulsar-topic-offload.
gcsManagedLedgerOffloadBucket=pulsar-topic-offload
Bucket region (required)
Tip
For more information about bucket location, see here.
示例
This example sets the bucket region as europe-west3.
Authentication (required)
To enable a broker access GCS, you need to configure gcsManagedLedgerOffloadServiceAccountKeyFile
in the configuration file broker.conf
.
gcsManagedLedgerOffloadServiceAccountKeyFile
is a JSON file, containing GCS credentials of a service account.
示例
To generate service account credentials or view the public credentials that you’ve already generated, follow the following steps.
Navigate to the Service accounts page.
选择一个项目或创建一个新项目。
Click Create service account.
In the Create service account window, type a name for the service account and select Furnish a new private key.
If you want to to the service account, select Enable G Suite Domain-wide Delegation.
Click Create.
You can get the following information and set this in
broker.conf
.gcsManagedLedgerOffloadServiceAccountKeyFile="/Users/user-name/Downloads/project-804d5e6a6f33.json"
Tip
For more information about how to create
gcsManagedLedgerOffloadServiceAccountKeyFile
, see .For more information about Google Cloud IAM, see here.
Size of block read/write
You can configure the size of a request sent to or read from GCS in the configuration file broker.conf
.
Configuration|Description |—-|—- gcsManagedLedgerOffloadReadBufferSizeInBytes
|Block size for each individual read when reading back data from GCS.
The default value is 1 MB. |Maximum size of a “part” sent during a multipart upload to GCS.
It can not be smaller than 5 MB.
The default value is 64 MB.
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 offload operation is triggered automatically.
0 | It triggers the offloading operation if the topic storage reaches its threshold. = 0|It causes a broker to offload data as soon as possible. < 0 |It 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, 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.
示例
This example sets the GCS offloader threshold size to 10 MB using pulsar-admin.
pulsar-admin namespaces set-offload-threshold --size 10M my-tenant/my-namespace
For individual topics, you can trigger GCS offloader manually using one of the following methods:
Use REST endpoint.
Use CLI tools (such as pulsar-admin).
To trigger the GCS 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 GCS until the threshold is no longer exceeded. Older segments are moved first.
示例
This example triggers the GCS offloader to run manually using pulsar-admin with the command
pulsar-admin topics offload (topic-name) (threshold)
.pulsar-admin topics offload persistent://my-tenant/my-namespace/topic1 10M
输出
Offload triggered for persistent://my-tenant/my-namespace/topic1 for messages before 2:0:-1
Tip
For more information about the
pulsar-admin topics offload options
command, including flags, descriptions, default values, and shorthands, see [here]((reference-pulsar-admin.md#offload).This example checks the GCS offloader status using pulsar-admin with the command
pulsar-admin topics offload-status options
.输出
Offload is currently running
To wait for GCS to complete the job, add the
-w
flag.pulsar-admin topics offload-status -w persistent://my-tenant/my-namespace/topic1
输出
If there is an error in offloading, the error is propagated to the
pulsar-admin topics offload-status
command.pulsar-admin topics offload-status persistent://my-tenant/my-namespace/topic1
输出
Tip
For more information about the
pulsar-admin topics offload-status options
command, including flags, descriptions, default values, and shorthands, see .
For the complete and step-by-step instructions on how to use the GCS offloader with Pulsar, see here.