Tencent / TubeMQ

TubeMQ has been donated to the Apache Software Foundation and renamed to InLong, please visit the new Apache repository: https://github.com/apache/incubator-inlong
https://inlong.apache.org/
2.02k stars 388 forks source link

redundancy encoding when loading meta-data from BDB-JE #89

Closed aloyszhang closed 5 years ago

aloyszhang commented 5 years ago

There are some redundancy encoding when loading meta-data from BDB-JE like this :

if (logger.isDebugEnabled()) {
                StringBuilder sBuilder = new StringBuilder(512);
                logger.debug("[Load topic config] load broker topic record start:");
                for (BdbTopicConfEntity bdbEntity : cursor) {
                    if (bdbEntity == null) {
                        logger.warn("[BDB Error] Found Null data while loading from topicConfIndex!");
                        continue;
                    }
                    ConcurrentHashMap<String/* topicName */, BdbTopicConfEntity> brokerTopicMap =
                            brokerIdTopicEntityMap.get(bdbEntity.getBrokerId());
                    if (brokerTopicMap == null) {
                        brokerTopicMap =
                                new ConcurrentHashMap<String, BdbTopicConfEntity>();
                        brokerIdTopicEntityMap.put(bdbEntity.getBrokerId(), brokerTopicMap);
                    }
                    brokerTopicMap.put(bdbEntity.getTopicName(), bdbEntity);
                    count++;
                    logger.debug(bdbEntity.toJsonString(sBuilder).toString());
                    sBuilder.delete(0, sBuilder.length());
                }
                logger.debug("[Load topic config] load broker topic record finished!");
            } else {
                for (BdbTopicConfEntity bdbEntity : cursor) {
                    if (bdbEntity == null) {
                        logger.warn("[BDB Error] Found Null data while loading from topicConfIndex!");
                        continue;
                    }
                    ConcurrentHashMap<String/* topicName */, BdbTopicConfEntity> brokerTopicMap =
                            brokerIdTopicEntityMap.get(bdbEntity.getBrokerId());
                    if (brokerTopicMap == null) {
                        brokerTopicMap =
                                new ConcurrentHashMap<String, BdbTopicConfEntity>();
                        brokerIdTopicEntityMap.put(bdbEntity.getBrokerId(), brokerTopicMap);
                    }
                    brokerTopicMap.put(bdbEntity.getTopicName(), bdbEntity);
                    count++;
                }
            }

I think we can make some condense about this. @gosonzhang

gosonzhang commented 5 years ago

Yes, these codes are more concise after this modification, thank you!