どのようにデータ・ストレージ・パスElasticsearchインデックスが決定されます

Elasticsearch、ノード構成を指定することができるpath.dataストレージノードカタログデータとして使用され、我々はパスデータストレージとして複数の値を指定することができ、次いでElasticsearchは横に格納すべき経路を決定する方法は?今日、私はこの問題を記録しました。

Elasticsearchインデックス作成プロセス

  1. クラスタマスターは、インデックスを作成するためのステップの数によって、インデックスを作成する要求を受信した後、作成されたインデックスは、最終的にCLUSTERSTATEに要求を提出します
  2. マスターはCLUSTERSTATEポイントに応じて、すべてのノードに配布されます
  3. これはシャードノードがローカルで利用可能な読み出し作成含むpath.data、次いで一定の規則に従ってパスを取得します。
  4. 基本的なシャードパスの作成、シャード基本的な情報を保存します。

そのディレクトリの下を確認する方法

ソース

メイン・コールはselectNewPathForShardのShardPath方法であります

   for (NodeEnvironment.NodePath nodePath : env.nodePaths()) {
                totFreeSpace = totFreeSpace.add(BigInteger.valueOf(nodePath.fileStore.getUsableSpace()));
            }

            // TODO: this is a hack!!  We should instead keep track of incoming (relocated) shards since we know
            // how large they will be once they're done copying, instead of a silly guess for such cases:

            // Very rough heuristic of how much disk space we expect the shard will use over its lifetime, the max of current average
            // shard size across the cluster and 5% of the total available free space on this node:
            BigInteger estShardSizeInBytes = BigInteger.valueOf(avgShardSizeInBytes).max(totFreeSpace.divide(BigInteger.valueOf(20)));

            // TODO - do we need something more extensible? Yet, this does the job for now...
            final NodeEnvironment.NodePath[] paths = env.nodePaths();

            // If no better path is chosen, use the one with the most space by default
            NodeEnvironment.NodePath bestPath = getPathWithMostFreeSpace(env);

            if (paths.length != 1) {
                Map<NodeEnvironment.NodePath, Long> pathToShardCount = env.shardCountPerPath(shardId.getIndex());

                // Compute how much space there is on each path
                final Map<NodeEnvironment.NodePath, BigInteger> pathsToSpace = new HashMap<>(paths.length);
                for (NodeEnvironment.NodePath nodePath : paths) {
                    FileStore fileStore = nodePath.fileStore;
                    BigInteger usableBytes = BigInteger.valueOf(fileStore.getUsableSpace());
                    pathsToSpace.put(nodePath, usableBytes);
                }

                bestPath = Arrays.stream(paths)
                        // Filter out paths that have enough space
                        .filter((path) -> pathsToSpace.get(path).subtract(estShardSizeInBytes).compareTo(BigInteger.ZERO) > 0)
                        // Sort by the number of shards for this index
                        .sorted((p1, p2) -> {
                                int cmp = Long.compare(pathToShardCount.getOrDefault(p1, 0L),
                                    pathToShardCount.getOrDefault(p2, 0L));
                                if (cmp == 0) {
                                    // if the number of shards is equal, tie-break with the number of total shards
                                    cmp = Integer.compare(dataPathToShardCount.getOrDefault(p1.path, 0),
                                            dataPathToShardCount.getOrDefault(p2.path, 0));
                                    if (cmp == 0) {
                                        // if the number of shards is equal, tie-break with the usable bytes
                                        cmp = pathsToSpace.get(p2).compareTo(pathsToSpace.get(p1));
                                    }
                                }
                                return cmp;
                            })
                        // Return the first result
                        .findFirst()
                        // Or the existing best path if there aren't any that fit the criteria
                        .orElse(bestPath);
            }

            statePath = bestPath.resolve(shardId);
            dataPath = statePath;
        }

プロセス分析

  1. まず、カスタムのかどうかを判断するpath.data、いかなるカスタムデフォルトのパスに作成されていません
  2. 空間の少なくとも5%を確保する定義されたノードの場合は使用することができるので
  3. すべてのパスを取得し、
  4. 次に、設定されたデフォルトのパスは、最良のパスは、現在、ほとんどのスペースを持ってい
  5. それは行にない場合、すべてのパスを通って、第一のすべての空間フィルタリングへのパスが存在しない、彼らは、ステップに進み、さもなければ、経路4つの手順を返す6
  6. ソートルール経路によれば、最初のシャードインデックスの最小数を含む各シャード指数より低い優先度のリターンパスのパスの数が存在するかどうかを判断し、
    条件が結果と同じである場合、各経路は、いくつかの比較シャード合計(すべてのインデックス)が含まれリターンパスは、断片の最小数を含み、
    第二の条件と同じ結果が、利用可能なスペース、ほとんどの利用可能なスペースのリターンパスを比較すると
  7. 適切なパスを生成し、ディレクトリやその他の情報を作成します。

 

 

298元記事公開 ウォンの賞賛107 ビューに14万+を

おすすめ

転載: blog.csdn.net/ywl470812087/article/details/104874698