querysub 0.290.0 → 0.292.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -6,11 +6,11 @@ import { getAllNodeIds, getOwnNodeId } from "../-f-node-discovery/NodeDiscovery"
|
|
|
6
6
|
import { getArchivesBackblazePublic } from "../-a-archives/archivesBackBlaze";
|
|
7
7
|
import { nestArchives } from "../-a-archives/archives";
|
|
8
8
|
import { SocketFunction } from "socket-function/SocketFunction";
|
|
9
|
-
import { runInSerial, runInfinitePoll, runInfinitePollCallAtStart } from "socket-function/src/batching";
|
|
9
|
+
import { delay, runInSerial, runInfinitePoll, runInfinitePollCallAtStart } from "socket-function/src/batching";
|
|
10
10
|
import { compare, compareArray, isNodeTrue, sort, timeInMinute } from "socket-function/src/misc";
|
|
11
11
|
import { cacheLimited, lazy } from "socket-function/src/caching";
|
|
12
12
|
import { canHaveChildren } from "socket-function/src/types";
|
|
13
|
-
import { shutdown } from "../diagnostics/periodic";
|
|
13
|
+
import { registerShutdownHandler, shutdown } from "../diagnostics/periodic";
|
|
14
14
|
import { hostArchives } from "../-b-authorities/cdnAuthority";
|
|
15
15
|
import { getModuleFromConfig } from "../3-path-functions/pathFunctionLoader";
|
|
16
16
|
import path from "path";
|
|
@@ -26,6 +26,7 @@ import { onEdgeNodesChanged } from "./edgeBootstrap";
|
|
|
26
26
|
import { startEdgeNotifier } from "./edgeClientWatcher";
|
|
27
27
|
import { getGitRefLive, getGitURLLive } from "./git";
|
|
28
28
|
import { DeployProgress } from "./deployFunctions";
|
|
29
|
+
import { watchOnRollingUpdate } from "../deployManager/machineController";
|
|
29
30
|
|
|
30
31
|
const UPDATE_POLL_INTERVAL = timeInMinute * 15;
|
|
31
32
|
const DEAD_NODE_COUNT_THRESHOLD = 15;
|
|
@@ -41,13 +42,17 @@ const getEdgeNodeConfig = cacheLimited(10000, async (fileName: string): Promise<
|
|
|
41
42
|
return obj;
|
|
42
43
|
});
|
|
43
44
|
let nextNodeNum = 1;
|
|
45
|
+
let registeredNodePaths = new Set<string>();
|
|
44
46
|
function getNextNodePath() {
|
|
45
|
-
|
|
47
|
+
let path = "node" + (nextNodeNum++) + "_" + getOwnNodeId();
|
|
48
|
+
registeredNodePaths.add(path);
|
|
49
|
+
return path;
|
|
46
50
|
}
|
|
47
51
|
function getNodeIdFromPath(path: string) {
|
|
48
52
|
return path.split("_").slice(1).join("_");
|
|
49
53
|
}
|
|
50
54
|
|
|
55
|
+
let edgeShutdown = false;
|
|
51
56
|
|
|
52
57
|
export type EdgeNodesIndex = {
|
|
53
58
|
edgeNodes: EdgeNodeConfig[];
|
|
@@ -85,6 +90,29 @@ export async function registerEdgeNode(config: {
|
|
|
85
90
|
registeredEdgeNode = true;
|
|
86
91
|
let host = config.host;
|
|
87
92
|
|
|
93
|
+
|
|
94
|
+
registerShutdownHandler(async () => {
|
|
95
|
+
edgeShutdown = true;
|
|
96
|
+
console.log(magenta(`Removing node from edge node list due to shutdown`));
|
|
97
|
+
await Promise.all(Array.from(registeredNodePaths).map(async nodePath => {
|
|
98
|
+
await edgeNodeStorage.del(nodePath);
|
|
99
|
+
}));
|
|
100
|
+
await updateEdgeNodesFile();
|
|
101
|
+
});
|
|
102
|
+
watchOnRollingUpdate({
|
|
103
|
+
callback: async (time) => {
|
|
104
|
+
let duration = time - Date.now();
|
|
105
|
+
// Wait a bit to remove ourself from the edge node list
|
|
106
|
+
void delay(duration * 0.2).finally(async () => {
|
|
107
|
+
console.log(magenta(`Removing node from edge node list due to rolling update at ${new Date().toLocaleString()}`));
|
|
108
|
+
await Promise.all(Array.from(registeredNodePaths).map(async nodePath => {
|
|
109
|
+
await edgeNodeStorage.del(nodePath);
|
|
110
|
+
}));
|
|
111
|
+
await updateEdgeNodesFile();
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
88
116
|
await waitForFirstTimeSync();
|
|
89
117
|
|
|
90
118
|
if (!isLocal() && !noSyncing()) {
|
|
@@ -193,6 +221,7 @@ const startUpdateLoop = lazy(async () => {
|
|
|
193
221
|
});
|
|
194
222
|
|
|
195
223
|
async function updateLoop() {
|
|
224
|
+
if (edgeShutdown) return;
|
|
196
225
|
await runEdgeNodesAliveCheck();
|
|
197
226
|
await updateEdgeNodesFile();
|
|
198
227
|
}
|
|
@@ -306,11 +306,11 @@ const getScreenState = measureWrap(async function getScreenState(populateIsProce
|
|
|
306
306
|
return screenList;
|
|
307
307
|
});
|
|
308
308
|
async function removeOldNodeId(screenName: string) {
|
|
309
|
-
let
|
|
310
|
-
if (fs.existsSync(
|
|
311
|
-
let nodeId = await fs.promises.readFile(
|
|
312
|
-
console.log(green(`Removing node if for dead service on ${
|
|
313
|
-
await fs.promises.unlink(
|
|
309
|
+
let nodeIdFile = os.homedir() + "/" + SERVICE_FOLDER + screenName + "/" + SERVICE_NODE_FILE_NAME;
|
|
310
|
+
if (fs.existsSync(nodeIdFile)) {
|
|
311
|
+
let nodeId = await fs.promises.readFile(nodeIdFile, "utf8");
|
|
312
|
+
console.log(green(`Removing node if for dead service on ${nodeIdFile}, node id ${nodeId}`));
|
|
313
|
+
await fs.promises.unlink(nodeIdFile);
|
|
314
314
|
await forceRemoveNode(nodeId);
|
|
315
315
|
}
|
|
316
316
|
}
|
|
@@ -346,10 +346,16 @@ const runScreenCommand = measureWrap(async function runScreenCommand(config: {
|
|
|
346
346
|
let rollingFinalTime = Date.now() + config.rollingWindow;
|
|
347
347
|
if (fs.existsSync(nodeIdPath)) {
|
|
348
348
|
let nodeId = await fs.promises.readFile(nodeIdPath, "utf8");
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
349
|
+
// REMOVE the nodeId file, so we the node isn't terminated!
|
|
350
|
+
await fs.promises.unlink(nodeIdPath);
|
|
351
|
+
try {
|
|
352
|
+
await triggerRollingUpdate({
|
|
353
|
+
nodeId,
|
|
354
|
+
time: rollingFinalTime,
|
|
355
|
+
});
|
|
356
|
+
} catch (e: any) {
|
|
357
|
+
console.warn(`Error triggering rolling update notification to ${nodeId} for ${screenName}: ${e.stack}`);
|
|
358
|
+
}
|
|
353
359
|
}
|
|
354
360
|
let rollingScreenName = screenName + "-rolling" + SCREEN_SUFFIX;
|
|
355
361
|
console.log(green(`Renaming screen ${screenName} to ${rollingScreenName} for rolling interval ${config.rollingWindow} at ${new Date().toLocaleString()}`));
|
|
@@ -44,6 +44,8 @@ export function watchOnRollingUpdate(config: {
|
|
|
44
44
|
}) {
|
|
45
45
|
rollingUpdateWatchers.add(config.callback);
|
|
46
46
|
}
|
|
47
|
+
// TODO: PathValueServer should use this to remove itself from the node pool, and then after 50% of the time until time tell it's clients to find a new server to get values from
|
|
48
|
+
// TODO: FunctionRunner needs to reshard when it sees this (somehow?)
|
|
47
49
|
export async function triggerRollingUpdate(config: {
|
|
48
50
|
nodeId: string;
|
|
49
51
|
time: number;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
Hmm... our cyoa servers are dying very fast... why?
|
|
2
|
+
|
|
1
3
|
9) Rolling service updates
|
|
2
4
|
- Add rollingWindow to the definition
|
|
3
5
|
- Set for public facing services (but not for scripts)
|
|
4
6
|
- PathValueServer - 10 minutes
|
|
5
|
-
- FunctionRunner -
|
|
7
|
+
- FunctionRunner - CANNOT use rolling
|
|
6
8
|
- HTTP - 4 hours
|
|
7
9
|
- Boostrapper - NO rolling
|
|
8
10
|
- gc/join - NO rolling
|