[ 
https://issues.apache.org/jira/browse/BOOKKEEPER-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13457816#comment-13457816
 ] 

Sijie Guo commented on BOOKKEEPER-407:
--------------------------------------

{quote}
The client is only a publisher. Since the publish channel is multiplexed at the 
moment, the channel is not(should not be) disconnected in case of topic 
movement. The client will never clear the topic2Host entry even if the topic 
moves.
{quote}

good point.

I did look at your patch. seems you synchronized on the whole map, it might be 
a big overhead when modifying host2Topics. especially when there are lots of 
topics.

since each time we received a valid response, we would try to set the ownership 
if there is a wrong one. so it seems that we don't needs to have strong 
consistency between topic2host and host2topics. why not leverage the benefits 
of concurrent collections. I had a similar approach for it when refactor java 
client in BOOKKEEPER-364. How is your idea about it?

{code}
    protected void storeTopic2HostMapping(ByteString topic, InetSocketAddress 
host) {
        InetSocketAddress oldHost = topic2Host.putIfAbsent(topic, host);
        if (null != oldHost && oldHost.equals(host)) {
            // Entry in map exists for the topic but it is the same as the
            // current host. In this case there is nothing to do.
            return;
        }

        if (null != oldHost) {
            if (topic2Host.replace(topic, oldHost, host)) {
                // Store the relevant mappings for this topic and host 
combination.
                logger.debug("Storing info for topic: {}, old host: {}, new 
host: {}.",
                             va(topic.toStringUtf8(), oldHost, host));
                clearHostForTopic(topic, oldHost);
            } else {
                logger.warn("Ownership of topic: {} has been changed from {} to 
{} when      storeing host: {}",
                            va(topic.toStringUtf8(), oldHost, 
topic2Host.get(topic), host));                 return;
            }       
        } else {
            logger.debug("Storing info for topic: {}, host: {}.",
                         va(topic.toStringUtf8(), host));
        }
        ConcurrentLinkedQueue<ByteString> topicsForHost = host2Topics.get(host);
        if (null == topicsForHost) {
            ConcurrentLinkedQueue<ByteString> newTopicsList = new               
             ConcurrentLinkedQueue<ByteString>();
            topicsForHost = host2Topics.putIfAbsent(host, newTopicsList);
            if (null == topicsForHost) {
              topicsForHost = newTopicsList;
            }
        }
        topicsForHost.add(topic);
    }
{code}




                
> Hedwig client doesn't remove old topic2Host mapping in case of redirect
> -----------------------------------------------------------------------
>
>                 Key: BOOKKEEPER-407
>                 URL: https://issues.apache.org/jira/browse/BOOKKEEPER-407
>             Project: Bookkeeper
>          Issue Type: Bug
>    Affects Versions: 4.2.0
>            Reporter: Aniruddha
>             Fix For: 4.2.0
>
>         Attachments: BK-407.patch
>
>
> In the storeTopic2HostMapping function, there is a topic2Host.putIfAbsent(). 
> This doesn't seem correct as we should always update the mapping in case of a 
> redirect. 
> Reviewboard : https://reviews.apache.org/r/7139/

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to