Avoid contended synchronized block on topic load
@@ -1278,7 +1278,7 @@ public class PulsarService implements AutoCloseable, ShutdownService {
});
}
- public synchronized LedgerOffloader createManagedLedgerOffloader(OffloadPoliciesImpl offloadPolicies)
+ public LedgerOffloader createManagedLedgerOffloader(OffloadPoliciesImpl offloadPolicies)
throws PulsarServerException {
try {
if (StringUtils.isNotBlank(offloadPolicies.getManagedLedgerOffloadDriver())) {
@@ -1286,6 +1286,7 @@ public class PulsarService implements AutoCloseable, ShutdownService {
"Offloader driver is configured to be '%s' but no offloaders directory is configured.",
offloadPolicies.getManagedLedgerOffloadDriver());
+ synchronized (this) {
Offloaders offloaders = offloadersCache.getOrLoadOffloaders(
offloadPolicies.getOffloadersDirectory(), config.getNarExtractionDirectory());
@@ -1295,16 +1296,20 @@ public class PulsarService implements AutoCloseable, ShutdownService {
return offloaderFactory.create(
offloadPolicies,
ImmutableMap.of(
- LedgerOffloader.METADATA_SOFTWARE_VERSION_KEY.toLowerCase(), PulsarVersion.getVersion(),
- LedgerOffloader.METADATA_SOFTWARE_GITSHA_KEY.toLowerCase(), PulsarVersion.getGitSha(),
- LedgerOffloader.METADATA_PULSAR_CLUSTER_NAME.toLowerCase(), config.getClusterName()
+ LedgerOffloader.METADATA_SOFTWARE_VERSION_KEY.toLowerCase(),
+ PulsarVersion.getVersion(),
+ LedgerOffloader.METADATA_SOFTWARE_GITSHA_KEY.toLowerCase(),
+ PulsarVersion.getGitSha(),
+ LedgerOffloader.METADATA_PULSAR_CLUSTER_NAME.toLowerCase(),
+ config.getClusterName()
),
schemaStorage, getOffloaderScheduler(offloadPolicies), this.offloaderStats);
} catch (IOException ioe) {
throw new PulsarServerException(ioe.getMessage(), ioe.getCause());
}
+ }
} else {
- LOG.info("No ledger offloader configured, using NULL instance");
+ LOG.debug("No ledger offloader configured, using NULL instance");
return NullLedgerOffloader.INSTANCE;
}
} catch (Throwable t) {
