Class: Tair::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/tair/cluster.rb

Overview

一个 cluster 是一个 tair 节点组合 cluster 由 bucket 构成 bucket 由 data_node 构成 node -> bucket -> cluster

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#copying_buckets_countObject (readonly)

Returns the value of attribute copying_buckets_count.



9
10
11
# File 'lib/tair/cluster.rb', line 9

def copying_buckets_count
  @copying_buckets_count
end

#nodes_per_bucketObject (readonly)

Returns the value of attribute nodes_per_bucket.



9
10
11
# File 'lib/tair/cluster.rb', line 9

def nodes_per_bucket
  @nodes_per_bucket
end

Instance Method Details

#bucketsObject



44
45
46
# File 'lib/tair/cluster.rb', line 44

def buckets
  @bucket ||= [nodes]
end

#data_node_for(key, will_write_data: false) ⇒ Object

根据指定的值,找到对应的数据节点



13
14
15
16
17
18
# File 'lib/tair/cluster.rb', line 13

def data_node_for key, will_write_data: false
  tair_key = Tair::TairObject.from(key).to_binary_s[4..-1]
  digest   = Tair::Protocol::Murmurhash.digest tair_key, 97
  idx      = digest % nodes_per_bucket
  primary_nodes[idx]
end

#nodesObject Also known as: primary_nodes



34
35
36
# File 'lib/tair/cluster.rb', line 34

def nodes
  @nodes
end

#update(nodes, nodes_per_bucket: nil, copying_buckets_count: 0) ⇒ Object

更新集群信息

Params:

- nodes Array 所有节点数组
- nodes_per_bucket Integer 多少个节点构成一个 bucket
- bucket_for_copy  Integer 有多少个 bucket 用来作备库


27
28
29
30
31
# File 'lib/tair/cluster.rb', line 27

def update(nodes, nodes_per_bucket: nil, copying_buckets_count: 0)
  @nodes_per_bucket      = nodes_per_bucket
  @nodes                 = nodes.first(nodes_per_bucket)
  @copying_buckets_count = copying_buckets_count
end