Skip to content

Commit

Permalink
remove some log
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce authored and Bruce committed Oct 11, 2021
1 parent 731baf7 commit 2df4baa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
2 changes: 0 additions & 2 deletions packages/wsrpc/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ class G {
chain = chain
ConnCntMap[chain] = ConnCntMap[chain] || {}
ConnCntMap[chain][pid] = ConnCntMap[chain][pid] || 0
log.debug(`increase ${chain} pid[${pid}] connection count: ${ConnCntMap[chain][pid]}`)
ConnCntMap[chain][pid] += 1
}

static decrConnCnt(chain: string, pid: IDT) {
log.debug(`decrease ${chain} pid[${pid}] connection count: ${ConnCntMap[chain][pid]}`)
ConnCntMap[chain][pid] -= 1
if (ConnCntMap[chain][pid] < 1) {
delete ConnCntMap[chain][pid]
Expand Down
5 changes: 1 addition & 4 deletions packages/wsrpc/src/matcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,13 @@ class Matcher {
const kvStatOk = GG.getServerStatus(chain, NodeType.Kv)
const memOpen = GG.getSuberEnable(chain, NodeType.Mem)
const memStatOk = GG.getServerStatus(chain, NodeType.Mem)
log.debug(`puber before bind: kv[%o] mem[%o]`, puber.kvSubId, puber.memSubId)

if (kvOpen && kvStatOk) {
re = await suberBind(chain, puber, NodeType.Kv)
if (isErr(re)) {
log.error(`${chain}-${pid} bind node suber error: %o`, re.value)
return Err(`${chain}-${pid} bind node suber error`)
}
log.debug(`puber after bind kv: kv[%o] mem[%o]`, puber.kvSubId, puber.memSubId)
}

if (memOpen && memStatOk) {
Expand All @@ -229,7 +227,6 @@ class Matcher {
let type = ReqTyp.Rpc
let subsId
if (isUnsubReq(method)) {
log.debug(`${chain} pid[${pid}] pre handle unsubscribe request: ${method}: %o`, data.params)
if (data.params!.length < 1 || !Suber.isSubscribeID(data.params![0])) {
return Err(`invalid unsubscribe params: ${data.params![0]}`)
}
Expand Down Expand Up @@ -258,7 +255,7 @@ class Matcher {
} as ReqT
Puber.addReq(id, req.id)
Matcher.addReqCache(req)
log.info(`new ${chain} ${pid} ${subType} request cache: ${JSON.stringify(req)}`)
log.info(`new ${chain} ${pid} ${subType} request method[${method}] originId[${data.id}] cache id [${req.id}]`)

data.id = req.id as string
return Ok(data)
Expand Down
1 change: 1 addition & 0 deletions packages/wsrpc/src/puber/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export async function dispatchWs(chain: string, data: ReqDataT, puber: Puber, st
if (Cacher.statusOk(chain)) {// no need to clear puber.subid and suber.pubers
const res = { id, jsonrpc } as WsData
let tmethod = method
// cache for block hash at 0 block number
if (method === 'chain_getBlockHash' && (params?.length === 1 && params[0] === 0)) {
// log.debug(`${chain}-${nodeId} get ws initial block hash`)
tmethod = `${method}_0`
Expand Down
22 changes: 7 additions & 15 deletions packages/wsrpc/src/suber/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ async function parseReq(dat: WsData, chain: string): PResultT<ReqT | boolean> {
function handleUnsubscribe(req: ReqT, dres: boolean): void {
// rem subed topic, update puber.topics del submap
// emit done event when puber.topics.size == 0
log.info(`handle ${req.chain} pid[${req.pid}] unsubscribe response subscript id[${req.subsId}] params: %o`, req.params)

const pubId = req.pubId
const re = Puber.get(pubId)
let puber
Expand All @@ -122,7 +120,6 @@ function handleUnsubscribe(req: ReqT, dres: boolean): void {
GG.remSubTopic(req.chain, req.pid, subsId)

GG.delSubReqMap(subsId)
log.info(`clear ${req.chain} pid[${req.pid}] subscribe context cache: subsId[${subsId}] reqId[${reqId}]`)

if (puber !== undefined) {
puber.topics.delete(subsId)
Expand Down Expand Up @@ -190,14 +187,13 @@ async function dataParse(data: WebSocket.Data, chain: string, subType: NodeType,
dat = JSON.parse(dat.result)
}
// dat.error: no need handle
// log.debug(`${chain} new kv ws response method[${dat.method}] ID[${dat.id || dat.subscription}]: ${dat.error}`)
} else if (subType === NodeType.Mem) {
// log.debug(`${chain} new memory node ws response method[${dat.method}] ID[${dat.id || dat.subscription}]: ${dat.error}`)
} else {
// log.debug(`${chain} new node ws response method[${dat.method}] ID[${dat.id || dat.subscription}]: ${dat.error}`)
}
// NOTE: if asynclize parseReqId,
// subReqMap may uninit, then miss the first data response
}
// else if (subType === NodeType.Mem) {
// // log.debug(`${chain} new memory node ws response method[${dat.method}] ID[${dat.id || dat.subscription}]: ${dat.error}`)
// } else {
// // log.debug(`${chain} new node ws response method[${dat.method}] ID[${dat.id || dat.subscription}]: ${dat.error}`)
// }

let re: any = await parseReq(dat, chain)
if (isErr(re)) {
log.error(`parse ${chain} request cache error: %o`, re.value)
Expand Down Expand Up @@ -232,7 +228,6 @@ async function dataParse(data: WebSocket.Data, chain: string, subType: NodeType,
Matcher.updateReqCache(req)
Matcher.delReqCacheByPubStat(req.id)
Puber.remReq(req.pubId, req.id)
log.info(`delete ${req.chain} pid[${req.pid}] non-subscribe cache request ID[${req.id}]: %o`, req.method)
} else {
updateStatistic(req, data.toString())
}
Expand Down Expand Up @@ -276,16 +271,13 @@ async function dataParse(data: WebSocket.Data, chain: string, subType: NodeType,

const cache = await Dao.fetchSubscribeResponse(subsId)
if (isSome(cache)) {
log.warn(`${req.chain} pid[${req.pid}] puber[${req.pubId}] has response not sent yet, send now [${subsId}].`)
puberSend(req, cache.value)
// set expire duration to 1 minute, since high concurrency will
// block the subscribe response, once receive response, clear
Dao.clearSubscribeResponse(subsId)
}
log.info(`${req.chain} pid[${req.pid}] puber[${req.pubId}] subscribe topic[${req.method}] params[${req.params}] successfully: ${subsId}`)
} else {
// rpc request
log.info(`New web socket response ${req.chain} pid[${req.pid}] puber[${req.pubId}] method[${req.method}] params[${req.params}]`)
dataToSend = JSON.stringify(dat) //
}
return Ok({ req, data: dataToSend })
Expand Down

0 comments on commit 2df4baa

Please sign in to comment.