风暴:Tick Tuple给出意想不到的结果

时间:2015-08-12 10:35:04

标签: java cassandra apache-storm

我正在运行一个风暴拓扑,它将数据写入Cassandra数据库,并且每隔15分钟将数据从Cassandra复制到mongoDB。我正在使用Tick-Tuple来实现此目的。当我启动时拓扑它运行正常,直到前15分钟,并将数据写入Cassandra之后,所有数据都被转移到mongodb并从Cassandra中删除。但是,之后数据没有写入Cassandra。虽然我会将所有数据都输入到我的执行方法中,但它也不会抛出任何错误。我也检查了日志,没有错误。

这是将数据插入cassandra的执行方法:

public void execute(Tuple input, BasicOutputCollector collector) {

    String term = input.getString(0);
    int year = input.getInteger(1);
    int month = input.getInteger(2);
    int day = input.getInteger(3);
    int hour = input.getInteger(4);
    int dayofyear = input.getInteger(5);
    int weekofyear = input.getInteger(6);
    int productcount = input.getInteger(7);
    String sessionid = input.getString(8);

    /**
     * Inserting Values In Cassandra
     */

    BoundStatement insertUpdateTable = new BoundStatement(pStatement);
    insertUpdateTable.bind(sessionid, term, year, month, day, hour,
            dayofyear, weekofyear, productcount);

    session.executeAsync(insertUpdateTable);

    LOG.info(
            "Inserted data into table topquery:{},{},{},{},{},{},{},{},{} ",
            term, year, month, day, hour, dayofyear, weekofyear,
            productcount, sessionid);

}

这是Tick-Tuple:

public void prepare(Map stormConf, TopologyContext context) {

    KEYSPACE = stormConf.get(ApplicationConstants._CASSANDRA_KEYSPACE);
    LOG.info("KEYSPACE AT PREPARE METHOD IN TickTuple : {}", KEYSPACE);

}

@Override
public Map<String, Object> getComponentConfiguration() {
    // configure how often a tick tuple will be sent to our bolt
    Config conf = new Config();
    conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, TICK_TUPLE_FREQ_SECS);
    return conf;
}

protected static boolean isTickTuple(Tuple tuple) {
    return tuple.getSourceComponent().equals(Constants.SYSTEM_COMPONENT_ID)
            && tuple.getSourceStreamId().equals(
                    Constants.SYSTEM_TICK_STREAM_ID);
}

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
}

@Override
public void execute(Tuple input, BasicOutputCollector collector) {

    try {
        if (isTickTuple(input)) {

            ArrayList<String> sessionid = new ArrayList<String>();
            /**
             * Returns the List of Inactive SessionID.
             */
            sessionid = InactiveSessionIdTimeStampCassandra
                    .returnInactiveSessionId(KEYSPACE.toString());
            LOG.info("sessionid in TickTuple METHOD IN TickTuple : {}",
                    sessionid);
            /**
             * Exports the Data from Cassandra Tables to MongoDB based on
             * the SessionID returned by the
             * InactiveSessionIdTimeStampCassandra
             * .returnInactiveSessionId().
             */
            CassExport.cassExp(KEYSPACE.toString(),
                    TABLE_CASSANDRA_TOP_QUERY, KEYSPACE.toString(),
                    MONGO_COLLECTION_TopQuery, sessionid);
            LOG.info("cassEport in TickTuple METHOD IN TickTuple : {}",
                    KEYSPACE.toString());
            /**
             * Deletes the Data from the Cassandra Tables based on the
             * SessionID returned by the InactiveSessionIdTimeStampCassandra
             * .returnInactiveSessionId().
             */
            TruncateCassandraTable.truncateData(TABLE_CASSANDRA_TOP_QUERY,
                    sessionid, KEYSPACE.toString());

            LOG.info("In Truncate");
            //return;
        }
    } catch (Exception e) {
        LOG.error("Exception in TickTuple", e);
    }

}

我无法弄清楚原因。

0 个答案:

没有答案