Search in sources :

Example 1 with BatchCache

use of com.alibaba.jstorm.transactional.BatchCache in project jstorm by alibaba.

the class TransactionBolt method prepare.

@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.conf = stormConf;
    this.topologyContext = context;
    this.topologyId = topologyContext.getTopologyId();
    this.taskId = topologyContext.getThisTaskId();
    this.componentId = topologyContext.getThisComponentId();
    this.upstreamTasks = TransactionCommon.getUpstreamTasks(componentId, topologyContext);
    this.downstreamTasks = TransactionCommon.getDownstreamTasks(componentId, topologyContext);
    this.topologyMasterId = context.getTopologyMasterId();
    LOG.info("TransactionBolt: upstreamTasks=" + upstreamTasks + ", downstreamTasks=" + downstreamTasks);
    this.outputCollector = new TransactionOutputCollector(this, collector);
    this.boltExecutor.prepare(conf, context, new OutputCollector(outputCollector));
    this.boltStatus = State.INIT;
    if (sysTopology == null) {
        try {
            sysTopology = Common.system_topology(stormConf, context.getRawTopology());
        } catch (InvalidTopologyException e) {
            LOG.error("Failed to build system topology", e);
            throw new RuntimeException(e);
        }
    }
    this.lastSuccessfulBatch = new ConcurrentHashMap<Integer, Long>();
    this.processingBatches = new HashMap<Integer, Map<Long, BatchTracker>>();
    Set<String> upstreamSpoutNames = TransactionCommon.getUpstreamSpouts(componentId, topologyContext);
    for (String spoutName : upstreamSpoutNames) {
        int groupId = TransactionCommon.groupIndex(topologyContext.getRawTopology(), spoutName);
        lastSuccessfulBatch.put(groupId, TransactionCommon.INIT_BATCH_ID);
        processingBatches.put(groupId, new HashMap<Long, BatchTracker>());
    }
    this.batchCache = new BatchCache(context, upstreamSpoutNames, sysTopology);
    this.kryoInput = new Input(1);
    this.streamIds = new SerializationFactory.IdDictionary(sysTopology);
    this.inputStreamIds = new HashSet<Integer>();
    Set<GlobalStreamId> inputs = topologyContext.getThisSources().keySet();
    for (GlobalStreamId stream : inputs) {
        inputStreamIds.add(streamIds.getStreamId(stream.get_componentId(), stream.get_streamId()));
    }
    for (String upstreamComponentId : TransactionCommon.getUpstreamComponents(componentId, topologyContext)) {
        inputStreamIds.add(streamIds.getStreamId(upstreamComponentId, TransactionCommon.BARRIER_STREAM_ID));
    }
    //LOG.info("Stream info prepare: streamIds={}, inputStreams={}, inputStreamIds={}", streamIds, inputs, inputStreamIds);
    startInitState();
}
Also used : OutputCollector(backtype.storm.task.OutputCollector) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) SerializationFactory(backtype.storm.serialization.SerializationFactory) BatchCache(com.alibaba.jstorm.transactional.BatchCache) Input(com.esotericsoftware.kryo.io.Input) GlobalStreamId(backtype.storm.generated.GlobalStreamId) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

GlobalStreamId (backtype.storm.generated.GlobalStreamId)1 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)1 SerializationFactory (backtype.storm.serialization.SerializationFactory)1 OutputCollector (backtype.storm.task.OutputCollector)1 BatchCache (com.alibaba.jstorm.transactional.BatchCache)1 Input (com.esotericsoftware.kryo.io.Input)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1