Source:
public void poll() { try { if (!started) { return; } ConcurrentHashMap<String, DruidDataSource> newDataSources = new ConcurrentHashMap<String, DruidDataSource>(); log.debug("Starting polling of segment table"); final List<DataSegment> segments = connector.getDBI().inTransaction( new TransactionCallback<List<DataSegment>>() { @Override public List<DataSegment> inTransaction(Handle handle, TransactionStatus status) throws Exception { return handle .createQuery(String.format("SELECT payload FROM %s WHERE used=true", getSegmentsTable())) .setFetchSize(connector.getStreamingFetchSize()) .map( new ResultSetMapper<DataSegment>() { @Override public DataSegment map(int index, ResultSet r, StatementContext ctx) throws SQLException { try { return jsonMapper.readValue(r.getBytes("payload"), DataSegment.class); } catch (IOException e) { log.makeAlert(e, "Failed to read segment from db."); return null; } } } ) .list(); } } ); if (segments == null || segments.isEmpty()) { log.warn("No segments found in the database!"); return; } final Collection<DataSegment> segmentsFinal = Collections2.filter( segments, Predicates.notNull() ); log.info("Polled and found %,d segments in the database", segments.size()); for (final DataSegment segment : segmentsFinal) { String datasourceName = segment.getDataSource(); DruidDataSource dataSource = newDataSources.get(datasourceName); if (dataSource == null) { dataSource = new DruidDataSource( datasourceName, ImmutableMap.of("created", new DateTime().toString()) ); Object shouldBeNull = newDataSources.put( datasourceName, dataSource ); if (shouldBeNull != null) { log.warn( "Just put key[%s] into dataSources and what was there wasn't null!? It was[%s]", datasourceName, shouldBeNull ); } } if (!dataSource.getSegments().contains(segment)) { dataSource.addSegment(segment.getIdentifier(), segment); } } synchronized (lock) { if (started) { dataSources.set(newDataSources); } } } catch (Exception e) { log.makeAlert(e, "Problem polling DB.").emit(); } }

Target:
public void poll() { try { if (!started) { return; } ConcurrentHashMap<String, DruidDataSource> newDataSources = new ConcurrentHashMap<String, DruidDataSource>(); log.debug("Starting polling of segment table"); final List<DataSegment> segments = inReadOnlyTransaction( new TransactionCallback<List<DataSegment>>() { @Override public List<DataSegment> inTransaction(Handle handle, TransactionStatus status) throws Exception { return handle .createQuery(String.format("SELECT payload FROM %s WHERE used=true", getSegmentsTable())) .setFetchSize(connector.getStreamingFetchSize()) .map( new ResultSetMapper<DataSegment>() { @Override public DataSegment map(int index, ResultSet r, StatementContext ctx) throws SQLException { try { return jsonMapper.readValue(r.getBytes("payload"), DataSegment.class); } catch (IOException e) { log.makeAlert(e, "Failed to read segment from db."); return null; } } } ) .list(); } } ); if (segments == null || segments.isEmpty()) { log.warn("No segments found in the database!"); return; } final Collection<DataSegment> segmentsFinal = Collections2.filter( segments, Predicates.notNull() ); log.info("Polled and found %,d segments in the database", segments.size()); for (final DataSegment segment : segmentsFinal) { String datasourceName = segment.getDataSource(); DruidDataSource dataSource = newDataSources.get(datasourceName); if (dataSource == null) { dataSource = new DruidDataSource( datasourceName, ImmutableMap.of("created", new DateTime().toString()) ); Object shouldBeNull = newDataSources.put( datasourceName, dataSource ); if (shouldBeNull != null) { log.warn( "Just put key[%s] into dataSources and what was there wasn't null!? It was[%s]", datasourceName, shouldBeNull ); } } if (!dataSource.getSegments().contains(segment)) { dataSource.addSegment(segment.getIdentifier(), segment); } } synchronized (lock) { if (started) { dataSources.set(newDataSources); } } } catch (Exception e) { log.makeAlert(e, "Problem polling DB.").emit(); } }