Skip to content

Commit 5d1af1f

Browse files
committed
address PR comments
1 parent 80a79b7 commit 5d1af1f

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/config/localConfig.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
interface LocalConfig {
2+
verticalScalingMode_enabled: boolean
3+
verticalScalingMode_path: string
4+
verticalScalingMode_shutdown_mode: 'sleep' | 'shutdown'
5+
}
6+
7+
export const localConfig: LocalConfig = {
8+
verticalScalingMode_enabled: false || process.env.VERTICALSCALING_ENABLED === 'true',
9+
verticalScalingMode_path: '/home/node/config' || process.env.VERTICALSCALING_PATH,
10+
verticalScalingMode_shutdown_mode: 'sleep'
11+
}

src/config/server.ts

-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ const SERVER_CONFIG: StrictServerConfiguration = {
184184
foundationNodeThreshold: 50,
185185
patchNetworkAccountSyncFixes: true,
186186
enableShardKeyChanges: true,
187-
verticalScalingMode: {
188-
enabled: false,
189-
path: '.'
190-
}
191187
},
192188
ip: {
193189
externalIp: '0.0.0.0',

src/p2p/Self.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import * as ServiceQueue from './ServiceQueue'
3636
import Shardus from '../shardus'
3737
import path from "path";
3838
import fs from "fs/promises";
39+
import {localConfig} from "@src/config/localConfig";
40+
import {sleep} from "../utils";
3941

4042
/** STATE */
4143

@@ -293,8 +295,8 @@ export function startupV2(shardus: Shardus): Promise<boolean> {
293295

294296
// check if file exists first
295297
let fileExists = false
296-
const filePath = path.join(Context.config.p2p.verticalScalingMode.path, '.sync-request')
297-
if (Context.config.p2p.verticalScalingMode.enabled) {
298+
const filePath = path.join(localConfig.verticalScalingMode_path, '.sync-request')
299+
if (localConfig.verticalScalingMode_enabled) {
298300
info('verticalScalingMode: enabled')
299301
// eslint-disable-next-line security/detect-non-literal-fs-filename
300302
fileExists = await fs.stat(filePath)
@@ -307,7 +309,11 @@ export function startupV2(shardus: Shardus): Promise<boolean> {
307309
try {
308310
// eslint-disable-next-line security/detect-non-literal-fs-filename
309311
await fs.writeFile(filePath, resp.id)
310-
process.exit(1) // exiting with status 1 causes our modified PM2 to not restart the process
312+
if (localConfig.verticalScalingMode_shutdown_mode === 'shutdown') {
313+
process.exit(1) // exiting with status 1 causes our modified PM2 to not restart the process
314+
} else {
315+
await sleep(10 * 10000) // sleep for 10 seconds
316+
}
311317
} catch (err) {
312318
console.error('The file could not be saved:', err)
313319
}
@@ -317,7 +323,7 @@ export function startupV2(shardus: Shardus): Promise<boolean> {
317323
//detect if we are a zombie node (bounce and network think we are still active)
318324
//if we never even tried to join yet but the network thinks we are active
319325
//then we are a zombie node
320-
const skipSyncingState = Context.config.p2p.verticalScalingMode.enabled && fileExists
326+
const skipSyncingState = localConfig.verticalScalingMode_enabled && fileExists
321327
info(`startupV2: skipSyncingState ${skipSyncingState}`)
322328
if (firstTimeJoiningLoop === true && !skipSyncingState) {
323329
isFailed = true
@@ -344,7 +350,7 @@ export function startupV2(shardus: Shardus): Promise<boolean> {
344350
}
345351

346352
// cleanup the file for the next run
347-
if (Context.config.p2p.verticalScalingMode.enabled && fileExists) {
353+
if (localConfig.verticalScalingMode_enabled && fileExists) {
348354
try {
349355
// eslint-disable-next-line security/detect-non-literal-fs-filename
350356
await fs.unlink(filePath)

src/shardus/shardus-types.ts

-5
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,6 @@ export interface ServerConfiguration {
10041004
patchNetworkAccountSyncFixes?: boolean
10051005
// enable shard key refactoring changes as part of SHARD-1892 sec fixes
10061006
enableShardKeyChanges : boolean
1007-
// settings for verical scaling by shutting down nodes after syncing is done and restarting them on better provisioned machines
1008-
verticalScalingMode: {
1009-
enabled: boolean,
1010-
path: string
1011-
}
10121007
}
10131008
/** Server IP configuration */
10141009
ip?: {

0 commit comments

Comments
 (0)