close() called when transaction is OPEN 一般思路

来源:互联网 发布:python stringbuffer 编辑:程序博客网 时间:2024/05/29 18:18

自定义flume  sink 操作的时候,往往可能报这样的错

close() called when transaction is OPEN    ,   close() called when transaction is begin()  等,什么原因造成的???

我也说不清楚,一般是在sink的transaction开始时,处理获取的event,但是没有处理完,又有新的Transaction开始

造成的线程间的干扰吧。也不是很明白,这个错误有时候报,有时候又没了。。。

看一段代码。

Transaction tx = null ;Status status=null;logger.debug("开始一个Transaction");Channel channel= getChannel();try{tx= channel.getTransaction();tx.begin();for(int i=0;i<batchSize;i++){// 使用take方法尽可能的以批量的方式从Channel中读取事件,直到没有更多的事件Event event =  channel.take();if(event==null){break;}else{  // 也可以不需要elsebyte[] body = event.getBody();String str=new String(body);logger.info("********************开始插入******");this.storeMongo(str);}}tx.commit();status=Status.READY;}catch (Exception e) {            logger.error("can't process events, drop it!", e);            if (tx != null) {                tx.commit();// commit to drop bad event, otherwise it will enter dead loop.            }        } finally {            if (tx != null) {            logger.debug("结束一个Transaction");                tx.close();            }        }return status;

我的只能是这样的了,或许有更好的形式,但是一般的结构都这样,也没有固定的标准。 这样的写法是开启一个Transaction后,可以从 Channel中获取较多的event,看source获取的数目。

不敢保证上面的那个错误再出现,我是在虚拟机上没问题,到服务器就出现上面的问题的。。。尴尬噻


0 0
原创粉丝点击