GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [improve][broker] Reduce cache retention after reads and apply retent… · apache/pulsar@80df050

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • conf
    • broker.conf
    • standalone.conf
  • pulsar-broker-common/src/main/java/org/apache/pulsar/broker
    • ServiceConfiguration.java
  • pulsar-broker/src
    • main/java/org/apache/pulsar/broker
      • ManagedLedgerClientFactory.java
    • test/java/org/apache/pulsar/broker
      • ManagedLedgerClientFactoryTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎conf/broker.conf‎

Copy file name to clipboardExpand all lines: conf/broker.conf
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,8 +1344,8 @@ managedLedgerCacheEvictionExtendTTLOfEntriesWithRemainingExpectedReadsMaxTimes=5
13441344
# When disabled:
13451345
# - Cache behaves more like a FIFO queue with time-based and size-based eviction
13461346
# - Minimum eviction time is managedLedgerCacheEvictionTimeThresholdMillis
1347-
# Default is true, to behave like a LRU cache.
1348-
managedLedgerCacheEvictionExtendTTLOfRecentlyAccessed=true
1347+
# Default is false, to avoid extending cache retention for entries that have already been read.
1348+
managedLedgerCacheEvictionExtendTTLOfRecentlyAccessed=false
13491349

13501350
# This setting configures the duration of continuing to cache added entries while there are no
13511351
# active cursors, when the last active cursor has left or immediately after initialization when
Collapse file

‎conf/standalone.conf‎

Copy file name to clipboardExpand all lines: conf/standalone.conf
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,8 @@ managedLedgerCacheEvictionExtendTTLOfEntriesWithRemainingExpectedReadsMaxTimes=5
876876
# When disabled:
877877
# - Cache behaves more like a FIFO queue with time-based and size-based eviction
878878
# - Minimum eviction time is managedLedgerCacheEvictionTimeThresholdMillis
879-
# Default is true, to behave like a LRU cache.
880-
managedLedgerCacheEvictionExtendTTLOfRecentlyAccessed=true
879+
# Default is false, to avoid extending cache retention for entries that have already been read.
880+
managedLedgerCacheEvictionExtendTTLOfRecentlyAccessed=false
881881

882882
# This setting configures the duration of continuing to cache added entries while there are no
883883
# active cursors, when the last active cursor has left or immediately after initialization when
Collapse file

‎pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java‎

Copy file name to clipboardExpand all lines: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,9 +2376,9 @@ The max allowed delay for delayed delivery (in milliseconds). If the broker rece
23762376
+ "When disabled:\n"
23772377
+ " - Cache behaves more like a FIFO queue with time-based and size-based eviction\n"
23782378
+ " - Minimum eviction time is managedLedgerCacheEvictionTimeThresholdMillis\n"
2379-
+ "Default is true, to behave like a LRU cache."
2379+
+ "Default is false, to avoid extending cache retention for entries that have already been read."
23802380
)
2381-
private boolean managedLedgerCacheEvictionExtendTTLOfRecentlyAccessed = true;
2381+
private boolean managedLedgerCacheEvictionExtendTTLOfRecentlyAccessed = false;
23822382

