Github user HeartSaVioR commented on a diff in the pull request:

    https://github.com/apache/storm/pull/1783#discussion_r90260820
  
    --- Diff: 
external/storm-hbase/src/main/java/org/apache/storm/hbase/bolt/HBaseLookupBolt.java
 ---
    @@ -40,51 +48,81 @@
      *
      */
     public class HBaseLookupBolt extends AbstractHBaseBolt {
    -    private static final Logger LOG = 
LoggerFactory.getLogger(HBaseLookupBolt.class);
    +   
    +   private static final long serialVersionUID = 1L;
    +   private static final Logger LOG = 
LoggerFactory.getLogger(HBaseLookupBolt.class);
    +
    +   private HBaseValueMapper rowToTupleMapper;
    +   private HBaseProjectionCriteria projectionCriteria;
    +   private transient LoadingCache<byte[], Result> cache;
    +   private transient boolean cacheEnabled;
     
    -    private HBaseValueMapper rowToTupleMapper;
    +   public HBaseLookupBolt(String tableName, HBaseMapper mapper, 
HBaseValueMapper rowToTupleMapper) {
    +      super(tableName, mapper);
    +      Validate.notNull(rowToTupleMapper, "rowToTupleMapper can not be 
null");
    +      this.rowToTupleMapper = rowToTupleMapper;
    +   }
     
    -    private HBaseProjectionCriteria projectionCriteria;
    +   public HBaseLookupBolt withConfigKey(String configKey) {
    +      this.configKey = configKey;
    +      return this;
    +   }
     
    -    public HBaseLookupBolt(String tableName, HBaseMapper mapper, 
HBaseValueMapper rowToTupleMapper){
    -        super(tableName, mapper);
    -        Validate.notNull(rowToTupleMapper, "rowToTupleMapper can not be 
null");
    -        this.rowToTupleMapper = rowToTupleMapper;
    -    }
    +   public HBaseLookupBolt withProjectionCriteria(HBaseProjectionCriteria 
projectionCriteria) {
    +      this.projectionCriteria = projectionCriteria;
    +      return this;
    +   }
     
    -    public HBaseLookupBolt withConfigKey(String configKey){
    -        this.configKey = configKey;
    -        return this;
    -    }
    +   @SuppressWarnings({ "unchecked", "rawtypes" })
    +   @Override
    +   public void prepare(Map config, TopologyContext topologyContext, 
OutputCollector collector) {
    +      super.prepare(config, topologyContext, collector);
    +      cacheEnabled = 
Boolean.parseBoolean(config.getOrDefault("hbase.cache.enable", 
"false").toString());
    +      int cacheTTL = 
Integer.parseInt(config.getOrDefault("hbase.cache.ttl.seconds", 
"300").toString());
    +      int maxCacheSize = 
Integer.parseInt(config.getOrDefault("hbase.cache.size", "1000").toString());
    +      if (cacheEnabled) {
    +         cache = Caffeine.newBuilder()
    +                       
.maximumSize(maxCacheSize).expireAfterWrite(cacheTTL, TimeUnit.SECONDS)
    +               .build(new CacheLoader<byte[], Result>() {
     
    -    public HBaseLookupBolt withProjectionCriteria(HBaseProjectionCriteria 
projectionCriteria) {
    -        this.projectionCriteria = projectionCriteria;
    -        return this;
    -    }
    +                  @Override
    +                  public Result load(byte[] rowKey) throws Exception {
    +                     Get get = hBaseClient.constructGetRequests(rowKey, 
projectionCriteria);
    +                     LOG.debug("Cache miss for key:"+new String(rowKey));
    --- End diff --
    
    @ambud 
    Could you address @vesense comment? 
    It makes unnecessary creation of String object for non-debug log level.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to