Skip to content

Commit

Permalink
fix: PAGE_SIZE,CLIENT_READ_SCHEDULE env params
Browse files Browse the repository at this point in the history
  • Loading branch information
Igx22 committed Jul 9, 2024
1 parent fc0a47b commit 451e7d6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
8 changes: 5 additions & 3 deletions snode/src/api/routes/storageRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import StorageNode from "../../services/messaging/storageNode";
import {Coll} from "../../utilz/coll";
import {MessageBlockUtil} from "../../services/messaging-common/messageBlock";
import {StorageContractState} from "../../services/messaging-common/storageContractState";
import {EnvLoader} from "../../utilz/envLoader";

const PAGE_SIZE = Number.parseInt(EnvLoader.getPropertyOrDefault("PAGE_SIZE", "30"));

const route = Router();
const dbh = new DbHelper();
Expand Down Expand Up @@ -160,7 +163,7 @@ export function storageRoutes(app: Router) {
const valContractState = Container.get(ValidatorContractState);
const storageContractState = Container.get(StorageContractState);
const nodeId = valContractState.nodeId; // todo read this from db
log.debug(`nsName=${nsName} nsIndex=${nsIndex} dt=${dt} nodeId=${nodeId}`);
log.debug(`nsName=${nsName} nsIndex=${nsIndex} dt=${dt} nodeId=${nodeId} PAGE_SIZE=${PAGE_SIZE}`);
let shardId = MessageBlockUtil.calculateAffectedShard(nsIndex, storageContractState.shardCount);
const date = DateTime.fromISO(dt, {zone: 'utc'});
if (!date.isValid) {
Expand All @@ -173,8 +176,7 @@ export function storageRoutes(app: Router) {
log.error('storage table not found');
return res.status(401).json('storage table not found');
}

const storageValue = await DbHelper.listInbox(nsName, shardId, nsIndex, storageTable, firstTs);
const storageValue = await DbHelper.listInbox(nsName, shardId, nsIndex, storageTable, firstTs, PAGE_SIZE);
log.debug(`found value: ${storageValue}`)
try {
return res.status(200).json(storageValue);
Expand Down
3 changes: 1 addition & 2 deletions snode/src/helpers/dbHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ END $$ LANGUAGE plpgsql;
}

static async listInbox(namespace: string, namespaceShardId: number, nsIndex:string,
storageTable: string, firstTsExcluded: string): Promise<object> {
const pageSize = 5;
storageTable: string, firstTsExcluded: string, pageSize:number): Promise<object> {
const pageLookAhead = 3;
const pageSizeForSameTimestamp = pageSize * 20;
const isFirstQuery = StrUtil.isEmpty(firstTsExcluded);
Expand Down
3 changes: 2 additions & 1 deletion snode/src/services/messaging/queueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {QueueServer} from '../messaging-dset/queueServer'
import {QueueClient} from '../messaging-dset/queueClient'
import StorageNode from "./storageNode";
import {QueueClientHelper} from "../messaging-common/queueClientHelper";
import {EnvLoader} from "../../utilz/envLoader";


@Service()
Expand All @@ -20,7 +21,7 @@ export class QueueManager {


// PING: schedule
private readonly CLIENT_READ_SCHEDULE = '*/30 * * * * *'
private readonly CLIENT_READ_SCHEDULE = EnvLoader.getPropertyOrDefault('CLIENT_READ_SCHEDULE', '*/30 * * * * *');

public static QUEUE_MBLOCK = 'mblock'
mblockQueue: QueueServer
Expand Down
8 changes: 8 additions & 0 deletions snode/src/utilz/envLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ export class EnvLoader {
const val = process.env[propName]
return val != null && val.toLowerCase() === 'true'
}

public static getPropertyOrDefault(propName: string, def:string): string {
const val = process.env[propName]
if (StrUtil.isEmpty(val)) {
return def;
}
return val
}
}

0 comments on commit 451e7d6

Please sign in to comment.