DefaultMemStore:
@Override
public void rollback(Cell cell) {
// If the key is in the snapshot, delete it. We should not update
// this.size, because that tracks the size of only the memstore and
// not the snapshot. The flush of this snapshot to disk has not
// yet started because Store.flush() waits for all rwcc transactions to
// commit before starting the flush to disk.
Cell found = this.snapshot.get(cell);
if (found != null && found.getSequenceId() == cell.getSequenceId()) {
this.snapshot.remove(cell);
long sz = heapSizeChange(cell, true);
this.snapshotSize -= sz;
}
// If the key is in the memstore, delete it. Update this.size.
found = this.cellSet.get(cell);
if (found != null && found.getSequenceId() == cell.getSequenceId()) {
removeFromCellSet(cell);
long s = heapSizeChange(cell, true);
this.size.addAndGet(-s);
}
}
这段代码里面有段注释:
The flush of this snapshot to disk has not yet started because Store.flush() waits for all rwcc transactions to
commit before starting the flush to disk.
flush之前会等之前的事务都完成。
我们来看下flush相关逻辑:
HRegion:
protected PrepareFlushResult internalPrepareFlushCache(final WAL wal, final long myseqid,
final Collection<Store> storesToFlush, MonitoredTask status, boolean writeFlushWalMarker)
throws IOException {
。。。
writeEntry = mvcc.beginMemstoreInsert();
// wait for all in-progress transactions to commit to WAL before
// we can start the flush. This prevents
// uncommitted transactions from being written into HFiles.
// We have to block before we start the flush, otherwise keys that
// were removed via a rollbackMemstore could be written to Hfiles.
mvcc.waitForPreviousTransactionsComplete(writeEntry);
。。。
}
代码是1.1.2版本
本文详细介绍了 HBase 中 DefaultMemStore 的回滚操作及 Flush 过程中的事务等待机制。解释了如何防止未提交的事务被写入到 HFile 中,确保数据的一致性。


被折叠的 条评论
为什么被折叠?



