Skip to content

Commit a1a676d

Browse files
committed
Some cleanup
1 parent eac8fee commit a1a676d

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

src/InstanceManager.ts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const WAIT_TIMEOUT = 400; // seconds
1818

1919
const debugLog = (...logLine: any[]) => {
2020
if (process.env.LOG_IMMEDIATE && process.env.LOG_IMMEDIATE == "1") {
21-
console.log(new Date().toISOString(), ...logLine);
21+
const [fmt, ...args] = logLine;
22+
console.log(new Date().toISOString() + " " + fmt, ...args);
2223
}
2324
};
2425

@@ -318,6 +319,14 @@ export default class InstanceManager {
318319
} catch (e) { }
319320
}
320321

322+
static access(obj: any, field: string | number) {
323+
if (obj[field]) {
324+
return obj[field];
325+
} else {
326+
return undefined;
327+
}
328+
}
329+
321330
/// Lookup the async failover leader in agency
322331
async asyncReplicationLeaderId(): Promise<string | null> {
323332
const baseUrl = endpointToUrl(this.getAgencyEndpoint());
@@ -335,7 +344,9 @@ export default class InstanceManager {
335344
return null;
336345
}
337346

338-
const leader = body[0].arango.Plan.AsyncReplication.Leader;
347+
// const leader = body[0].arango.Plan.AsyncReplication.Leader;
348+
const leader = [0, "arango", "Plan", "AsyncReplication", "Leader"]
349+
.reduce(InstanceManager.access, body);
339350
if (!leader) {
340351
return null;
341352
}
@@ -396,7 +407,7 @@ export default class InstanceManager {
396407
console.error("Could not find leader instance locally");
397408
throw new Error("Could not find leader instance locally");
398409
}
399-
console.log("Leader in agency %s (%s)", uuid, instance.endpoint);
410+
debugLog("Leader in agency %s (%s)", uuid, instance.endpoint);
400411
// we need to wait for the server to get out of maintenance mode
401412
await InstanceManager.asyncWaitInstanceOperational(instance.endpoint);
402413
return instance;
@@ -538,7 +549,6 @@ export default class InstanceManager {
538549
await this.waitForInstances(this.agents());
539550
debugLog("all agents are booted");
540551

541-
await sleep(2000);
542552
const dbServers = Array.from(Array(numDbServers).keys()).map(index => {
543553
return this.startDbServer("dbServer-" + (index + 1));
544554
});
@@ -547,7 +557,6 @@ export default class InstanceManager {
547557
await Promise.all(dbServers);
548558
await this.waitForInstances(this.dbServers());
549559
debugLog("all DBServers are booted");
550-
await sleep(2000);
551560

552561
const coordinators = Array.from(Array(numCoordinators).keys()).map(
553562
index => {
@@ -558,7 +567,7 @@ export default class InstanceManager {
558567
await Promise.all(coordinators);
559568
debugLog("all Coordinators are booted");
560569

561-
debugLog("waiting for /_api/version to succeed an all servers");
570+
debugLog("waiting for /_api/version to succeed on all servers");
562571
await this.waitForAllInstances();
563572
debugLog("adding server IDs to all instances");
564573
await this.addIdsToAllInstances();
@@ -678,12 +687,15 @@ export default class InstanceManager {
678687
Object.values(plan).map(colInfo => colInfo.name)
679688
);
680689

681-
for (const collection of systemCollections) {
682-
if (!planCollections.has(collection)) {
683-
debugLog(`collection ${collection} still missing from Plan`);
684-
lastError.error = `collection ${collection} still missing from Plan`;
685-
return false;
686-
}
690+
const missingCollections =
691+
_.filter(systemCollections,
692+
collection => !planCollections.has(collection)
693+
);
694+
695+
if (missingCollections.length > 0) {
696+
debugLog(`collections ${missingCollections} still missing from Plan`);
697+
lastError.error = `collections ${missingCollections} still missing from Plan`;
698+
return false;
687699
}
688700

689701
// inverse check if there are any system collections we haven't included.
@@ -797,10 +809,10 @@ export default class InstanceManager {
797809
message += ` The last error was: ${lastError.error}`;
798810
}
799811
if (agencyDump !== undefined) {
800-
message += ` Complete agency dump: ` + JSON.stringify(agencyDump);
812+
message += `; Complete agency dump: ` + JSON.stringify(agencyDump);
801813
}
802814
if (exception !== undefined) {
803-
message += ` Error getting a full agency dump: ` + JSON.stringify(exception);
815+
message += `; Error getting a full agency dump: ` + JSON.stringify(exception);
804816
}
805817
throw new Error(message);
806818
}
@@ -858,10 +870,15 @@ export default class InstanceManager {
858870

859871
async waitForAllInstances(): Promise<Instance[]> {
860872
const results = await this.waitForInstances(this.instances);
861-
if (this.hasAgentsOnly()) {
862-
await this.waitForAgency();
863-
} else {
873+
if (this.hasDbServers()) {
874+
// This is the cluster case: When we have DB Servers, we also have an
875+
// agency.
876+
// In this case, we wait for synchronous replication.
864877
await this.waitForSyncReplication();
878+
} else {
879+
// We have just an agency and/or single servers (possibly with active
880+
// failover).
881+
await this.waitForAgency();
865882
}
866883
return results;
867884
}
@@ -1145,7 +1162,9 @@ export default class InstanceManager {
11451162
);
11461163
}
11471164
// Send SIGABRT to produce a core dump.
1148-
console.warn(`Sending SIGABRT to ${instance.name} due to timeout. PID is ${instance.process.pid}.`);
1165+
console.warn(
1166+
`Sending SIGABRT to ${instance.name} due to timeout `
1167+
+ `during shutdown. PID is ${instance.process.pid}.`);
11491168
instance.process.kill("SIGABRT");
11501169
instance.status = "KILLED";
11511170
throw new Error(`Reached shutdown timeout, logfile is ${instance.logFile}`);
@@ -1277,7 +1296,7 @@ export default class InstanceManager {
12771296
await this.waitForAllInstances();
12781297
}
12791298

1280-
private hasAgentsOnly(): boolean {
1299+
private hasDbServers(): boolean {
12811300
return this.instances.length === this.agents().length;
12821301
}
12831302
}

0 commit comments

Comments
 (0)