[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce system topic and topic policies service

2019-09-18 Thread GitBox
sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r325945216
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/TopicPoliciesService.java
 ##
 @@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service;
+
+import org.apache.pulsar.common.naming.NamespaceBundle;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.policies.data.TopicPolicies;
+import org.apache.pulsar.common.util.FutureUtil;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Topic policies service
+ */
+public interface TopicPoliciesService {
+
+TopicPoliciesService DISABLED = new TopicPoliciesServiceDisabled();
+
+/**
+ * Update policies for a topic async
+ * @param topicName topic name
+ * @param policies policies for the topic name
+ */
+CompletableFuture updateTopicPoliciesAsync(TopicName topicName, 
TopicPolicies policies);
+
+/**
+ * Get policies for a topic async
+ * @param topicName topic name
+ * @return future of the topic policies
+ */
+TopicPolicies getTopicPolicies(TopicName topicName);
+
+/**
+ * Get policies for a topic without cache async
+ * @param topicName topic name
+ * @return future of the topic policies
+ */
+CompletableFuture 
getTopicPoliciesWithoutCacheAsync(TopicName topicName);
 
 Review comment:
   ```suggestion
   CompletableFuture 
getTopicPoliciesBypassCacheAsync(TopicName topicName);
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce system topic and topic policies service

2019-09-18 Thread GitBox
sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r325946271
 
 

 ##
 File path: 
pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/Policies.java
 ##
 @@ -164,7 +164,7 @@ public String toString() {
 .add("clusterSubscribeRate", clusterSubscribeRate)
 .add("latency_stats_sample_rate", latency_stats_sample_rate)
 .add("antiAffinityGroup", antiAffinityGroup)
-.add("message_ttl_in_seconds", 
message_ttl_in_seconds).add("retention_policies", retention_policies)
+.add("message_ttl_in_seconds", 
message_ttl_in_seconds).add("retentionPolicies", retention_policies)
 
 Review comment:
   any reason why do you change this field here?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce system topic and topic policies service

2019-09-18 Thread GitBox
sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r325944980
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
 ##
 @@ -977,6 +979,9 @@ public BacklogQuotaManager getBacklogQuotaManager() {
  * @return determine if quota enforcement needs to be done for topic
  */
 public boolean isBacklogExceeded(PersistentTopic topic) {
 
 Review comment:
   Can we move this method to PersistentTopic?
   
   so the logic can be clear:
   
   ```
   
   class PersistentTopic {
   
   public boolean isBacklogExceed() {
// check the backlog logic
   }
   }
   
   class SystemTopic {
   public boolean isBacklogExceed() {
return false;
   } 
   }
   
   so the method can be simplified as 
   
   public boolean isBacklogExceeded(PersistentTopic topic) {
   return topic.isBacklogExceeded();
   }
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce system topic and topic policies service

2019-09-18 Thread GitBox
sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r325945526
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
 ##
 @@ -1031,7 +1042,7 @@ public void checkCompaction() {
 .orElseThrow(() -> new KeeperException.NoNodeException());
 
 
-if (policies.compaction_threshold != 0
+if (isSystemTopic || policies.compaction_threshold != 0
 
 Review comment:
   ```suggestion
   if (isSystemTopic() || policies.compaction_threshold != 0
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce system topic and topic policies service

2019-09-18 Thread GitBox
sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r325943243
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
 ##
 @@ -324,37 +324,12 @@ private boolean registerNamespace(String namespace, 
boolean ensureOwned) throws
 targetMap = findingBundlesNotAuthoritative;
 }
 
-return targetMap.computeIfAbsent(bundle, (k) -> {
-CompletableFuture> future = new 
CompletableFuture<>();
-
-// First check if we or someone else already owns the bundle
-ownershipCache.getOwnerAsync(bundle).thenAccept(nsData -> {
-if (!nsData.isPresent()) {
-// No one owns this bundle
+if (targetMap.get(bundle) != null && !targetMap.get(bundle).isDone()) {
 
 Review comment:
   the two get calls can *potentially* return different values. so as a good 
practice, I would recommend writing in the following way.
   
   ```
   CompletableFuture> future = targetMap.get(bundle);
   if (future != null && !future.isDone()) {
   // ...
   }
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce system topic and topic policies service

2019-09-18 Thread GitBox
sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r325943491
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
 ##
 @@ -324,37 +324,12 @@ private boolean registerNamespace(String namespace, 
boolean ensureOwned) throws
 targetMap = findingBundlesNotAuthoritative;
 }
 
-return targetMap.computeIfAbsent(bundle, (k) -> {
-CompletableFuture> future = new 
CompletableFuture<>();
-
-// First check if we or someone else already owns the bundle
-ownershipCache.getOwnerAsync(bundle).thenAccept(nsData -> {
-if (!nsData.isPresent()) {
-// No one owns this bundle
+if (targetMap.get(bundle) != null && !targetMap.get(bundle).isDone()) {
+return findBrokerServiceUrlInternal(bundle, authoritative, 
readOnly);
 
 Review comment:
   shouldn't we return the `future` here, since there is already an ongoing 
lookup, no?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce system topic and topic policies service

2019-09-18 Thread GitBox
sijie commented on a change in pull request #4955: [WIP][PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r325945444
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
 ##
 @@ -151,6 +151,8 @@
 private CompletableFuture currentCompaction = 
CompletableFuture.completedFuture(COMPACTION_NEVER_RUN);
 private final CompactedTopic compactedTopic;
 
+private final boolean isSystemTopic;
 
 Review comment:
   see my comment above about making a new `SystemTopic` class and making it 
extend `PersistentTopic`.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r316411189
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/TopicPoliciesService.java
 ##
 @@ -0,0 +1,230 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.cache.RemovalListener;
+import org.apache.pulsar.broker.PulsarServerException;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.systopic.EventType;
+import org.apache.pulsar.broker.systopic.NamespaceEventsSystemTopicFactory;
+import org.apache.pulsar.broker.systopic.SystemTopic;
+import org.apache.pulsar.broker.systopic.TopicEvent;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.policies.data.TopicPolicies;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Topic policies service
+ */
+public class TopicPoliciesService {
+
+private final PulsarService pulsarService;
+private NamespaceEventsSystemTopicFactory 
namespaceEventsSystemTopicFactory;
+
+private final Map policiesCache = new 
ConcurrentHashMap<>();
+
+private final LoadingCache> readerCache;
 
 Review comment:
   If we are using Guava cache, how do we backfill the cache if the entries are 
evicted out of the cache?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r315511539
 
 

 ##
 File path: conf/broker.conf
 ##
 @@ -284,6 +284,13 @@ replicatedSubscriptionsSnapshotTimeoutSeconds=30
 # Max number of snapshot to be cached per subscription.
 replicatedSubscriptionsSnapshotMaxCachedPerSubscription=10
 
+# Enable or disable system topic
+systemTopicEnable=true
 
 Review comment:
   `systemTopicEnabled`
   
   make the name consistent with others


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r316409371
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/systopic/ActionType.java
 ##
 @@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.systopic;
+
+/**
+ * Pulsar event action type
+ */
+public enum ActionType {
 
 Review comment:
   I would suggest moving this package to `pulsar-common` and renaming it to 
`org.apache.pulsar.common.events`. The reason to put the classes under 
`pulsar-common` is that pulsar users can use those classes to consume these 
change events.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r316410694
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/TopicPoliciesService.java
 ##
 @@ -0,0 +1,230 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.cache.RemovalListener;
+import org.apache.pulsar.broker.PulsarServerException;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.systopic.EventType;
+import org.apache.pulsar.broker.systopic.NamespaceEventsSystemTopicFactory;
+import org.apache.pulsar.broker.systopic.SystemTopic;
+import org.apache.pulsar.broker.systopic.TopicEvent;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.policies.data.TopicPolicies;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Topic policies service
+ */
+public class TopicPoliciesService {
+
+private final PulsarService pulsarService;
+private NamespaceEventsSystemTopicFactory 
namespaceEventsSystemTopicFactory;
+
+private final Map policiesCache = new 
ConcurrentHashMap<>();
+
+private final LoadingCache> readerCache;
+
+public TopicPoliciesService(PulsarService pulsarService) {
+this(pulsarService, 1000, 10, TimeUnit.MINUTES);
+}
+
+public TopicPoliciesService(PulsarService pulsarService, long cacheSize, 
long cacheExpireDuration, TimeUnit cacheExpireUnit) {
+this.pulsarService = pulsarService;
+this.readerCache = CacheBuilder.newBuilder()
+.maximumSize(cacheSize)
+.expireAfterAccess(cacheExpireDuration, cacheExpireUnit)
+.removalListener((RemovalListener>) notification -> {
+NamespaceName namespaceName = notification.getKey();
+if (log.isDebugEnabled()) {
+log.debug("Reader cache was evicted for namespace {}, 
current reader cache size is {} ", namespaceName,
+
TopicPoliciesService.this.readerCache.asMap().size());
+}
+policiesCache.entrySet().removeIf(entry -> 
entry.getKey().getNamespaceObject().equals(namespaceName));
+if (log.isDebugEnabled()) {
+log.debug("Topic policies cache deleted success, current 
policies cache size is {} ", policiesCache.size());
+}
+notification.getValue().whenComplete((reader, ex) -> {
+if (ex == null && reader != null) {
+reader.closeAsync().whenComplete((v, e) -> {
+if (e != null) {
+log.error("Close system topic reader error for 
reader cache expire", e);
+} else {
+if (log.isDebugEnabled()) {
+log.debug("Reader for system topic {} is 
closed.", reader.getSystemTopic().getTopicName());
+}
+}
+});
+} else {
+
TopicPoliciesService.this.readerCache.asMap().remove(namespaceName, 
notification.getValue());
+}
+});
+})
+.build(new CacheLoader>() {
+@Override
+public CompletableFuture 
load(NamespaceName namespaceName) {
+CompletableFuture readerFuture = 
loadSystemTopicReader(namespaceName);
+readerFuture.whenComplete((r, cause) -> {
+if (null != cause || r == 

[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r315512537
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/TopicPoliciesService.java
 ##
 @@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service;
+
+import org.apache.pulsar.broker.PulsarServerException;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.cache.TopicPoliciesCache;
+import org.apache.pulsar.broker.systopic.EventType;
+import org.apache.pulsar.broker.systopic.NamespaceEventsSystemTopicService;
+import org.apache.pulsar.broker.systopic.SystemTopic;
+import org.apache.pulsar.broker.systopic.TopicEvent;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.policies.data.TopicPolicies;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Topic policies service
+ */
+public class TopicPoliciesService {
+
+private final PulsarService pulsarService;
+private final TopicPoliciesCache topicPoliciesCache;
+private NamespaceEventsSystemTopicService 
namespaceEventsSystemTopicService;
+private Map readers;
 
 Review comment:
   final


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r316409421
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/systopic/EventType.java
 ##
 @@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.systopic;
+
+/**
+ * Pulsar system event type
+ */
+public enum EventType {
 
 Review comment:
   same comments as above.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r315512692
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/TopicPoliciesService.java
 ##
 @@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service;
+
+import org.apache.pulsar.broker.PulsarServerException;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.cache.TopicPoliciesCache;
+import org.apache.pulsar.broker.systopic.EventType;
+import org.apache.pulsar.broker.systopic.NamespaceEventsSystemTopicService;
+import org.apache.pulsar.broker.systopic.SystemTopic;
+import org.apache.pulsar.broker.systopic.TopicEvent;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.policies.data.TopicPolicies;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Topic policies service
+ */
+public class TopicPoliciesService {
+
+private final PulsarService pulsarService;
+private final TopicPoliciesCache topicPoliciesCache;
+private NamespaceEventsSystemTopicService 
namespaceEventsSystemTopicService;
+private Map readers;
+
+public TopicPoliciesService(PulsarService pulsarService, 
TopicPoliciesCache topicPoliciesCache) {
+this.pulsarService = pulsarService;
+this.topicPoliciesCache = topicPoliciesCache;
+this.readers = new ConcurrentHashMap<>();
+}
+
+public TopicPolicies getTopicPolicies(TopicName topicName) {
+return topicPoliciesCache.getTopicPolicies(topicName);
+}
+
+public void namespaceOwned(NamespaceName namespaceName) {
+try {
+synchronized (this) {
+if (namespaceEventsSystemTopicService == null) {
+namespaceEventsSystemTopicService = new 
NamespaceEventsSystemTopicService(pulsarService.getClient());
+}
+if (readers.containsKey(namespaceName)) {
 
 Review comment:
   do you need to put line 64-66 in the synchronized block?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r316409633
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/systopic/PulsarEvent.java
 ##
 @@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.systopic;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class PulsarEvent {
 
 Review comment:
   same comments as above


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r315511828
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
 ##
 @@ -383,6 +387,14 @@ public void start() throws PulsarServerException {
 
 brokerService.start();
 
+if (config.isSystemTopicEnable()) {
+namespaceEventsSystemTopicService = new 
NamespaceEventsSystemTopicService(getClient());
+}
+
+if (config.isTopicLevelPoliciesEnable()) {
 
 Review comment:
   Don't we need to check if system topic is enabled?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r315511615
 
 

 ##
 File path: conf/broker.conf
 ##
 @@ -284,6 +284,13 @@ replicatedSubscriptionsSnapshotTimeoutSeconds=30
 # Max number of snapshot to be cached per subscription.
 replicatedSubscriptionsSnapshotMaxCachedPerSubscription=10
 
+# Enable or disable system topic
+systemTopicEnable=true
+
+# Enable or disable topic level policies, topic level policies depends on the 
system topic
+# Please enable the system topic first.
+topicLevelPoliciesEnable=true
 
 Review comment:
   `topicLevelPoliciesEnabled`


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r316409583
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/systopic/NamespaceEventsSystemTopicFactory.java
 ##
 @@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.systopic;
+
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.naming.TopicName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NamespaceEventsSystemTopicFactory {
+
+public static final String LOCAL_TOPIC_NAME = "__change_events";
 
 Review comment:
   define this constant in `common` module.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce system topic and topic policies service

2019-08-21 Thread GitBox
sijie commented on a change in pull request #4955: [WIP] [PIP-39] Introduce 
system topic and topic policies service
URL: https://github.com/apache/pulsar/pull/4955#discussion_r315512176
 
 

 ##
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
 ##
 @@ -652,8 +652,9 @@ private void createPersistentTopic(final String topic, 
boolean createIfMissing,
 @Override
 public void openLedgerComplete(ManagedLedger ledger, 
Object ctx) {
 try {
-PersistentTopic persistentTopic = new 
PersistentTopic(topic, ledger,
-BrokerService.this);
+PersistentTopic persistentTopic = 
isSystemTopic(topic)
 
 Review comment:
   `PersistentTopic persistentTopic = new PersistentTopic(topic, ledger, 
BrokerService.this, isSystemTopic(topic));`


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services