this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Sandbox to start sandbox clusters

garrison a376c75f e3d3ab48

+105 -1
+101
lib/sandbox.ex
··· 1 + defmodule Hobbes.Sandbox do 2 + alias Hobbes.{ClusterConfig, ClusterNode} 3 + alias Trinity.Sim 4 + 5 + import ExUnit.Assertions, only: [assert: 1] 6 + 7 + defmodule AppShim do 8 + use Application 9 + 10 + alias Hobbes.Construct.SimSupervisor 11 + 12 + def start(_type, [config]) do 13 + children = [ 14 + {Hobbes.ClusterNode, config} 15 + ] 16 + SimSupervisor.start_link(children, max_restarts: 0) 17 + end 18 + end 19 + 20 + defp default_slots do 21 + [ 22 + stateless: 6, 23 + tlog: [ 24 + "/tlog_1", 25 + ], 26 + storage: 1..4 |> Enum.map(&"/storage_#{&1}"), 27 + ] 28 + end 29 + 30 + defp init_distributed_cluster(num_coordinators, %ClusterConfig{} = cluster_config) do 31 + # Starting a distributed cluster is sim-only for now 32 + assert Sim.simulated?() 33 + 34 + coordinators = Enum.map(0..(num_coordinators - 1), fn i -> 35 + # TODO: name should include cluster name 36 + {String.to_atom("coordinator-#{i}"), String.to_atom("node-#{i}")} 37 + end) 38 + 39 + coordinators 40 + |> Enum.with_index() 41 + |> Enum.each(fn {{_name, node}, i} -> 42 + node_config = [ 43 + # TODO: configurable 44 + cluster: "cluster", 45 + coordinators: coordinators, 46 + coordinator_id: i, 47 + initial_cluster_config: cluster_config, 48 + 49 + # TODO: configurable 50 + slots: default_slots(), 51 + ] 52 + 53 + mfa = {Hobbes.Sandbox.AppShim, :start, [nil, [node_config]]} 54 + :ok = Sim.create_node(node, mfa) 55 + :ok = Sim.start_node(node) 56 + end) 57 + 58 + coordinators 59 + end 60 + 61 + defp init_local_cluster(num_coordinators, %ClusterConfig{} = cluster_config) do 62 + coordinators = Enum.map(0..(num_coordinators - 1), fn i -> 63 + # TODO: name should include cluster name 64 + String.to_atom("coordinator-#{i}") 65 + end) 66 + 67 + coordinators 68 + |> Enum.with_index() 69 + |> Enum.each(fn {_name, i} -> 70 + node_config = [ 71 + # TODO: configurable 72 + cluster: "cluster", 73 + coordinators: coordinators, 74 + coordinator_id: i, 75 + initial_cluster_config: cluster_config, 76 + 77 + # TODO: configurable 78 + slots: default_slots(), 79 + ] 80 + 81 + ClusterNode.start_link(node_config) 82 + end) 83 + 84 + coordinators 85 + end 86 + 87 + @spec start_cluster(keyword) :: {:ok, [atom] | [{atom, atom}]} 88 + def start_cluster(opts) do 89 + num_coordinators = Keyword.get(opts, :num_coordinators, 3) 90 + config = ClusterConfig.from_opts(opts) 91 + 92 + coordinators = 93 + if Keyword.get(opts, :distributed) do 94 + init_distributed_cluster(num_coordinators, config) 95 + else 96 + init_local_cluster(num_coordinators, config) 97 + end 98 + 99 + {:ok, coordinators} 100 + end 101 + end
+4 -1
lib/workloads.ex
··· 144 144 def run_one(_seed, workloads, opts \\ []) do 145 145 {cluster_opts, _opts} = Keyword.pop(opts, :cluster_opts, []) 146 146 147 - {:ok, coordinator_pids} = Hobbes.start_cluster(cluster_opts) 147 + # Use a distributed cluster in simulation 148 + cluster_opts = Keyword.put(cluster_opts, :distributed, Sim.simulated?()) 149 + {:ok, coordinator_pids} = Hobbes.Sandbox.start_cluster(cluster_opts) 150 + 148 151 SimProcess.sleep(2_000) 149 152 {:ok, {manager_pid, _gen}} = Coordinator.get_manager(hd(coordinator_pids)) 150 153 {:ok, %Cluster{} = cluster} = Manager.get_cluster(manager_pid)