0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ninda 21日目: パーティショニング 〜大規模データの分散〜

Last updated at Posted at 2025-12-20

今日のゴール

  • コンシステントハッシングを理解する
  • データのパーティショニング方法を学ぶ
  • レプリケーション戦略を理解する

コンシステントハッシング

ハッシュリングでデータを分散:

タプルのハッシュ値に基づいて、最も近いノードに配置。


HashRingの使用

import ninda/distributed/partition

proc hashRingExample() {.async.} =
  var ring = newHashRing()

  # ノードを追加
  ring.addNode("node-1")
  ring.addNode("node-2")
  ring.addNode("node-3")

  # タプルの担当ノードを取得
  let tuple = toTuple(strVal("key"), intVal(100))
  let nodes = ring.getNodesForTuple(tuple)
  echo "Responsible nodes: ", nodes

  # パターンの担当ノード
  let pattern = toPattern(strVal("key"), nilValue())
  let patternNodes = ring.getNodesForPattern(pattern)
  echo "Pattern nodes: ", patternNodes

  # ノード削除(データ再分散)
  ring.removeNode("node-2")

waitFor hashRingExample()

レプリケーション

デフォルトで3レプリカ:


ノード追加時の再バランス

Before:                After adding N4:
  N1: [0-120]            N1: [0-90]
  N2: [120-240]    →     N2: [120-210]
  N3: [240-360]          N3: [240-330]
                         N4: [90-120, 210-240, 330-360]

まとめ

今日はパーティショニングを学びました:

  • コンシステントハッシング: データの分散配置
  • レプリケーション: 耐障害性のためのコピー
  • 再バランス: ノード追加・削除時のデータ移動

前回: クラスタ構成 | 目次 | 次回: 障害検知と復旧

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?