Make all globals start with a "g_" prefix

This makes it easier to spot them in code, and is shorter than using explicit
namespacing.
This commit is contained in:
Christian Kreibich 2021-11-29 11:56:03 -08:00
parent 14a8c979c1
commit b57be021b7
3 changed files with 32 additions and 32 deletions

View file

@ -9,18 +9,18 @@
redef ClusterController::role = ClusterController::Types::AGENT; redef ClusterController::role = ClusterController::Types::AGENT;
# The global configuration as passed to us by the controller # The global configuration as passed to us by the controller
global global_config: ClusterController::Types::Configuration; global g_config: ClusterController::Types::Configuration;
# A map to make other instance info accessible # A map to make other instance info accessible
global instances: table[string] of ClusterController::Types::Instance; global g_instances: table[string] of ClusterController::Types::Instance;
# A map for the nodes we run on this instance, via this agent. # A map for the nodes we run on this instance, via this agent.
global nodes: table[string] of ClusterController::Types::Node; global g_nodes: table[string] of ClusterController::Types::Node;
# The node map employed by the supervisor to describe the cluster # The node map employed by the supervisor to describe the cluster
# topology to newly forked nodes. We refresh it when we receive # topology to newly forked nodes. We refresh it when we receive
# new configurations. # new configurations.
global data_cluster: table[string] of Supervisor::ClusterEndpoint; global g_data_cluster: table[string] of Supervisor::ClusterEndpoint;
event SupervisorControl::create_response(reqid: string, result: string) event SupervisorControl::create_response(reqid: string, result: string)
{ {
@ -86,43 +86,43 @@ event ClusterAgent::API::set_configuration_request(reqid: string, config: Cluste
# Adopt the global configuration provided. # Adopt the global configuration provided.
# XXX this can later handle validation and persistence # XXX this can later handle validation and persistence
# XXX should do this transactionally, only set when all else worked # XXX should do this transactionally, only set when all else worked
global_config = config; g_config = config;
# Refresh the instances table: # Refresh the instances table:
instances = table(); g_instances = table();
for ( inst in config$instances ) for ( inst in config$instances )
instances[inst$name] = inst; g_instances[inst$name] = inst;
# Terminate existing nodes # Terminate existing nodes
for ( nodename in nodes ) for ( nodename in g_nodes )
supervisor_destroy(nodename); supervisor_destroy(nodename);
nodes = table(); g_nodes = table();
# Refresh the data cluster and nodes tables # Refresh the data cluster and nodes tables
data_cluster = table(); g_data_cluster = table();
for ( node in config$nodes ) for ( node in config$nodes )
{ {
if ( node$instance == ClusterAgent::name ) if ( node$instance == ClusterAgent::name )
nodes[node$name] = node; g_nodes[node$name] = node;
local cep = Supervisor::ClusterEndpoint( local cep = Supervisor::ClusterEndpoint(
$role = node$role, $role = node$role,
$host = instances[node$instance]$host, $host = g_instances[node$instance]$host,
$p = node$p); $p = node$p);
if ( node?$interface ) if ( node?$interface )
cep$interface = node$interface; cep$interface = node$interface;
data_cluster[node$name] = cep; g_data_cluster[node$name] = cep;
} }
# Apply the new configuration via the supervisor # Apply the new configuration via the supervisor
for ( nodename in nodes ) for ( nodename in g_nodes )
{ {
node = nodes[nodename]; node = g_nodes[nodename];
nc = Supervisor::NodeConfig($name=nodename); nc = Supervisor::NodeConfig($name=nodename);
if ( ClusterAgent::cluster_directory != "" ) if ( ClusterAgent::cluster_directory != "" )
@ -140,7 +140,7 @@ event ClusterAgent::API::set_configuration_request(reqid: string, config: Cluste
# XXX could use options to enable per-node overrides for # XXX could use options to enable per-node overrides for
# directory, stdout, stderr, others? # directory, stdout, stderr, others?
nc$cluster = data_cluster; nc$cluster = g_data_cluster;
supervisor_create(nc); supervisor_create(nc);
} }

View file

@ -9,8 +9,8 @@
redef ClusterController::role = ClusterController::Types::CONTROLLER; redef ClusterController::role = ClusterController::Types::CONTROLLER;
global config_current: ClusterController::Types::Configuration; global g_config_current: ClusterController::Types::Configuration;
global config_reqid_pending: string = ""; global g_config_reqid_pending: string = "";
function send_config_to_agents(req: ClusterController::Request::Request, function send_config_to_agents(req: ClusterController::Request::Request,
config: ClusterController::Types::Configuration) config: ClusterController::Types::Configuration)
@ -90,15 +90,15 @@ event ClusterAgent::API::notify_agent_hello(instance: string, host: addr, api_ve
# If we have a pending configuration request, check in on it now to see whether # If we have a pending configuration request, check in on it now to see whether
# we have all agents required, and finalize the config request. # we have all agents required, and finalize the config request.
if ( config_reqid_pending == "" ) if ( g_config_reqid_pending == "" )
return; return;
local req = ClusterController::Request::lookup(config_reqid_pending); local req = ClusterController::Request::lookup(g_config_reqid_pending);
if ( ClusterController::Request::is_null(req) || ! req?$set_configuration_state ) if ( ClusterController::Request::is_null(req) || ! req?$set_configuration_state )
{ {
# Odd, just clear out pending state. # Odd, just clear out pending state.
config_reqid_pending = ""; g_config_reqid_pending = "";
return; return;
} }
@ -117,7 +117,7 @@ event ClusterAgent::API::notify_agent_hello(instance: string, host: addr, api_ve
# update the request state and eventually send the response event # update the request state and eventually send the response event
# to the client. # to the client.
send_config_to_agents(req, req$set_configuration_state$config); send_config_to_agents(req, req$set_configuration_state$config);
config_reqid_pending = ""; g_config_reqid_pending = "";
} }
@ -216,11 +216,11 @@ event ClusterController::API::set_configuration_request(reqid: string, config: C
req$set_configuration_state = ClusterController::Request::SetConfigurationState($config = config); req$set_configuration_state = ClusterController::Request::SetConfigurationState($config = config);
# At the moment there can only be one pending request. # At the moment there can only be one pending request.
if ( config_reqid_pending != "" ) if ( g_config_reqid_pending != "" )
{ {
res = ClusterController::Types::Result($reqid=reqid); res = ClusterController::Types::Result($reqid=reqid);
res$success = F; res$success = F;
res$error = fmt("request %s still pending", config_reqid_pending); res$error = fmt("request %s still pending", g_config_reqid_pending);
req$results += res; req$results += res;
ClusterController::Log::info(fmt("tx ClusterController::API::set_configuration_response %s", ClusterController::Log::info(fmt("tx ClusterController::API::set_configuration_response %s",
@ -312,7 +312,7 @@ event ClusterController::API::set_configuration_request(reqid: string, config: C
ClusterController::connect_retry); ClusterController::connect_retry);
} }
config_reqid_pending = req$id; g_config_reqid_pending = req$id;
return; return;
} }

View file

@ -49,30 +49,30 @@ export {
} }
# XXX this needs a mechanism for expiring stale requests # XXX this needs a mechanism for expiring stale requests
global requests: table[string] of Request; global g_requests: table[string] of Request;
function create(reqid: string): Request function create(reqid: string): Request
{ {
local ret = Request($id=reqid); local ret = Request($id=reqid);
requests[reqid] = ret; g_requests[reqid] = ret;
return ret; return ret;
} }
function lookup(reqid: string): Request function lookup(reqid: string): Request
{ {
if ( reqid in requests ) if ( reqid in g_requests )
return requests[reqid]; return g_requests[reqid];
return null_req; return null_req;
} }
function finish(reqid: string): bool function finish(reqid: string): bool
{ {
if ( reqid !in requests ) if ( reqid !in g_requests )
return F; return F;
local req = requests[reqid]; local req = g_requests[reqid];
delete requests[reqid]; delete g_requests[reqid];
req$finished = T; req$finished = T;