Skip to content
Snippets Groups Projects

Add cron worker to automatically rollout zoekt exact code search to paid namespaces

Merged John Mason requested to merge jm-namespace-assignment-service into master
1 file
+ 19
13
Compare changes
  • Side-by-side
  • Inline
@@ -90,21 +90,17 @@ def generate
def simulate_replica_plan
replica_id = find_replica&.id
plan_indices
add_replica_plan(replica_id)
rescue StandardError => e
log_error(replica_plans.size, nil, :replica_failed, e.message)
end
def plan_indices
# Fetch and assign projects to nodes
fetch_unassigned_projects.each_batch(of: batch_size) do |batch|
batch.each do |project|
stats = project.statistics
assign_to_node(stats)
rescue StandardError => e
log_error(replica_plans.size, nil, :assignment_failed, e.message)
assign_to_node(stats) # Updates node[:indices] directly
end
end
# Add the replica plan with indices collected from all nodes
add_replica_plan(replica_id)
end
def fetch_unassigned_projects(last_project_id: nil)
@@ -141,17 +137,27 @@ def find_best_node(stats)
end
def assign_project_to_index(node, stats)
index = node[:indices].find do |idx|
idx[:required_storage_bytes] + scaled_size(stats) <= idx[:max_storage_bytes]
end
project_size = scaled_size(stats)
# First, try to fit the project into an existing index
index = node[:indices]
.select { |idx| idx[:required_storage_bytes] + project_size <= idx[:max_storage_bytes] }
.min_by { |idx| idx[:max_storage_bytes] - (idx[:required_storage_bytes] + project_size) }
# If no index can fit, create a new one
unless index
if node[:indices].size >= MAX_INDICES_PER_REPLICA
log_error(nil, nil, :index_limit_exceeded, "Max indices per replica reached on node #{node[:id]}")
return
end
index = simulate_index(node)
node[:indices] << index
end
# Add the project to the chosen index
add_project_to_index(index, stats)
node[:unclaimed_storage_bytes] -= scaled_size(stats)
node[:unclaimed_storage_bytes] -= project_size
end
def simulate_index(node)
Loading