GeezerVison is showing github.com — [improve][test] Remove EntryCacheCreator from ManagedLedgerFactoryImp… · CleverCloud/pulsar@185c646
File treeExpand file treeCollapse file tree Open diff view settings main/java/org/apache/bookkeeper/mledger/impl test/java/org/apache/bookkeeper
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerFactoryImpl.java +6-25Lines changed: 6 additions & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 | import static org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException; | 22 | 22 | import static org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.NULL_OFFLOAD_PROMISE; | 23 | 23 | import static org.apache.pulsar.common.util.Runnables.catchingAndLoggingThrowables; | 24 | | -import com.google.common.annotations.VisibleForTesting; | 25 | 24 | import com.google.common.base.Predicates; | 26 | 25 | import com.google.common.collect.BoundType; | 27 | 26 | import com.google.common.collect.Maps; | | 48 | 47 | import java.util.concurrent.ScheduledExecutorService; | 49 | 48 | import java.util.concurrent.ScheduledFuture; | 50 | 49 | import java.util.concurrent.TimeUnit; | 51 | | -import java.util.function.Function; | 52 | 50 | import java.util.function.Supplier; | 53 | 51 | import java.util.stream.Collectors; | 54 | 52 | import lombok.Getter; | | 110 | 108 | import org.apache.pulsar.metadata.api.Stat; | 111 | 109 | import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended; | 112 | 110 | import org.apache.pulsar.metadata.api.extended.SessionEvent; | 113 | | -import org.jspecify.annotations.Nullable; | 114 | 111 | import org.slf4j.Logger; | 115 | 112 | import org.slf4j.LoggerFactory; | 116 | 113 |
| @@ -173,7 +170,7 @@ public ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore, ClientConfi | 173 | 170 | ManagedLedgerFactoryConfig config) | 174 | 171 | throws Exception { | 175 | 172 | this(metadataStore, new DefaultBkFactory(bkClientConfiguration), | 176 | | - true /* isBookkeeperManaged */, config, NullStatsLogger.INSTANCE, OpenTelemetry.noop(), null); | | 173 | + true /* isBookkeeperManaged */, config, NullStatsLogger.INSTANCE, OpenTelemetry.noop()); | 177 | 174 | } | 178 | 175 |
| 179 | 176 | public ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore, BookKeeper bookKeeper) | @@ -187,21 +184,12 @@ public ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore, BookKeeper | 187 | 184 | this(metadataStore, (policyConfig) -> CompletableFuture.completedFuture(bookKeeper), config); | 188 | 185 | } | 189 | 186 |
| 190 | | - @VisibleForTesting | 191 | | - public ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore, BookKeeper bookKeeper, | 192 | | - @Nullable Function<ManagedLedgerFactoryImpl, EntryCacheManager> | 193 | | - entryCacheManagerCreator) | 194 | | - throws Exception { | 195 | | - this(metadataStore, __ -> CompletableFuture.completedFuture(bookKeeper), false, | 196 | | - new ManagedLedgerFactoryConfig(), NullStatsLogger.INSTANCE, OpenTelemetry.noop(), | 197 | | - entryCacheManagerCreator); | 198 | | - } | 199 | | - | 200 | 187 | public ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore, | 201 | 188 | BookkeeperFactoryForCustomEnsemblePlacementPolicy bookKeeperGroupFactory, | 202 | 189 | ManagedLedgerFactoryConfig config) | 203 | 190 | throws Exception { | 204 | | - this(metadataStore, bookKeeperGroupFactory, config, NullStatsLogger.INSTANCE, OpenTelemetry.noop()); | | 191 | + this(metadataStore, bookKeeperGroupFactory, false /* isBookkeeperManaged */, | | 192 | + config, NullStatsLogger.INSTANCE, OpenTelemetry.noop()); | 205 | 193 | } | 206 | 194 |
| 207 | 195 | public ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore, | @@ -210,18 +198,15 @@ public ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore, | 210 | 198 | OpenTelemetry openTelemetry) | 211 | 199 | throws Exception { | 212 | 200 | this(metadataStore, bookKeeperGroupFactory, false /* isBookkeeperManaged */, | 213 | | - config, statsLogger, openTelemetry, null); | | 201 | + config, statsLogger, openTelemetry); | 214 | 202 | } | 215 | 203 |
| 216 | 204 | private ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore, | 217 | 205 | BookkeeperFactoryForCustomEnsemblePlacementPolicy bookKeeperGroupFactory, | 218 | 206 | boolean isBookkeeperManaged, | 219 | 207 | ManagedLedgerFactoryConfig config, | 220 | 208 | StatsLogger statsLogger, | 221 | | - OpenTelemetry openTelemetry, | 222 | | - @Nullable Function<ManagedLedgerFactoryImpl, EntryCacheManager> | 223 | | - entryCacheManagerCreator) | 224 | | - throws Exception { | | 209 | + OpenTelemetry openTelemetry) throws Exception { | 225 | 210 | MetadataCompressionConfig compressionConfigForManagedLedgerInfo = | 226 | 211 | config.getCompressionConfigForManagedLedgerInfo(); | 227 | 212 | MetadataCompressionConfig compressionConfigForManagedCursorInfo = | @@ -243,11 +228,7 @@ private ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore, | 243 | 228 | compressionConfigForManagedCursorInfo); | 244 | 229 | this.config = config; | 245 | 230 | this.mbean = new ManagedLedgerFactoryMBeanImpl(this); | 246 | | - if (entryCacheManagerCreator == null) { | 247 | | - this.entryCacheManager = new RangeEntryCacheManagerImpl(this, scheduledExecutor, openTelemetry); | 248 | | - } else { | 249 | | - this.entryCacheManager = entryCacheManagerCreator.apply(this); | 250 | | - } | | 231 | + this.entryCacheManager = new RangeEntryCacheManagerImpl(this, scheduledExecutor, openTelemetry); | 251 | 232 | this.statsTask = scheduledExecutor.scheduleWithFixedDelay(catchingAndLoggingThrowables(this::refreshStats), | 252 | 233 | 0, config.getStatsPeriodSeconds(), TimeUnit.SECONDS); | 253 | 234 | this.flushCursorsTask = scheduledExecutor.scheduleAtFixedRate(catchingAndLoggingThrowables(this::flushCursors), | |
Collapse file Copy file name to clipboardExpand all lines: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeEntryCacheImpl.java +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -440,9 +440,8 @@ private long getAvgEntrySize() { | 440 | 440 | * @param shouldCacheEntry if we should put the entry into the cache | 441 | 441 | * @return a handle to the operation | 442 | 442 | */ | 443 | | - @VisibleForTesting | 444 | | - protected CompletableFuture<List<EntryImpl>> readFromStorage(ReadHandle lh, long firstEntry, long lastEntry, | 445 | | - boolean shouldCacheEntry) { | | 443 | + CompletableFuture<List<EntryImpl>> readFromStorage(ReadHandle lh, | | 444 | + long firstEntry, long lastEntry, boolean shouldCacheEntry) { | 446 | 445 | final int entriesToRead = (int) (lastEntry - firstEntry) + 1; | 447 | 446 | CompletableFuture<List<EntryImpl>> readResult = ReadEntryUtils.readAsync(ml, lh, firstEntry, lastEntry) | 448 | 447 | .thenApply( | |
Collapse file Copy file name to clipboardExpand all lines: managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java +28-10Lines changed: 28 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 47 | 47 | import java.util.Collections; | 48 | 48 | import java.util.HashMap; | 49 | 49 | import java.util.HashSet; | | 50 | +import java.util.Iterator; | 50 | 51 | import java.util.List; | 51 | 52 | import java.util.Map; | 52 | 53 | import java.util.Optional; | | 79 | 80 | import org.apache.bookkeeper.client.BookKeeper.DigestType; | 80 | 81 | import org.apache.bookkeeper.client.LedgerEntry; | 81 | 82 | import org.apache.bookkeeper.client.PulsarMockBookKeeper; | | 83 | +import org.apache.bookkeeper.client.PulsarMockReadHandleInterceptor; | | 84 | +import org.apache.bookkeeper.client.api.LedgerEntries; | 82 | 85 | import org.apache.bookkeeper.client.api.ReadHandle; | 83 | 86 | import org.apache.bookkeeper.common.util.OrderedExecutor; | 84 | 87 | import org.apache.bookkeeper.mledger.AsyncCallbacks; | | 100 | 103 | import org.apache.bookkeeper.mledger.ScanOutcome; | 101 | 104 | import org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.VoidCallback; | 102 | 105 | import org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback; | 103 | | -import org.apache.bookkeeper.mledger.impl.cache.RangeEntryCacheImpl; | 104 | | -import org.apache.bookkeeper.mledger.impl.cache.RangeEntryCacheManagerImpl; | 105 | 106 | import org.apache.bookkeeper.mledger.proto.MLDataFormats; | 106 | 107 | import org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo; | 107 | 108 | import org.apache.bookkeeper.mledger.proto.MLDataFormats.PositionInfo; | 108 | 109 | import org.apache.bookkeeper.test.MockedBookKeeperTestCase; | | 110 | +import org.apache.commons.collections.iterators.EmptyIterator; | 109 | 111 | import org.apache.commons.lang3.mutable.MutableBoolean; | 110 | 112 | import org.apache.pulsar.common.api.proto.CommandSubscribe; | 111 | 113 | import org.apache.pulsar.common.api.proto.IntRange; | @@ -139,7 +141,7 @@ public static Object[][] useOpenRangeSet() { | 139 | 141 |
| 140 | 142 | @AfterMethod | 141 | 143 | public void afterMethod() { | 142 | | - setEntryCacheCreator(null); | | 144 | + bkc.setReadHandleInterceptor(null); | 143 | 145 | } | 144 | 146 |
| 145 | 147 | @Test | @@ -5413,16 +5415,32 @@ public void operationFailed(ManagedLedgerException exception) { | 5413 | 5415 | @Test(timeOut = 10000) | 5414 | 5416 | public void testReadNoEntries() throws Exception { | 5415 | 5417 | final var firstRead = new AtomicBoolean(true); | 5416 | | - setEntryCacheCreator(ml -> new RangeEntryCacheImpl((RangeEntryCacheManagerImpl) factory.getEntryCacheManager(), | 5417 | | - ml, factory.getConfig().isCopyEntriesInCache()) { | 5418 | | - | | 5418 | + bkc.setReadHandleInterceptor(new PulsarMockReadHandleInterceptor() { | 5419 | 5419 | @Override | 5420 | | - protected CompletableFuture<List<EntryImpl>> readFromStorage(ReadHandle lh, long firstEntry, long lastEntry, | 5421 | | - boolean shouldCacheEntry) { | | 5420 | + public CompletableFuture<LedgerEntries> interceptReadAsync(long ledgerId, long firstEntry, long lastEntry, | | 5421 | + LedgerEntries entries) { | 5422 | 5422 | if (firstRead.compareAndSet(true, false)) { | 5423 | | - return CompletableFuture.completedFuture(List.of()); | | 5423 | + // LedgerEntriesImpl doesn't allow empty entries list. | | 5424 | + // Implementing a dummy LedgerEntries that returns an empty list. | | 5425 | + return CompletableFuture.completedFuture(new LedgerEntries() { | | 5426 | + @Override | | 5427 | + public org.apache.bookkeeper.client.api.LedgerEntry getEntry(long entryId) { | | 5428 | + return null; | | 5429 | + } | | 5430 | + | | 5431 | + @Override | | 5432 | + public Iterator<org.apache.bookkeeper.client.api.LedgerEntry> iterator() { | | 5433 | + return EmptyIterator.INSTANCE; | | 5434 | + } | | 5435 | + | | 5436 | + @Override | | 5437 | + public void close() { | | 5438 | + | | 5439 | + } | | 5440 | + }); | | 5441 | + } else { | | 5442 | + return CompletableFuture.completedFuture(entries); | 5424 | 5443 | } | 5425 | | - return super.readFromStorage(lh, firstEntry, lastEntry, shouldCacheEntry); | 5426 | 5444 | } | 5427 | 5445 | }); | 5428 | 5446 | final var ml = factory.open("testReadNoEntries"); | |
Collapse file Copy file name to clipboardExpand all lines: managed-ledger/src/test/java/org/apache/bookkeeper/test/MockedBookKeeperTestCase.java +1-21Lines changed: 1 addition & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | */ | 19 | 19 | package org.apache.bookkeeper.test; | 20 | 20 |
| 21 | | -import io.opentelemetry.api.OpenTelemetry; | 22 | 21 | import java.lang.reflect.Method; | 23 | 22 | import java.util.Optional; | 24 | 23 | import java.util.concurrent.ExecutorService; | 25 | 24 | import java.util.concurrent.Executors; | 26 | 25 | import java.util.concurrent.TimeUnit; | 27 | | -import java.util.function.Function; | 28 | 26 | import lombok.SneakyThrows; | 29 | 27 | import org.apache.bookkeeper.client.PulsarMockBookKeeper; | 30 | 28 | import org.apache.bookkeeper.common.util.OrderedScheduler; | 31 | 29 | import org.apache.bookkeeper.mledger.ManagedLedgerException; | 32 | 30 | import org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig; | 33 | 31 | import org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl; | 34 | | -import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl; | 35 | | -import org.apache.bookkeeper.mledger.impl.cache.EntryCache; | 36 | | -import org.apache.bookkeeper.mledger.impl.cache.RangeEntryCacheManagerImpl; | 37 | 32 | import org.apache.pulsar.metadata.api.MetadataStoreConfig; | 38 | 33 | import org.apache.pulsar.metadata.api.MetadataStoreException; | 39 | 34 | import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended; | @@ -62,7 +57,6 @@ public abstract class MockedBookKeeperTestCase { | 62 | 57 | protected ExecutorService cachedExecutor; | 63 | 58 |
| 64 | 59 | protected FaultInjectionMetadataStore metadataStore; | 65 | | - private Function<ManagedLedgerImpl, EntryCache> entryCacheCreator = null; | 66 | 60 |
| 67 | 61 | public MockedBookKeeperTestCase() { | 68 | 62 | // By default start a 3 bookies cluster | @@ -90,17 +84,7 @@ public final void setUp(Method method) throws Exception { | 90 | 84 |
| 91 | 85 | ManagedLedgerFactoryConfig managedLedgerFactoryConfig = new ManagedLedgerFactoryConfig(); | 92 | 86 | initManagedLedgerFactoryConfig(managedLedgerFactoryConfig); | 93 | | - factory = new ManagedLedgerFactoryImpl(metadataStore, bkc, __ -> new RangeEntryCacheManagerImpl(__, | 94 | | - __.getScheduledExecutor(), OpenTelemetry.noop()) { | 95 | | - | 96 | | - @Override | 97 | | - public EntryCache getEntryCache(ManagedLedgerImpl ml) { | 98 | | - if (entryCacheCreator != null) { | 99 | | - return entryCacheCreator.apply(ml); | 100 | | - } | 101 | | - return super.getEntryCache(ml); | 102 | | - } | 103 | | - }); | | 87 | + factory = new ManagedLedgerFactoryImpl(metadataStore, bkc); | 104 | 88 |
| 105 | 89 | setUpTestCase(); | 106 | 90 | } | @@ -180,8 +164,4 @@ protected void stopBookKeeper() { | 180 | 164 | protected void stopMetadataStore() { | 181 | 165 | metadataStore.setAlwaysFail(new MetadataStoreException("failed")); | 182 | 166 | } | 183 | | - | 184 | | - protected void setEntryCacheCreator(Function<ManagedLedgerImpl, EntryCache> entryCacheCreator) { | 185 | | - this.entryCacheCreator = entryCacheCreator; | 186 | | - } | 187 | 167 | } |
|