@@ -18,7 +18,8 @@ const WAIT_TIMEOUT = 400; // seconds
18
18
19
19
const debugLog = ( ...logLine : any [ ] ) => {
20
20
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 ) ;
22
23
}
23
24
} ;
24
25
@@ -318,6 +319,14 @@ export default class InstanceManager {
318
319
} catch ( e ) { }
319
320
}
320
321
322
+ static access ( obj : any , field : string | number ) {
323
+ if ( obj [ field ] ) {
324
+ return obj [ field ] ;
325
+ } else {
326
+ return undefined ;
327
+ }
328
+ }
329
+
321
330
/// Lookup the async failover leader in agency
322
331
async asyncReplicationLeaderId ( ) : Promise < string | null > {
323
332
const baseUrl = endpointToUrl ( this . getAgencyEndpoint ( ) ) ;
@@ -335,7 +344,9 @@ export default class InstanceManager {
335
344
return null ;
336
345
}
337
346
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 ) ;
339
350
if ( ! leader ) {
340
351
return null ;
341
352
}
@@ -396,7 +407,7 @@ export default class InstanceManager {
396
407
console . error ( "Could not find leader instance locally" ) ;
397
408
throw new Error ( "Could not find leader instance locally" ) ;
398
409
}
399
- console . log ( "Leader in agency %s (%s)" , uuid , instance . endpoint ) ;
410
+ debugLog ( "Leader in agency %s (%s)" , uuid , instance . endpoint ) ;
400
411
// we need to wait for the server to get out of maintenance mode
401
412
await InstanceManager . asyncWaitInstanceOperational ( instance . endpoint ) ;
402
413
return instance ;
@@ -538,7 +549,6 @@ export default class InstanceManager {
538
549
await this . waitForInstances ( this . agents ( ) ) ;
539
550
debugLog ( "all agents are booted" ) ;
540
551
541
- await sleep ( 2000 ) ;
542
552
const dbServers = Array . from ( Array ( numDbServers ) . keys ( ) ) . map ( index => {
543
553
return this . startDbServer ( "dbServer-" + ( index + 1 ) ) ;
544
554
} ) ;
@@ -547,7 +557,6 @@ export default class InstanceManager {
547
557
await Promise . all ( dbServers ) ;
548
558
await this . waitForInstances ( this . dbServers ( ) ) ;
549
559
debugLog ( "all DBServers are booted" ) ;
550
- await sleep ( 2000 ) ;
551
560
552
561
const coordinators = Array . from ( Array ( numCoordinators ) . keys ( ) ) . map (
553
562
index => {
@@ -558,7 +567,7 @@ export default class InstanceManager {
558
567
await Promise . all ( coordinators ) ;
559
568
debugLog ( "all Coordinators are booted" ) ;
560
569
561
- debugLog ( "waiting for /_api/version to succeed an all servers" ) ;
570
+ debugLog ( "waiting for /_api/version to succeed on all servers" ) ;
562
571
await this . waitForAllInstances ( ) ;
563
572
debugLog ( "adding server IDs to all instances" ) ;
564
573
await this . addIdsToAllInstances ( ) ;
@@ -678,12 +687,15 @@ export default class InstanceManager {
678
687
Object . values ( plan ) . map ( colInfo => colInfo . name )
679
688
) ;
680
689
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 ;
687
699
}
688
700
689
701
// inverse check if there are any system collections we haven't included.
@@ -797,10 +809,10 @@ export default class InstanceManager {
797
809
message += ` The last error was: ${ lastError . error } ` ;
798
810
}
799
811
if ( agencyDump !== undefined ) {
800
- message += ` Complete agency dump: ` + JSON . stringify ( agencyDump ) ;
812
+ message += `; Complete agency dump: ` + JSON . stringify ( agencyDump ) ;
801
813
}
802
814
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 ) ;
804
816
}
805
817
throw new Error ( message ) ;
806
818
}
@@ -858,10 +870,15 @@ export default class InstanceManager {
858
870
859
871
async waitForAllInstances ( ) : Promise < Instance [ ] > {
860
872
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.
864
877
await this . waitForSyncReplication ( ) ;
878
+ } else {
879
+ // We have just an agency and/or single servers (possibly with active
880
+ // failover).
881
+ await this . waitForAgency ( ) ;
865
882
}
866
883
return results ;
867
884
}
@@ -1145,7 +1162,9 @@ export default class InstanceManager {
1145
1162
) ;
1146
1163
}
1147
1164
// 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 } .` ) ;
1149
1168
instance . process . kill ( "SIGABRT" ) ;
1150
1169
instance . status = "KILLED" ;
1151
1170
throw new Error ( `Reached shutdown timeout, logfile is ${ instance . logFile } ` ) ;
@@ -1277,7 +1296,7 @@ export default class InstanceManager {
1277
1296
await this . waitForAllInstances ( ) ;
1278
1297
}
1279
1298
1280
- private hasAgentsOnly ( ) : boolean {
1299
+ private hasDbServers ( ) : boolean {
1281
1300
return this . instances . length === this . agents ( ) . length ;
1282
1301
}
1283
1302
}
0 commit comments