Rename Master to Controller

The role of the master server as the party controlling every part of the
cluster is not well reflected in its name and has caused confusion among
users on several occasions.  Rename master to controller to better
reflects its role.
This commit is contained in:
Hornwitser committed 2023-02-22 15:30:51 +01:00
1 parent 6ae4c8ef46
commit 70ad295a89
119 files changed
+1394 -1376

No files matched your search

+9 -9
View File
@@ -13,9 +13,9 @@ When a server crashes while you are online there won't be time to immediately up
Run the following commands in the folder Clusterio is installed to:
npm install @clusterio/plugin-inventory_sync
npx clusteriomaster plugin add @clusterio/plugin-inventory_sync
npx clusteriocontroller plugin add @clusterio/plugin-inventory_sync
Substitute clusteriomaster with clusterioslave or clusterioctl if this a dedicated slave or ctl installation respectively.
Substitute clusteriocontroller with clusterioslave or clusterioctl if this a dedicated slave or ctl installation respectively.
## Method of operation
@@ -23,17 +23,17 @@ This plugin does event based synchronization of inventories.
The greatly simplified data flow is as follows:
1. Player joins server.
2. Scenario script asks master for exclusive access to the player.
3. Master grants exclusive access for the player to the instance.
2. Scenario script asks controller for exclusive access to the player.
3. Controller grants exclusive access for the player to the instance.
4. Scenario script checks the access response and then acts according to the situation:
1. If the player has no inventory on the master then the current inventory becomes the synced inventory and the process is done.
2. If the player inventory was previously uploaded and is the same as the one stored on the master then the current inventory becomes the synced inventory and the process is done.
1. If the player has no inventory on the controller then the current inventory becomes the synced inventory and the process is done.
2. If the player inventory was previously uploaded and is the same as the one stored on the controller then the current inventory becomes the synced inventory and the process is done.
3. If the player inventory was previously uploaded but is not the same then the player inventory is deleted and the player is turned into a spectator.
4. Otherwise the player inventory is kept.
5. Scenario script asks for the player inventory from the master.
6. Master sends it to the scenario in a stream of chunks.
5. Scenario script asks for the player inventory from the controller.
6. Controller sends it to the scenario in a stream of chunks.
7. Scenario displays and updates a progress bar as each chunk is received.
8. Once all chunks have loaded the player's synced inventory is recreated from the data and the player can start playing.
@@ -41,5 +41,5 @@ When the player leaves the inventory is uploaded if it's a synced inventory and
Should an error occur during this process the player is given the option to use a temporary inventory instead, which will be merged back into the synced inventory the next time the sync succeeds on that instance.
Communication between the server and instance goes over stdout or rcon, depending on the size of the data.
Communication between the instance and the master server goes over websockets.
Communication between the instance and the controller goes over websockets.
Overall, we are able to achieve a latency between 3 and infinite ticks from server join, depending on the size of the inventory. The major limiter is rcon transfer speeds with larger inventories, especially if they contain blueprints.
@@ -6,7 +6,7 @@ const libFileOps = require("@clusterio/lib/file_ops");
const libPlugin = require("@clusterio/lib/plugin");
async function loadDatabase(config, logger) {
let itemsPath = path.resolve(config.get("master.database_directory"), "inventories.json");
let itemsPath = path.resolve(config.get("controller.database_directory"), "inventories.json");
logger.verbose(`Loading ${itemsPath}`);
try {
let content = await fs.readFile(itemsPath);
@@ -21,24 +21,24 @@ async function loadDatabase(config, logger) {
}
}
async function saveDatabase(masterConfig, playerDatastore, logger) {
async function saveDatabase(controllerConfig, playerDatastore, logger) {
if (playerDatastore) {
let file = path.resolve(masterConfig.get("master.database_directory"), "inventories.json");
let file = path.resolve(controllerConfig.get("controller.database_directory"), "inventories.json");
logger.verbose(`writing ${file}`);
let content = JSON.stringify(Array.from(playerDatastore));
await libFileOps.safeOutputFile(file, content);
}
}
class MasterPlugin extends libPlugin.BaseMasterPlugin {
class ControllerPlugin extends libPlugin.BaseControllerPlugin {
async init() {
this.acquiredPlayers = new Map();
this.playerDatastore = await loadDatabase(this.master.config, this.logger);
this.playerDatastore = await loadDatabase(this.controller.config, this.logger);
this.autosaveId = setInterval(() => {
saveDatabase(this.master.config, this.playerDatastore, this.logger).catch(err => {
saveDatabase(this.controller.config, this.playerDatastore, this.logger).catch(err => {
this.logger.error(`Unexpected error autosaving player data:\n${err.stack}`);
});
}, this.master.config.get("inventory_sync.autosave_interval") * 1000);
}, this.controller.config.get("inventory_sync.autosave_interval") * 1000);
}
async onInstanceStatusChanged(instance) {
@@ -52,7 +52,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
}
if (["unknown", "stopped"].includes(instance.status)) {
let timeout = this.master.config.get("inventory_sync.player_lock_timeout") * 1000;
let timeout = this.controller.config.get("inventory_sync.player_lock_timeout") * 1000;
for (let acquisitonRecord of this.acquiredPlayers.values()) {
if (acquisitonRecord.instanceId === instanceId && !acquisitonRecord.expires) {
acquisitonRecord.expires = Date.now() + timeout;
@@ -74,7 +74,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
if (
!acquisitionRecord
|| acquisitionRecord.instanceId === instanceId
|| !this.master.instances.has(acquisitionRecord.instanceId)
|| !this.controller.instances.has(acquisitionRecord.instanceId)
|| acquisitionRecord.expires && acquisitionRecord.expires < Date.now()
) {
this.acquiredPlayers.set(playerName, { instanceId });
@@ -88,7 +88,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
let { instance_id, player_name } = message.data;
if (!this.acquire(instance_id, player_name)) {
let acquisitionRecord = this.acquiredPlayers.get(player_name);
let instance = this.master.instances.get(acquisitionRecord.instanceId);
let instance = this.controller.instances.get(acquisitionRecord.instanceId);
return {
status: "busy",
message: instance.config.get("instance.name"),
@@ -117,7 +117,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
async uploadRequestHandler(message) {
let { instance_id, player_name, player_data } = message.data;
let instanceName = this.master.instances.get(instance_id).config.get("instance.name");
let instanceName = this.controller.instances.get(instance_id).config.get("instance.name");
let store = true;
let acquisitionRecord = this.acquiredPlayers.get(player_name);
if (!acquisitionRecord) {
@@ -151,7 +151,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
async downloadRequestHandler(message) {
let { instance_id, player_name } = message.data;
let instanceName = this.master.instances.get(instance_id).config.get("instance.name");
let instanceName = this.controller.instances.get(instance_id).config.get("instance.name");
let acquisitionRecord = this.acquiredPlayers.get(player_name);
if (!acquisitionRecord) {
@@ -168,7 +168,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
async onShutdown() {
clearInterval(this.autosaveId);
await saveDatabase(this.master.config, this.playerDatastore, this.logger);
await saveDatabase(this.controller.config, this.playerDatastore, this.logger);
}
async databaseStatsRequestHandler(message) {
@@ -190,5 +190,5 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
}
module.exports = {
MasterPlugin,
ControllerPlugin,
};
+18 -18
View File
@@ -1,17 +1,17 @@
"use strict";
const { libConfig, libLink, libUsers } = require("@clusterio/lib");
class MasterConfigGroup extends libConfig.PluginConfigGroup { }
MasterConfigGroup.defaultAccess = ["master", "slave", "control"];
MasterConfigGroup.groupName = "inventory_sync";
MasterConfigGroup.define({
class ControllerConfigGroup extends libConfig.PluginConfigGroup { }
ControllerConfigGroup.defaultAccess = ["controller", "slave", "control"];
ControllerConfigGroup.groupName = "inventory_sync";
ControllerConfigGroup.define({
name: "autosave_interval",
title: "Autosave Interval",
description: "Interval the player data is autosaved at in seconds.",
type: "number",
initial_value: 600, // 10 minutes
});
MasterConfigGroup.define({
ControllerConfigGroup.define({
name: "player_lock_timeout",
title: "Player Lock Timeout",
description:
@@ -19,10 +19,10 @@ MasterConfigGroup.define({
type: "number",
initial_value: 60,
});
MasterConfigGroup.finalize();
ControllerConfigGroup.finalize();
class InstanceConfigGroup extends libConfig.PluginConfigGroup { }
InstanceConfigGroup.defaultAccess = ["master", "slave", "control"];
InstanceConfigGroup.defaultAccess = ["controller", "slave", "control"];
InstanceConfigGroup.groupName = "inventory_sync";
InstanceConfigGroup.define({
name: "rcon_chunk_size",
@@ -48,8 +48,8 @@ module.exports = {
instanceEntrypoint: "instance",
InstanceConfigGroup,
masterEntrypoint: "master",
MasterConfigGroup,
controllerEntrypoint: "controller",
ControllerConfigGroup,
webEntrypoint: "./web",
routes: ["/inventory"],
@@ -57,8 +57,8 @@ module.exports = {
messages: {
acquire: new libLink.Request({
type: "inventory_sync:acquire",
links: ["instance-slave", "slave-master"],
forwardTo: "master",
links: ["instance-slave", "slave-controller"],
forwardTo: "controller",
requestProperties: {
"instance_id": { type: "integer" },
"player_name": { type: "string" },
@@ -73,8 +73,8 @@ module.exports = {
}),
release: new libLink.Request({
type: "inventory_sync:release",
links: ["instance-slave", "slave-master"],
forwardTo: "master",
links: ["instance-slave", "slave-controller"],
forwardTo: "controller",
requestProperties: {
"instance_id": { type: "integer" },
"player_name": { type: "string" },
@@ -82,8 +82,8 @@ module.exports = {
}),
upload: new libLink.Request({
type: "inventory_sync:upload",
links: ["instance-slave", "slave-master"],
forwardTo: "master",
links: ["instance-slave", "slave-controller"],
forwardTo: "controller",
requestProperties: {
"instance_id": { type: "integer" },
"player_name": { type: "string" },
@@ -92,8 +92,8 @@ module.exports = {
}),
download: new libLink.Request({
type: "inventory_sync:download",
links: ["instance-slave", "slave-master"],
forwardTo: "master",
links: ["instance-slave", "slave-controller"],
forwardTo: "controller",
requestProperties: {
"instance_id": { type: "integer" },
"player_name": { type: "string" },
@@ -104,7 +104,7 @@ module.exports = {
}),
databaseStats: new libLink.Request({
type: "inventory_sync:databaseStats",
links: ["control-master"],
links: ["control-controller"],
permission: "inventory_sync.inventory.view",
responseProperties: {
"database_size": { type: "integer" },
+3 -3
View File
@@ -32,11 +32,11 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
.catch(err => this.logger.error(`Error handling ipc-inventory_sync_download:\n${err.stack}`)));
}
onPrepareMasterDisconnect() {
onPrepareControllerDisconnect() {
this.disconnecting = true;
}
onMasterConnectionEvent(event) {
onControllerConnectionEvent(event) {
if (event === "connect") {
this.disconnecting = false;
(async () => {
@@ -60,7 +60,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
let response = {
player_name: request.player_name,
status: "error",
message: "Master is temporarily unavailable",
message: "Controller is temporarily unavailable",
};
if (this.slave.connector.connected && !this.disconnecting) {
@@ -25,8 +25,8 @@ local function download_inventory(player_name, data, number, total)
if total == 0 then
-- Download was requested but the player had no data stored.
log("ERROR: Inventory sync failed, got empty player data for " .. player.name .. " from the master")
player.print("ERROR: Inventory sync failed, got empty player data from the master")
log("ERROR: Inventory sync failed, got empty player data for " .. player.name .. " from the controller")
player.print("ERROR: Inventory sync failed, got empty player data from the controller")
progress_dialog.remove(player)
@@ -49,7 +49,7 @@ function dialog_failed_download.create(player, acquire_response)
local reason
if acquire_response.status == "timeout" then
reason = "Timed out fetching inventory from the master server."
reason = "Timed out fetching inventory from the controller."
elseif acquire_response.status == "busy" then
reason =
@@ -58,10 +58,10 @@ function dialog_failed_download.create(player, acquire_response)
"If you just logged out from there it might take some time before the inventory is available."
elseif acquire_response.status == "error" then
reason = "Error fetching inventory from the master server: " .. acquire_response.message .. "."
reason = "Error fetching inventory from the controller: " .. acquire_response.message .. "."
else
reason = "Unknown status " .. acquire_response.status .. " fetching inventory from the master server."
reason = "Unknown status " .. acquire_response.status .. " fetching inventory from the controller."
end
local p1 = content.add {
@@ -129,7 +129,7 @@ dialog_failed_download.events = {
global.inventory_sync.players[player.name].sync = false
elseif event.element.name == "inventory_sync_failed_download_retry" then
-- Retry acquiring the player from the master
-- Retry acquiring the player from the controller
local player = game.get_player(event.player_index)
inventory_sync.acquire(player)
player.gui.screen.dialog_failed_download.destroy()
@@ -2,8 +2,8 @@
Inventory Sync
When a player leaves the game, serialize the player state and upload it to the master.
When a player joins the game, request the player data from master and deserialize the player state from it.
When a player leaves the game, serialize the player state and upload it to the controller.
When a player joins the game, request the player data from controller and deserialize the player state from it.
]]
@@ -23,7 +23,7 @@ end
local function create_player(player, dirty)
global.inventory_sync.players[player.name] = {
dirty = dirty, -- Player inventory has changes that should be persisted
sync = false, -- Player inventory is synced from the master
sync = false, -- Player inventory is synced from the controller
generation = 0,
}
end
@@ -40,7 +40,7 @@ end
inventory_sync = {}
-- This function is called by instance.js as /sc inventory_sync.download_inventory("danielv", Escaped JSON string, package_number, total_packages_count) with data from the master
-- This function is called by instance.js as /sc inventory_sync.download_inventory("danielv", Escaped JSON string, package_number, total_packages_count) with data from the controller
inventory_sync.download_inventory = download_inventory
-- This function is called internally when a player leaves the game to
@@ -280,7 +280,7 @@ function inventory_sync.sync_player(acquire_response)
end
if acquire_response.status == "acquired" then
-- The stored data on the master server has changed since the
-- The stored data on the controller has changed since the
-- download was started. Restart it.
game.print("Restarting download")
download_record.restart = true
@@ -342,7 +342,7 @@ function inventory_sync.finish_download(player, finished_record)
player_record.generation = finished_record.generation
end
-- Download inventory from master
-- Download inventory from controller
inventory_sync.events[defines.events.on_player_joined_game] = function(event)
-- Send acquire request even if an active download is currently in plogress
local player = game.get_player(event.player_index)
@@ -406,7 +406,7 @@ inventory_sync.events[defines.events.on_pre_player_left_game] = function(event)
clusterio_api.send_json("inventory_sync_upload", result)
end
-- Invoked by the instance code to confirm the master has received the uploaded data
-- Invoked by the instance code to confirm the controller has received the uploaded data
function inventory_sync.confirm_upload(player_name, generation)
local player = game.get_player(player_name)
if not player or player.connected then
+1 -1
View File
@@ -40,7 +40,7 @@ export class WebPlugin extends libPlugin.BaseWebPlugin {
];
}
onMasterConnectionEvent(event) {
onControllerConnectionEvent(event) {
if (event === "connect") {
}