-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Issue 2688]Support set retention on topic level. #7747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b133646
74c8d4d
477d08a
e739133
dbd7771
c8f1043
bebd6f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,8 @@ | |
| import org.apache.pulsar.client.impl.MessageIdImpl; | ||
| import org.apache.pulsar.common.allocator.PulsarByteBufAllocator; | ||
| import org.apache.pulsar.common.naming.PartitionedManagedLedgerInfo; | ||
| import org.apache.pulsar.common.policies.data.PolicyName; | ||
| import org.apache.pulsar.common.policies.data.PolicyOperation; | ||
| import org.apache.pulsar.common.protocol.Commands; | ||
| import org.apache.pulsar.common.api.proto.PulsarApi.CommandSubscribe.InitialPosition; | ||
| import org.apache.pulsar.common.api.proto.PulsarApi.KeyValue; | ||
|
|
@@ -2156,6 +2158,67 @@ protected void internalRemoveBacklogQuota(AsyncResponse asyncResponse, | |
| internalSetBacklogQuota(asyncResponse, backlogQuotaType, null); | ||
| } | ||
|
|
||
| protected void internalGetRetention(AsyncResponse asyncResponse){ | ||
| validateAdminAccessForTenant(namespaceName.getTenant()); | ||
| validatePoliciesReadOnlyAccess(); | ||
| if (topicName.isGlobal()) { | ||
| validateGlobalNamespaceOwnership(namespaceName); | ||
| } | ||
| checkTopicLevelPolicyEnable(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checkTopicLevelPolicyEnable() is also called by getTopicPolicies(), so we can delete it here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, let me solve these problems |
||
| Optional<RetentionPolicies> retention = getTopicPolicies(topicName) | ||
| .map(TopicPolicies::getRetentionPolicies); | ||
| if (!retention.isPresent()) { | ||
| asyncResponse.resume(Response.noContent().build()); | ||
| }else { | ||
| asyncResponse.resume(retention.get()); | ||
| } | ||
| } | ||
|
|
||
| protected CompletableFuture<Void> internalSetRetention(RetentionPolicies retention) { | ||
| validateAdminAccessForTenant(namespaceName.getTenant()); | ||
| validatePoliciesReadOnlyAccess(); | ||
| if (topicName.isGlobal()) { | ||
| validateGlobalNamespaceOwnership(namespaceName); | ||
| } | ||
| checkTopicLevelPolicyEnable(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same to the above. |
||
| if (retention == null) { | ||
| return CompletableFuture.completedFuture(null); | ||
| } | ||
| TopicPolicies topicPolicies = getTopicPolicies(topicName) | ||
| .orElseGet(TopicPolicies::new); | ||
| BacklogQuota backlogQuota = | ||
| topicPolicies.getBackLogQuotaMap().get(BacklogQuota.BacklogQuotaType.destination_storage.name()); | ||
| if (backlogQuota == null){ | ||
| Policies policies = getNamespacePolicies(topicName.getNamespaceObject()); | ||
| backlogQuota = policies.backlog_quota_map.get(BacklogQuota.BacklogQuotaType.destination_storage); | ||
| } | ||
| if(!checkBacklogQuota(backlogQuota, retention)){ | ||
| log.warn( | ||
| "[{}] Failed to update retention quota configuration for topic {}: conflicts with retention quota", | ||
| clientAppId(), topicName); | ||
| throw new RestException(Status.PRECONDITION_FAILED, | ||
|
jianyun8023 marked this conversation as resolved.
|
||
| "Retention Quota must exceed configured backlog quota for topic. " + | ||
| "Please increase retention quota and retry"); | ||
| } | ||
| topicPolicies.setRetentionPolicies(retention); | ||
| return pulsar().getTopicPoliciesService().updateTopicPoliciesAsync(topicName, topicPolicies); | ||
| } | ||
|
|
||
| protected CompletableFuture<Void> internalRemoveRetention() { | ||
| validateAdminAccessForTenant(namespaceName.getTenant()); | ||
| validatePoliciesReadOnlyAccess(); | ||
| if (topicName.isGlobal()) { | ||
| validateGlobalNamespaceOwnership(namespaceName); | ||
| } | ||
| checkTopicLevelPolicyEnable(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same to the above. |
||
| Optional<TopicPolicies> topicPolicies = getTopicPolicies(topicName); | ||
| if (!topicPolicies.isPresent()) { | ||
| return CompletableFuture.completedFuture(null); | ||
| } | ||
| topicPolicies.get().setRetentionPolicies(null); | ||
| return pulsar().getTopicPoliciesService().updateTopicPoliciesAsync(topicName, topicPolicies.get()); | ||
| } | ||
|
|
||
| protected MessageId internalTerminate(boolean authoritative) { | ||
| if (topicName.isGlobal()) { | ||
| validateGlobalNamespaceOwnership(namespaceName); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.