Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug/extra logging #509

Merged
merged 11 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions codex/blockexchange/engine/discovery.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ proc discoveryQueueLoop(b: DiscoveryEngine) {.async.} =
trace "About to sleep discovery loop"
await sleepAsync(b.discoveryLoopSleep)

proc advertiseQueueLoop*(b: DiscoveryEngine) {.async.} =
proc advertiseQueueLoop(b: DiscoveryEngine) {.async.} =
while b.discEngineRunning:
if cids =? await b.localStore.listBlocks(blockType = b.advertiseType):
trace "Begin iterating blocks..."
for c in cids:
if cid =? await c:
await b.advertiseQueue.put(cid)
await sleepAsync(50.millis)
trace "Iterating blocks finished."

trace "About to sleep advertise loop", sleep = b.advertiseLoopSleep
await sleepAsync(b.advertiseLoopSleep)
Expand Down Expand Up @@ -256,7 +258,7 @@ proc new*(
advertiseType = BlockType.Both
): DiscoveryEngine =
## Create a discovery engine instance for advertising services
##
##
DiscoveryEngine(
localStore: localStore,
peers: peers,
Expand Down
12 changes: 11 additions & 1 deletion codex/blockexchange/engine/pendingblocks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
## those terms.

import std/tables
import std/monotimes

import pkg/upraises

Expand All @@ -24,6 +25,7 @@ logScope:
topics = "codex pendingblocks"

declareGauge(codexBlockExchangePendingBlockRequests, "codex blockexchange pending block requests")
declareGauge(codexBlockExchangeRetrievalTimeUs, "codex blockexchange block retrieval time us")

const
DefaultBlockTimeout* = 10.minutes
Expand All @@ -32,6 +34,7 @@ type
BlockReq* = object
handle*: Future[Block]
inFlight*: bool
startTime*: int64

PendingBlocksManager* = ref object of RootObj
blocks*: Table[Cid, BlockReq] # pending Block requests
Expand All @@ -52,7 +55,8 @@ proc getWantHandle*(
if cid notin p.blocks:
p.blocks[cid] = BlockReq(
handle: newFuture[Block]("pendingBlocks.getWantHandle"),
inFlight: inFlight)
inFlight: inFlight,
startTime: getMonoTime().ticks)

trace "Adding pending future for block", cid, inFlight = p.blocks[cid].inFlight

Expand Down Expand Up @@ -80,6 +84,12 @@ proc resolve*(p: PendingBlocksManager,
if not pending[].handle.completed:
trace "Resolving block", cid = blk.cid
pending[].handle.complete(blk)
let
startTime = pending[].startTime
stopTime = getMonoTime().ticks
retrievalDurationUs = (stopTime - startTime) div 1000
codexBlockExchangeRetrievalTimeUs.set(retrievalDurationUs)
trace "Block retrieval time", retrievalDurationUs

proc setInFlight*(p: PendingBlocksManager,
cid: Cid,
Expand Down
3 changes: 2 additions & 1 deletion codex/node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ proc store*(

trace "Stored data", manifestCid = manifest.cid,
contentCid = cid,
blocks = blockManifest.len
blocks = blockManifest.len,
size=blockManifest.originalBytes

# Announce manifest
await self.discovery.provide(manifest.cid)
Expand Down
4 changes: 3 additions & 1 deletion codex/rest/api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,15 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
trace "Uploaded file", cid
return RestApiResponse.response($cid)
except CancelledError:
trace "Upload cancelled error"
return RestApiResponse.error(Http500)
except AsyncStreamError:
trace "Async stream error"
return RestApiResponse.error(Http500)
finally:
await reader.closeWait()

# if we got here something went wrong?
trace "Something went wrong error"
return RestApiResponse.error(Http500)

router.api(
Expand Down
4 changes: 2 additions & 2 deletions codex/streams/storestream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ proc new*(
pad = true
): StoreStream =
## Create a new StoreStream instance for a given store and manifest
##
##
result = StoreStream(
store: store,
manifest: manifest,
Expand All @@ -79,7 +79,7 @@ method readOnce*(
## Read `nbytes` from current position in the StoreStream into output buffer pointed by `pbytes`.
## Return how many bytes were actually read before EOF was encountered.
## Raise exception if we are already at EOF.
##
##

trace "Reading from manifest", cid = self.manifest.cid.get(), blocks = self.manifest.len
if self.atEof:
Expand Down