Files
ubicloud/prog/minio/minio_pool_nexus.rb
Enes Cakir f15c01348b Remove unnecessary transactions in progs
We already run the prog labels in a DB transaction when we call
`strand.run`, so there's no need to wrap them in another transaction.

We only use DB transactions in the assemble function in progs because
they might be called from web routes or pry, so they aren't wrapped by a
tra transaction all the time.
2025-02-11 10:05:55 +03:00

84 lines
2.0 KiB
Ruby

# frozen_string_literal: true
require_relative "../../lib/util"
class Prog::Minio::MinioPoolNexus < Prog::Base
subject_is :minio_pool
def self.assemble(cluster_id, start_index, server_count, drive_count, storage_size_gib, vm_size)
unless MinioCluster[cluster_id]
fail "No existing cluster"
end
DB.transaction do
ubid = MinioPool.generate_ubid
minio_pool = MinioPool.create(
cluster_id: cluster_id,
start_index: start_index,
server_count: server_count,
drive_count: drive_count,
storage_size_gib: storage_size_gib,
vm_size: vm_size
) { _1.id = ubid.to_uuid }
minio_pool.server_count.times do |i|
Prog::Minio::MinioServerNexus.assemble(minio_pool.id, minio_pool.start_index + i)
end
Strand.create(prog: "Minio::MinioPoolNexus", label: "wait_servers") { _1.id = minio_pool.id }
end
end
def self.assemble_additional_pool(cluster_id, server_count, drive_count, storage_size_gib, vm_size)
DB.transaction do
st = assemble(cluster_id, MinioCluster[cluster_id]&.server_count, server_count, drive_count, storage_size_gib, vm_size)
st.subject.incr_add_additional_pool
st
end
end
def before_run
when_destroy_set? do
unless ["destroy", "wait_servers_destroyed"].include?(strand.label)
hop_destroy
end
end
end
def cluster
@cluster ||= minio_pool.cluster
end
label def wait_servers
if minio_pool.servers.all? { _1.strand.label == "wait" }
when_add_additional_pool_set? do
decr_add_additional_pool
cluster.incr_reconfigure
end
hop_wait
end
nap 5
end
label def wait
nap 30
end
label def destroy
register_deadline(nil, 10 * 60)
decr_destroy
minio_pool.servers.each(&:incr_destroy)
hop_wait_servers_destroyed
end
label def wait_servers_destroyed
nap 5 unless minio_pool.servers.empty?
minio_pool.destroy
pop "pool destroyed"
end
end