| 312 | } |
| 313 | |
| 314 | bool BlockChunkCacheAdapter::processReq(BlockReqWrapper& rw, |
| 315 | OpResultType result) { |
| 316 | // We are only done if we have got everything. |
| 317 | bool done = false; |
| 318 | if (result == OpResultType::kGetHit || result == OpResultType::kSetSuccess || |
| 319 | result == OpResultType::kSetFailure || result == OpResultType::kSetSkip) { |
| 320 | // Update the piece fetch index |
| 321 | rw.cachePieces->updateFetchIndex(); |
| 322 | |
| 323 | // The piece index we need to fetch next |
| 324 | auto nextPieceIndex = rw.cachePieces->getCurFetchingPieceIndex(); |
| 325 | |
| 326 | // Record the cache hit stats |
| 327 | if (result == OpResultType::kGetHit) { |
| 328 | auto resultPieceIndex = nextPieceIndex - 1; |
| 329 | // We always fetch a complete piece. |
| 330 | auto pieceSize = rw.cachePieces->getSizeOfAPiece(resultPieceIndex); |
| 331 | stats_.recordPieceBodyHit(pieceSize); |
| 332 | } |
| 333 | |
| 334 | // Check if we have got all the pieces we need to fetch |
| 335 | if (rw.cachePieces->isPieceWithinBound(nextPieceIndex)) { |
| 336 | XDCHECK_LT(nextPieceIndex, maxCachePieces_); |
| 337 | // Reset op since it could have been changed to kSet |
| 338 | rw.req.setOp(rw.op); |
| 339 | // Update the piece key and the size |
| 340 | rw.updatePieceKey( |
| 341 | ChunkPieces::createPieceKey(rw.baseKey, nextPieceIndex)); |
| 342 | XDCHECK_EQ(rw.sizes.size(), 1u); |
| 343 | rw.sizes[0] = rw.cachePieces->getSizeOfAPiece(nextPieceIndex); |
| 344 | } else { |
| 345 | // we are done |
| 346 | done = true; |
| 347 | } |
| 348 | } else if (result == OpResultType::kGetMiss) { |
| 349 | // We do the lookaside always, so perform set operation next |
| 350 | // for the current piece |
| 351 | rw.req.setOp(OpType::kSet); |
| 352 | auto curIndex = rw.cachePieces->getCurFetchingPieceIndex() - 1; |
| 353 | // Update the missing piece index accordingly |
| 354 | if (rw.missPieceRange.first < 0) { |
| 355 | rw.missPieceRange.first = curIndex; |
| 356 | } |
| 357 | rw.missPieceRange.second = curIndex; |
| 358 | } else { |
| 359 | XLOG(INFO) << "Unsupported OpResultType: " << static_cast<int>(result); |
| 360 | done = true; |
| 361 | } |
| 362 | |
| 363 | if (done && rw.op == OpType::kGet) { |
| 364 | // We have got all the pieces that are requested, record the full |
| 365 | if (rw.missPieceRange.first < 0) { |
| 366 | // No missing pieces, record full hit |
| 367 | stats_.recordRequestHit(rw.cachePieces->getTotalSize()); |
| 368 | } else { |
| 369 | // Record ingress bytes since we will fetch the bytes from upstream. |
| 370 | // Note that we always fetch all the missing pieces as one operation, |
| 371 | // meaning any hit pieces in the middle will also be fetched again |
nothing calls this directly
no test coverage detected