forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue 3458: Tag Pulsar ledgers in order to distinguish from other le…
…ggers in the same Bookkeeper cluster (apache#3525) Fixes apache#3458 ### Motivation See apache#3458 ### Modifications Add a new LedgerMetadataUtils class which holds the logic for building "metadata" to be attached to ### Verifying this change This change is a trivial rework / code cleanup without any test coverage.
- Loading branch information
Showing
7 changed files
with
157 additions
and
20 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/LedgerMetadataUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.bookkeeper.mledger.impl; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
|
||
/** | ||
* Utilities for managing BookKeeper Ledgers custom metadata. | ||
*/ | ||
public final class LedgerMetadataUtils { | ||
|
||
private static final String METADATA_PROPERTY_APPLICATION = "application"; | ||
private static final byte[] METADATA_PROPERTY_APPLICATION_PULSAR | ||
= "pulsar".getBytes(StandardCharsets.UTF_8); | ||
|
||
private static final String METADATA_PROPERTY_COMPONENT = "component"; | ||
private static final byte[] METADATA_PROPERTY_COMPONENT_MANAGED_LEDGER | ||
= "managed-ledger".getBytes(StandardCharsets.UTF_8); | ||
private static final byte[] METADATA_PROPERTY_COMPONENT_COMPACTED_LEDGER | ||
= "compacted-ledger".getBytes(StandardCharsets.UTF_8); | ||
private static final byte[] METADATA_PROPERTY_COMPONENT_SCHEMA | ||
= "schema".getBytes(StandardCharsets.UTF_8); | ||
|
||
private static final String METADATA_PROPERTY_MANAGED_LEDGER_NAME = "pulsar/managed-ledger"; | ||
private static final String METADATA_PROPERTY_CURSOR_NAME = "pulsar/cursor"; | ||
private static final String METADATA_PROPERTY_COMPACTEDTOPIC = "pulsar/compactedTopic"; | ||
private static final String METADATA_PROPERTY_COMPACTEDTO = "pulsar/compactedTo"; | ||
private static final String METADATA_PROPERTY_SCHEMAID = "pulsar/schemaId"; | ||
|
||
/** | ||
* Build base metadata for every ManagedLedger. | ||
* | ||
* @param name the name of the ledger | ||
* @return an immutable map which describes a ManagedLedger | ||
*/ | ||
static Map<String, byte[]> buildBaseManagedLedgerMetadata(String name) { | ||
return ImmutableMap.of( | ||
METADATA_PROPERTY_APPLICATION, METADATA_PROPERTY_APPLICATION_PULSAR, | ||
METADATA_PROPERTY_COMPONENT, METADATA_PROPERTY_COMPONENT_MANAGED_LEDGER, | ||
METADATA_PROPERTY_MANAGED_LEDGER_NAME, name.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
/** | ||
* Build additional metadata for a Cursor. | ||
* | ||
* @param name the name of the cursor | ||
* @return an immutable map which describes the cursor | ||
* @see #buildBaseManagedLedgerMetadata(java.lang.String) | ||
*/ | ||
static Map<String, byte[]> buildAdditionalMetadataForCursor(String name) { | ||
return ImmutableMap.of(METADATA_PROPERTY_CURSOR_NAME, name.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
/** | ||
* Build additional metadata for a CompactedLedger. | ||
* | ||
* @param compactedTopic reference to the compacted topic. | ||
* @param compactedToMessageId last mesasgeId. | ||
* @return an immutable map which describes the compacted ledger | ||
*/ | ||
public static Map<String, byte[]> buildMetadataForCompactedLedger(String compactedTopic, byte[] compactedToMessageId) { | ||
return ImmutableMap.of( | ||
METADATA_PROPERTY_APPLICATION, METADATA_PROPERTY_APPLICATION_PULSAR, | ||
METADATA_PROPERTY_COMPONENT, METADATA_PROPERTY_COMPONENT_COMPACTED_LEDGER, | ||
METADATA_PROPERTY_COMPACTEDTOPIC, compactedTopic.getBytes(StandardCharsets.UTF_8), | ||
METADATA_PROPERTY_COMPACTEDTO, compactedToMessageId | ||
); | ||
} | ||
|
||
/** | ||
* Build additional metadata for a Schema | ||
* | ||
* @param schemaId id of the schema | ||
* @return an immutable map which describes the schema | ||
*/ | ||
public static Map<String, byte[]> buildMetadataForSchema(String schemaId) { | ||
return ImmutableMap.of( | ||
METADATA_PROPERTY_APPLICATION, METADATA_PROPERTY_APPLICATION_PULSAR, | ||
METADATA_PROPERTY_COMPONENT, METADATA_PROPERTY_COMPONENT_SCHEMA, | ||
METADATA_PROPERTY_SCHEMAID, schemaId.getBytes(StandardCharsets.UTF_8) | ||
); | ||
} | ||
|
||
private LedgerMetadataUtils() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
id: cookbooks-bookkeepermetadata | ||
title: BookKeeper Ledger Metadata | ||
--- | ||
|
||
Pulsar stores data on BookKeeper ledgers, you can understand the contents of a ledger by inspecting the metadata attached to the ledger. | ||
Such metadata are stored on ZooKeeper and they are readable using BookKeeper APIs. | ||
|
||
Description of current metadata: | ||
|
||
| Scope | Metadata name | Metadata value | | ||
| ------------- | ------------- | ------------- | | ||
| All ledgers | application | 'pulsar' | | ||
| All ledgers | component | 'managed-ledger', 'schema', 'compacted-topic' | | ||
| Managed ledgers | pulsar/managed-ledger | name of the ledger | | ||
| Cursor | pulsar/cursor | name of the cursor | | ||
| Compacted topic | pulsar/compactedTopic | name of the original topic | | ||
| Compacted topic | pulsar/compactedTo | id of the last compacted message | | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters