From 02c838c990543200c05f3d1479d74e685f895bba Mon Sep 17 00:00:00 2001 From: Yan Zhao Date: Mon, 10 Apr 2023 22:49:29 +0800 Subject: [PATCH] [fix][broker]Make LedgerOffloaderFactory can load the old nar. (#19913) After #13833, we change the signature of LedgerOffloaderFactory#create. But some users may use the old version LedgerOffloaderFactory in the offloader nar, when pulsar load the offloader nar, it will use the LedgerOffloaderFactory in the offloader nar, the LedgerOffloaderFactory#create has no param offloaderStats. Modifications: Make LedgerOffloaderFactory can load the old nar. --- .../mledger/LedgerOffloaderFactory.java | 39 ++++++++++++++++++- .../mledger/LedgerOffloaderStatsDisable.java | 4 +- .../FileSystemLedgerOffloaderFactory.java | 8 ++++ .../jcloud/JCloudLedgerOffloaderFactory.java | 7 ++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/LedgerOffloaderFactory.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/LedgerOffloaderFactory.java index 42f92359f9a94..7ecb8f08d573d 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/LedgerOffloaderFactory.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/LedgerOffloaderFactory.java @@ -42,7 +42,7 @@ public interface LedgerOffloaderFactory { boolean isDriverSupported(String driverName); /** - * Create a ledger offloader with the provided configuration, user-metadata and scheduler. + * Create a ledger offloader with the provided configuration, user-metadata, scheduler and offloaderStats. * * @param offloadPolicies offload policies * @param userMetadata user metadata @@ -50,12 +50,29 @@ public interface LedgerOffloaderFactory { * @return the offloader instance * @throws IOException when fail to create an offloader */ + T create(OffloadPoliciesImpl offloadPolicies, + Map userMetadata, + OrderedScheduler scheduler) + throws IOException; + + + /** + * Create a ledger offloader with the provided configuration, user-metadata, scheduler and offloaderStats. + * + * @param offloadPolicies offload policies + * @param userMetadata user metadata + * @param scheduler scheduler + * @param offloaderStats offloaderStats + * @return the offloader instance + * @throws IOException when fail to create an offloader + */ T create(OffloadPoliciesImpl offloadPolicies, Map userMetadata, OrderedScheduler scheduler, LedgerOffloaderStats offloaderStats) throws IOException; + /** * Create a ledger offloader with the provided configuration, user-metadata, schema storage and scheduler. * @@ -66,6 +83,26 @@ T create(OffloadPoliciesImpl offloadPolicies, * @return the offloader instance * @throws IOException when fail to create an offloader */ + default T create(OffloadPoliciesImpl offloadPolicies, + Map userMetadata, + SchemaStorage schemaStorage, + OrderedScheduler scheduler) + throws IOException { + return create(offloadPolicies, userMetadata, scheduler); + } + + /** + * Create a ledger offloader with the provided configuration, user-metadata, schema storage, + * scheduler and offloaderStats. + * + * @param offloadPolicies offload policies + * @param userMetadata user metadata + * @param schemaStorage used for schema lookup in offloader + * @param scheduler scheduler + * @param offloaderStats offloaderStats + * @return the offloader instance + * @throws IOException when fail to create an offloader + */ default T create(OffloadPoliciesImpl offloadPolicies, Map userMetadata, SchemaStorage schemaStorage, diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/LedgerOffloaderStatsDisable.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/LedgerOffloaderStatsDisable.java index 0fe0f453347bf..eeac9cfcfa994 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/LedgerOffloaderStatsDisable.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/LedgerOffloaderStatsDisable.java @@ -20,9 +20,9 @@ import java.util.concurrent.TimeUnit; -class LedgerOffloaderStatsDisable implements LedgerOffloaderStats { +public class LedgerOffloaderStatsDisable implements LedgerOffloaderStats { - static final LedgerOffloaderStats INSTANCE = new LedgerOffloaderStatsDisable(); + public static final LedgerOffloaderStats INSTANCE = new LedgerOffloaderStatsDisable(); private LedgerOffloaderStatsDisable() { diff --git a/tiered-storage/file-system/src/main/java/org/apache/bookkeeper/mledger/offload/filesystem/FileSystemLedgerOffloaderFactory.java b/tiered-storage/file-system/src/main/java/org/apache/bookkeeper/mledger/offload/filesystem/FileSystemLedgerOffloaderFactory.java index 8853ddf3da8ac..5649d264f579c 100644 --- a/tiered-storage/file-system/src/main/java/org/apache/bookkeeper/mledger/offload/filesystem/FileSystemLedgerOffloaderFactory.java +++ b/tiered-storage/file-system/src/main/java/org/apache/bookkeeper/mledger/offload/filesystem/FileSystemLedgerOffloaderFactory.java @@ -23,6 +23,7 @@ import org.apache.bookkeeper.common.util.OrderedScheduler; import org.apache.bookkeeper.mledger.LedgerOffloaderFactory; import org.apache.bookkeeper.mledger.LedgerOffloaderStats; +import org.apache.bookkeeper.mledger.LedgerOffloaderStatsDisable; import org.apache.bookkeeper.mledger.offload.filesystem.impl.FileSystemManagedLedgerOffloader; import org.apache.pulsar.common.policies.data.OffloadPoliciesImpl; @@ -32,6 +33,13 @@ public boolean isDriverSupported(String driverName) { return FileSystemManagedLedgerOffloader.driverSupported(driverName); } + @Override + public FileSystemManagedLedgerOffloader create(OffloadPoliciesImpl offloadPolicies, + Map userMetadata, OrderedScheduler scheduler) + throws IOException { + return create(offloadPolicies, userMetadata, scheduler, LedgerOffloaderStatsDisable.INSTANCE); + } + @Override public FileSystemManagedLedgerOffloader create(OffloadPoliciesImpl offloadPolicies, Map userMetadata, diff --git a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/JCloudLedgerOffloaderFactory.java b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/JCloudLedgerOffloaderFactory.java index e10575f5ddbb4..2c9165674444d 100644 --- a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/JCloudLedgerOffloaderFactory.java +++ b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/JCloudLedgerOffloaderFactory.java @@ -23,6 +23,7 @@ import org.apache.bookkeeper.common.util.OrderedScheduler; import org.apache.bookkeeper.mledger.LedgerOffloaderFactory; import org.apache.bookkeeper.mledger.LedgerOffloaderStats; +import org.apache.bookkeeper.mledger.LedgerOffloaderStatsDisable; import org.apache.bookkeeper.mledger.offload.jcloud.impl.BlobStoreManagedLedgerOffloader; import org.apache.bookkeeper.mledger.offload.jcloud.provider.JCloudBlobStoreProvider; import org.apache.bookkeeper.mledger.offload.jcloud.provider.TieredStorageConfiguration; @@ -44,6 +45,12 @@ public boolean isDriverSupported(String driverName) { return JCloudBlobStoreProvider.driverSupported(driverName); } + @Override + public BlobStoreManagedLedgerOffloader create(OffloadPoliciesImpl offloadPolicies, Map userMetadata, + OrderedScheduler scheduler) throws IOException { + return create(offloadPolicies, userMetadata, scheduler, LedgerOffloaderStatsDisable.INSTANCE); + } + @Override public BlobStoreManagedLedgerOffloader create(OffloadPoliciesImpl offloadPolicies, Map userMetadata, OrderedScheduler scheduler,