Skip to content

Commit

Permalink
Add support for Arbiter pools
Browse files Browse the repository at this point in the history
Signed-off-by: Shree Vatsa N <vatsa@kadalu.tech>
  • Loading branch information
vatsa287 committed May 12, 2023
1 parent 863e621 commit eecc0ce
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
6 changes: 3 additions & 3 deletions mgr/shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ shards:

crinja:
git: https://github.com/straight-shoota/crinja.git
version: 0.8.0
version: 0.8.1

db:
git: https://github.com/crystal-lang/crystal-db.git
Expand All @@ -22,7 +22,7 @@ shards:

kemal:
git: https://github.com/kemalcr/kemal.git
version: 1.3.0
version: 1.4.0

moana_types:
path: ../types
Expand All @@ -38,7 +38,7 @@ shards:

volgen:
git: https://github.com/kadalu/volgen.git
version: 0.3.1
version: 0.4.1

xattr:
git: https://github.com/aravindavk/xattr-crystal.git
Expand Down
20 changes: 19 additions & 1 deletion mgr/src/cmds/pool_create_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ module PoolRequestParser
storage_units["replica"].size,
storage_units["mirror"].size
)
elsif storage_units["arbiter"].size == 3
grp_storage_units = storage_units["arbiter"]
dist_group.replica_count = 3
dist_group.arbiter_count = 1
elsif storage_units["disperse"].size > 0 ||
storage_units["data"].size > 0
grp_storage_units = storage_units["disperse"] +
Expand Down Expand Up @@ -292,7 +296,20 @@ module PoolRequestParser
# TODO: Pool name validations

req.distribute_groups.each do |dist_grp|
if dist_grp.replica_count > 0 && dist_grp.storage_units.size != dist_grp.replica_count
puts "#{dist_grp.arbiter_count}"
puts "#{dist_grp.replica_count}"
puts "#{dist_grp.storage_units.size}"

replica_cnt = dist_grp.replica_count
disperse_cnt = dist_grp.disperse_count
arbiter_cnt = dist_grp.arbiter_count

replica_arbiter_dist_grp_size = dist_grp.replica_count
if dist_grp.arbiter_count > 0 && dist_grp.replica_count == 2
replica_arbiter_dist_grp_size += 1
end

if dist_grp.replica_count > 0 && dist_grp.storage_units.size != replica_arbiter_dist_grp_size
raise InvalidPoolRequest.new(
"Number of Storage units not matching #{dist_grp.replica_keyword} count"
)
Expand All @@ -309,5 +326,6 @@ module PoolRequestParser
raise InvalidPoolRequest.new("Node name is not specified for #{msg}") if storage_unit.node.name == ""
end
end
exit -1
end
end
21 changes: 20 additions & 1 deletion mgr/src/server/plugins/pool_utils.cr
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,20 @@ def services_and_volfiles(req)

# Client Volfile
tmpl = volfile_get("client")

puts "tmpl: #{tmpl}"

puts "type: #{req.to_json}"

req.distribute_groups.each do |dist_grp|
puts "arbiter_count: #{dist_grp.arbiter_count}"
puts "replica_count: #{dist_grp.replica_count}"
end

client_volfile_content = Volgen.generate(tmpl, req.to_json, req.options)

puts "client_volfile_content:/n #{client_volfile_content}"

# SHD Volfile
shd_volfile_content = ""
if req.replicate_family?
Expand All @@ -309,7 +321,7 @@ def services_and_volfiles(req)
end

req.distribute_groups.each do |dist_grp|
dist_grp.storage_units.each do |storage_unit|
dist_grp.storage_units.each_with_index do |storage_unit, index|
# Generate Service Unit
service = StorageUnitService.new(req.name, storage_unit)
services[storage_unit.node.name] = [] of MoanaTypes::ServiceUnit unless services[storage_unit.node.name]?
Expand All @@ -321,6 +333,13 @@ def services_and_volfiles(req)
tmpl = volfile_get("storage_unit")
storage_unit.volume.id = req.id
storage_unit.volume.name = req.name

# Handle arbiter pools
# Mark every 3rd storage-unit as type arbiter if distribute group has arbiter count > 0
if dist_grp.arbiter_count > 0 && ((index + 1) % 3 == 0)
storage_unit.type = "arbiter"
end

content = Volgen.generate(tmpl, storage_unit.to_json)
volfiles[storage_unit.node.name] = [] of MoanaTypes::Volfile unless volfiles[storage_unit.node.name]?
volfiles[storage_unit.node.name] << MoanaTypes::Volfile.new(service.id, content)
Expand Down
4 changes: 3 additions & 1 deletion types/src/moana_types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ module MoanaTypes
end

def type
if @replica_count > 0
if @replica_count >= 2 && @arbiter_count == 1
"Arbiter"
elsif @replica_count > 0
@replica_keyword == "mirror" ? "Mirror" : "Replicate"
elsif @disperse_count > 0
"Disperse"
Expand Down

0 comments on commit eecc0ce

Please sign in to comment.