本文整理汇总了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);
}