23832383
@FieldContext(category = CATEGORY_STORAGE_ML,
23842384
doc = "Configure the threshold (in number of entries) from where a cursor should be considered 'backlogged'"
Collapse file

‎pulsar-broker/src/main/java/org/apache/pulsar/broker/ManagedLedgerClientFactory.java‎

Copy file name to clipboardExpand all lines: pulsar-broker/src/main/java/org/apache/pulsar/broker/ManagedLedgerClientFactory.java
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public void initialize(ServiceConfiguration conf, MetadataStoreExtended metadata
7878
managedLedgerFactoryConfig.setCacheEvictionIntervalMs(conf.getManagedLedgerCacheEvictionIntervalMs());
7979
managedLedgerFactoryConfig.setCacheEvictionTimeThresholdMillis(
8080
conf.getManagedLedgerCacheEvictionTimeThresholdMillis());
81+
managedLedgerFactoryConfig.setCacheEvictionExtendTTLOfRecentlyAccessed(
82+
conf.isManagedLedgerCacheEvictionExtendTTLOfRecentlyAccessed());
83+
managedLedgerFactoryConfig.setCacheEvictionExtendTTLOfEntriesWithRemainingExpectedReadsMaxTimes(
84+
conf.getManagedLedgerCacheEvictionExtendTTLOfEntriesWithRemainingExpectedReadsMaxTimes());
8185
Long continueCachingAddedEntriesAfterLastActiveCursorLeavesMillis =
8286
conf.getManagedLedgerContinueCachingAddedEntriesAfterLastActiveCursorLeavesMillis();
8387
if (continueCachingAddedEntriesAfterLastActiveCursorLeavesMillis != null) {
Collapse file

‎pulsar-broker/src/test/java/org/apache/pulsar/broker/ManagedLedgerClientFactoryTest.java‎

Copy file name to clipboard
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.pulsar.broker;
20+
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.mockito.ArgumentMatchers.any;
23+
import static org.mockito.ArgumentMatchers.isNull;
24+
import static org.mockito.Mockito.doReturn;
25+
import static org.mockito.Mockito.mock;
26+
import static org.mockito.Mockito.spy;
27+
import static org.mockito.Mockito.verify;
28+
import static org.mockito.Mockito.when;
29+
import io.netty.channel.EventLoopGroup;
30+
import io.opentelemetry.api.OpenTelemetry;
31+
import java.util.concurrent.CompletableFuture;
32+
import org.apache.bookkeeper.client.BookKeeper;
33+
import org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig;
34+
import org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl;
35+
import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended;
36+
import org.mockito.ArgumentCaptor;
37+
import org.testng.annotations.DataProvider;
38+
import org.testng.annotations.Test;
39+
40+
@Test(groups = "broker")
41+
public class ManagedLedgerClientFactoryTest {
42+
@DataProvider
43+
public Object[][] cacheExtensionSettings() {
44+
return new Object[][] {{null, 5}, {false, 2}, {true, 0}, {true, 5}};
45+
}
46+
47+
@Test(dataProvider = "cacheExtensionSettings")
48+
public void testCacheExtensionSettingsAtStartup(Boolean extendRecentlyAccessed, int maxExtensions)
49+
throws Exception {
50+
ServiceConfiguration conf = new ServiceConfiguration();
51+
if (extendRecentlyAccessed == null) {
52+
assertThat(conf.isManagedLedgerCacheEvictionExtendTTLOfRecentlyAccessed()).isFalse();
53+
} else {
54+
conf.setManagedLedgerCacheEvictionExtendTTLOfRecentlyAccessed(extendRecentlyAccessed);
55+
}
56+
conf.setManagedLedgerCacheEvictionExtendTTLOfEntriesWithRemainingExpectedReadsMaxTimes(maxExtensions);
57+
conf.setBookkeeperClientExposeStatsToPrometheus(false);
58+
BookKeeperClientFactory bookkeeperProvider = mock(BookKeeperClientFactory.class);
59+
when(bookkeeperProvider.create(any(), any(), any(), any(), isNull(), any()))
60+
.thenReturn(CompletableFuture.completedFuture(mock(BookKeeper.class)));
61+
try (ManagedLedgerClientFactory factory = spy(new ManagedLedgerClientFactory())) {
62+
doReturn(mock(ManagedLedgerFactoryImpl.class)).when(factory)
63+
.createManagedLedgerFactory(any(), any(), any(), any(), any());
64+
factory.initialize(conf, mock(MetadataStoreExtended.class), bookkeeperProvider,
65+
mock(EventLoopGroup.class), OpenTelemetry.noop());
66+
ArgumentCaptor<ManagedLedgerFactoryConfig> config =
67+
ArgumentCaptor.forClass(ManagedLedgerFactoryConfig.class);
68+
verify(factory).createManagedLedgerFactory(any(), any(), any(), config.capture(), any());
69+
assertThat(config.getValue().isCacheEvictionExtendTTLOfRecentlyAccessed())
70+
.isEqualTo(Boolean.TRUE.equals(extendRecentlyAccessed));
71+
assertThat(config.getValue().getCacheEvictionExtendTTLOfEntriesWithRemainingExpectedReadsMaxTimes())
72+
.isEqualTo(maxExtensions);
73+
}
74+
}
75+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.