当前位置: 首页>>代码示例>>Java>>正文


Java TxnIterator.getStorageSize方法代码示例

本文整理汇总了Java中org.apache.zookeeper.server.persistence.TxnLog.TxnIterator.getStorageSize方法的典型用法代码示例。如果您正苦于以下问题:Java TxnIterator.getStorageSize方法的具体用法?Java TxnIterator.getStorageSize怎么用?Java TxnIterator.getStorageSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.zookeeper.server.persistence.TxnLog.TxnIterator的用法示例。


在下文中一共展示了TxnIterator.getStorageSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getProposalsFromTxnLog

import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator; //导入方法依赖的package包/类
/**
 * Get proposals from txnlog. Only packet part of proposal is populated.
 *
 * @param startZxid the starting zxid of the proposal
 * @param sizeLimit maximum on-disk size of txnlog to fetch
 *                  0 is unlimited, negative value means disable.
 * @return list of proposal (request part of each proposal is null)
 */
public Iterator<Proposal> getProposalsFromTxnLog(long startZxid,
                                                 long sizeLimit) {
    if (sizeLimit < 0) {
        LOG.debug("Negative size limit - retrieving proposal via txnlog is disabled");
        return TxnLogProposalIterator.EMPTY_ITERATOR;
    }

    TxnIterator itr = null;
    try {

        itr = snapLog.readTxnLog(startZxid, false);

        // If we cannot guarantee that this is strictly the starting txn
        // after a given zxid, we should fail.
        if ((itr.getHeader() != null)
                && (itr.getHeader().getZxid() > startZxid)) {
            LOG.warn("Unable to find proposals from txnlog for zxid: "
                    + startZxid);
            itr.close();
            return TxnLogProposalIterator.EMPTY_ITERATOR;
        }

        if (sizeLimit > 0) {
            long txnSize = itr.getStorageSize();
            if (txnSize > sizeLimit) {
                LOG.info("Txnlog size: " + txnSize + " exceeds sizeLimit: "
                        + sizeLimit);
                itr.close();
                return TxnLogProposalIterator.EMPTY_ITERATOR;
            }
        }
    } catch (IOException e) {
        LOG.error("Unable to read txnlog from disk", e);
        try {
            if (itr != null) {
                itr.close();
            }
        } catch (IOException ioe) {
            LOG.warn("Error closing file iterator", ioe);
        }
        return TxnLogProposalIterator.EMPTY_ITERATOR;
    }
    return new TxnLogProposalIterator(itr);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:53,代码来源:ZKDatabase.java


注:本文中的org.apache.zookeeper.server.persistence.TxnLog.TxnIterator.getStorageSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。