elasticsearch5 源码 索引过程
来源:互联网 发布:h3c 3600端口acl 编辑:程序博客网 时间:2024/06/06 03:37
elasticsearch
1、索引入口RestIndexAction方法中prepareRequest,封装IndexRequest,并由NodeClient调用index方法
client.index(indexRequest, new RestStatusToXContentListener<>(channel, r -> r.getLocation(indexRequest.routing())));
2、中间经过一些抽象类中方法调用后来到NodeClient类中的executeLocally方法,经过一系列的判断校验等到TransportIndexAction
3、TransportIndexAction中doExecute方法会有一个判断是否自动创建索引,暂时先考虑不自动创建
ClusterState state = clusterService.state();
if (shouldAutoCreate(request, state)) { //是否自动创建索引
...................................................
} else {
innerExecute(task, request, listener);
}
4、主要操作都在TransportReplicationAction类中,ReroutePhase内部类中的doRun方法判断是否本地执行
5、TransportReplicationAction中AsyncPrimaryAction异步执行索引操作
6、ReplicationOperation执行execute方法,primary.perform(request)主分片索引,
public void execute() throws Exception { final String activeShardCountFailure = checkActiveShardCount(); final ShardRouting primaryRouting = primary.routingEntry(); final ShardId primaryId = primaryRouting.shardId(); if (activeShardCountFailure != null) { finishAsFailed(new UnavailableShardsException(primaryId, "{} Timeout: [{}], request: [{}]", activeShardCountFailure, request.timeout(), request)); return; } totalShards.incrementAndGet(); pendingActions.incrementAndGet(); primaryResult = primary.perform(request); //主分片索引 final ReplicaRequest replicaRequest = primaryResult.replicaRequest(); assert replicaRequest.primaryTerm() > 0 : "replicaRequest doesn't have a primary term"; if (logger.isTraceEnabled()) { logger.trace("[{}] op [{}] completed on primary for request [{}]", primaryId, opType, request); } // we have to get a new state after successfully indexing into the primary in order to honour recovery semantics. // we have to make sure that every operation indexed into the primary after recovery start will also be replicated // to the recovery target. If we use an old cluster state, we may miss a relocation that has started since then. ClusterState clusterState = clusterStateSupplier.get(); final List<ShardRouting> shards = getShards(primaryId, clusterState); Set<String> inSyncAllocationIds = getInSyncAllocationIds(primaryId, clusterState); markUnavailableShardsAsStale(replicaRequest, inSyncAllocationIds, shards); //标记不可用副本分片 performOnReplicas(replicaRequest, shards); //副本 和主分片相同入库到内存并标记Translog successfulShards.incrementAndGet(); decPendingAndFinishIfNeeded(); }
public static WriteResult<IndexResponse> executeIndexRequestOnPrimary(IndexRequest request, IndexShard indexShard, MappingUpdatedAction mappingUpdatedAction) throws Exception { Engine.Index operation = prepareIndexOperationOnPrimary(request, indexShard); //模板合并等操作并封装Engine.Index Mapping update = operation.parsedDoc().dynamicMappingsUpdate(); final ShardId shardId = indexShard.shardId(); if (update != null) { mappingUpdatedAction.updateMappingOnMaster(shardId.getIndex(), request.type(), update); //master模板修改 operation = prepareIndexOperationOnPrimary(request, indexShard); update = operation.parsedDoc().dynamicMappingsUpdate(); if (update != null) { throw new ReplicationOperation.RetryOnPrimaryException(shardId, "Dynamic mappings are not available on the node that holds the primary yet"); } } indexShard.index(operation); //索引入内存并添加Translog // update the version on request so it will happen on the replicas final long version = operation.version(); request.version(version); request.versionType(request.versionType().versionTypeForReplicationAndRecovery()); assert request.versionType().validateVersionForWrites(request.version()); IndexResponse response = new IndexResponse(shardId, request.type(), request.id(), request.version(), operation.isCreated()); return new WriteResult<>(response, operation.getTranslogLocation()); }
- elasticsearch5 源码 索引过程
- Elasticsearch5.X索引
- solr索引过程源码解析
- elasticsearch5.1.2安装过程记录
- Solr分布式索引过程源码解析
- 深入elasticsearch源码之索引过程
- elasticsearch5.3.0 索引创建及查询
- Elasticsearch5.3 用JAVA创建索引
- Elasticsearch源码分析之二------索引过程源码概要分析
- ElasticSearch源码分析之二:索引过程源码概要分析
- elasticsearch5.4.0安装head插件过程
- Lucene3.4索引文件创建过程(有源码)
- lucene4.5源码分析系列:索引的创建过程
- lucene源码-倒排索引的读过程
- elasticsearch5.0.1集群索引分片丢失的处理
- ElasticSearch5.X—模糊查询和获取所有索引字段
- elasticsearch5.0.1源码调试配置(附源码+环境配置文件)
- elasticsearch5.4.2安装以及插件head的安装过程
- jquery 动态生成form提交数据的例子, 及其 form is not connected 错误解决
- 单点登录使用
- 归并排序的同时求逆序数
- linux-用户命令
- 手机卫士02
- elasticsearch5 源码 索引过程
- Docker学习(二)Docker架构
- 世界主要城市中英文对照表(json格式)
- java连接ElasticSearch集群
- mycat2.0源码分析02-客户端发送认证报文
- beego 如何自定error
- Java NIO的非阻塞式网络通讯
- 登录注册案例(集合实现)
- tomcat内存溢出解决,java.lang.OutOfMemoryError: PermGen space