es底层lucene保证indexwrite和translog的数据一致性,为什么还要采用2PC机制?
Elasticsearch | 作者 jianjianhe | 发布于2018年06月29日 | 阅读数:3526
通过es的lucene源码中看到有一个TwoPhaseCommit接口,接口的实现类有两个:IndexWrite和Translog,
public interface TwoPhaseCommit {
/**
* The first stage of a 2-phase commit. Implementations should do as much work
* as possible in this method, but avoid actual committing changes. If the
* 2-phase commit fails, {@link #rollback()} is called to discard all changes
* since last successful commit.
*/
public long prepareCommit() throws IOException;
/**
* The second phase of a 2-phase commit. Implementations should ideally do
* very little work in this method (following {@link #prepareCommit()}, and
* after it returns, the caller can assume that the changes were successfully
* committed to the underlying storage.
*/
public long commit() throws IOException;
/**
* Discards any changes that have occurred since the last commit. In a 2-phase
* commit algorithm, where one of the objects failed to {@link #commit()} or
* {@link #prepareCommit()}, this method is used to roll all other objects
* back to their previous state.
*/
public void rollback() throws IOException;
}
我记得es的一致性性是采用类似raft协议的选举算法实现的,为什么这里还要用的两段式提交,2PC效率低,因为是同步阻塞,必须全部成功,
3 个回复
ScriptShi
赞同来自:
参考来源:https://zhuanlan.zhihu.com/p/34830403
ScriptShi
赞同来自:
code4j - coder github: https://github.com/rpgmakervx
赞同来自: