|
67 | 67 | import java.util.concurrent.atomic.AtomicReference;
|
68 | 68 | import lombok.Cleanup;
|
69 | 69 | import lombok.extern.slf4j.Slf4j;
|
| 70 | +import org.apache.bookkeeper.client.api.ReadHandle; |
| 71 | +import org.apache.bookkeeper.mledger.LedgerOffloader; |
70 | 72 | import org.apache.bookkeeper.mledger.ManagedLedgerConfig;
|
71 | 73 | import org.apache.bookkeeper.mledger.ManagedLedgerException;
|
72 | 74 | import org.apache.bookkeeper.mledger.impl.ManagedCursorImpl;
|
73 | 75 | import org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl;
|
74 | 76 | import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl;
|
| 77 | +import org.apache.bookkeeper.mledger.impl.NullLedgerOffloader; |
75 | 78 | import org.apache.http.HttpResponse;
|
76 | 79 | import org.apache.http.client.methods.HttpGet;
|
77 | 80 | import org.apache.http.impl.client.CloseableHttpClient;
|
|
112 | 115 | import org.apache.pulsar.common.naming.TopicName;
|
113 | 116 | import org.apache.pulsar.common.policies.data.BundlesData;
|
114 | 117 | import org.apache.pulsar.common.policies.data.LocalPolicies;
|
| 118 | +import org.apache.pulsar.common.policies.data.OffloadPolicies; |
| 119 | +import org.apache.pulsar.common.policies.data.OffloadPoliciesImpl; |
| 120 | +import org.apache.pulsar.common.policies.data.OffloadedReadPriority; |
115 | 121 | import org.apache.pulsar.common.policies.data.SubscriptionStats;
|
116 | 122 | import org.apache.pulsar.common.policies.data.TopicStats;
|
117 | 123 | import org.apache.pulsar.common.protocol.Commands;
|
@@ -1745,4 +1751,92 @@ public void testUnsubscribeNonDurableSub() throws Exception {
|
1745 | 1751 | fail("Unsubscribe failed");
|
1746 | 1752 | }
|
1747 | 1753 | }
|
| 1754 | + |
| 1755 | + |
| 1756 | + @Test |
| 1757 | + public void testOffloadConfShouldNotAppliedForSystemTopic() throws PulsarAdminException { |
| 1758 | + final String driver = "aws-s3"; |
| 1759 | + final String region = "test-region"; |
| 1760 | + final String bucket = "test-bucket"; |
| 1761 | + final String role = "test-role"; |
| 1762 | + final String roleSessionName = "test-role-session-name"; |
| 1763 | + final String credentialId = "test-credential-id"; |
| 1764 | + final String credentialSecret = "test-credential-secret"; |
| 1765 | + final String endPoint = "test-endpoint"; |
| 1766 | + final Integer maxBlockSizeInBytes = 5; |
| 1767 | + final Integer readBufferSizeInBytes = 2; |
| 1768 | + final Long offloadThresholdInBytes = 10L; |
| 1769 | + final Long offloadThresholdInSeconds = 1000L; |
| 1770 | + final Long offloadDeletionLagInMillis = 5L; |
| 1771 | + |
| 1772 | + final OffloadPoliciesImpl offloadPolicies = OffloadPoliciesImpl.create( |
| 1773 | + driver, |
| 1774 | + region, |
| 1775 | + bucket, |
| 1776 | + endPoint, |
| 1777 | + role, |
| 1778 | + roleSessionName, |
| 1779 | + credentialId, |
| 1780 | + credentialSecret, |
| 1781 | + maxBlockSizeInBytes, |
| 1782 | + readBufferSizeInBytes, |
| 1783 | + offloadThresholdInBytes, |
| 1784 | + offloadThresholdInSeconds, |
| 1785 | + offloadDeletionLagInMillis, |
| 1786 | + OffloadedReadPriority.TIERED_STORAGE_FIRST |
| 1787 | + ); |
| 1788 | + |
| 1789 | + var fakeOffloader = new LedgerOffloader() { |
| 1790 | + @Override |
| 1791 | + public String getOffloadDriverName() { |
| 1792 | + return driver; |
| 1793 | + } |
| 1794 | + |
| 1795 | + @Override |
| 1796 | + public CompletableFuture<Void> offload(ReadHandle ledger, UUID uid, Map<String, String> extraMetadata) { |
| 1797 | + return CompletableFuture.completedFuture(null); |
| 1798 | + } |
| 1799 | + |
| 1800 | + @Override |
| 1801 | + public CompletableFuture<ReadHandle> readOffloaded(long ledgerId, UUID uid, Map<String, String> offloadDriverMetadata) { |
| 1802 | + return CompletableFuture.completedFuture(null); |
| 1803 | + } |
| 1804 | + |
| 1805 | + @Override |
| 1806 | + public CompletableFuture<Void> deleteOffloaded(long ledgerId, UUID uid, Map<String, String> offloadDriverMetadata) { |
| 1807 | + return CompletableFuture.completedFuture(null); |
| 1808 | + } |
| 1809 | + |
| 1810 | + @Override |
| 1811 | + public OffloadPolicies getOffloadPolicies() { |
| 1812 | + return offloadPolicies; |
| 1813 | + } |
| 1814 | + |
| 1815 | + @Override |
| 1816 | + public void close() { |
| 1817 | + } |
| 1818 | + }; |
| 1819 | + |
| 1820 | + final BrokerService brokerService = pulsar.getBrokerService(); |
| 1821 | + final String namespace = "prop/" + UUID.randomUUID(); |
| 1822 | + admin.namespaces().createNamespace(namespace); |
| 1823 | + admin.namespaces().setOffloadPolicies(namespace, offloadPolicies); |
| 1824 | + |
| 1825 | + // Inject the cache to avoid real load off-loader jar |
| 1826 | + final Map<NamespaceName, LedgerOffloader> ledgerOffloaderMap = pulsar.getLedgerOffloaderMap(); |
| 1827 | + ledgerOffloaderMap.put(NamespaceName.get(namespace), fakeOffloader); |
| 1828 | + |
| 1829 | + // (1) test normal topic |
| 1830 | + final String normalTopic = "persistent://" + namespace + "/" + UUID.randomUUID(); |
| 1831 | + var managedLedgerConfig = brokerService.getManagedLedgerConfig(TopicName.get(normalTopic)).join(); |
| 1832 | + |
| 1833 | + Assert.assertEquals(managedLedgerConfig.getLedgerOffloader(), fakeOffloader); |
| 1834 | + |
| 1835 | + // (2) test system topic |
| 1836 | + for (String eventTopicName : SystemTopicNames.EVENTS_TOPIC_NAMES) { |
| 1837 | + managedLedgerConfig = brokerService.getManagedLedgerConfig(TopicName.get(eventTopicName)).join(); |
| 1838 | + Assert.assertEquals(managedLedgerConfig.getLedgerOffloader(), NullLedgerOffloader.INSTANCE); |
| 1839 | + } |
| 1840 | + } |
1748 | 1841 | }
|
| 1842 | + |
0 commit comments