| 370 | } |
| 371 | |
| 372 | void RequestContext::AddRangeToDisk(const unique_lock<mutex>& lock, |
| 373 | RequestRange* range, ScheduleMode schedule_mode) { |
| 374 | DCHECK(lock.mutex() == &lock_ && lock.owns_lock()); |
| 375 | DCHECK_EQ(state_, Active) << DebugString(); |
| 376 | PerDiskState* disk_state = &disk_states_[range->disk_id()]; |
| 377 | if (disk_state->done()) { |
| 378 | DCHECK_EQ(disk_state->num_remaining_ranges(), 0); |
| 379 | disk_state->set_done(false); |
| 380 | ++num_disks_with_ranges_; |
| 381 | } |
| 382 | if (range->request_type() == RequestType::READ) { |
| 383 | ScanRange* scan_range = static_cast<ScanRange*>(range); |
| 384 | if (schedule_mode == ScheduleMode::IMMEDIATELY) { |
| 385 | ScheduleScanRange(lock, scan_range); |
| 386 | } else if (schedule_mode != ScheduleMode::BY_CALLER) { |
| 387 | if (schedule_mode == ScheduleMode::UPON_GETNEXT_TAIL) { |
| 388 | disk_state->unstarted_scan_ranges()->Enqueue(scan_range); |
| 389 | } else { |
| 390 | DCHECK_ENUM_EQ(schedule_mode, ScheduleMode::UPON_GETNEXT_HEAD); |
| 391 | disk_state->unstarted_scan_ranges()->PushFront(scan_range); |
| 392 | } |
| 393 | num_unstarted_scan_ranges_.Add(1); |
| 394 | // If there's no 'next_scan_range_to_start', schedule this RequestContext so that |
| 395 | // one of the 'unstarted_scan_ranges' will become the 'next_scan_range_to_start'. |
| 396 | if (disk_state->next_scan_range_to_start() == nullptr) { |
| 397 | disk_state->ScheduleContext(lock, this, range->disk_id()); |
| 398 | } |
| 399 | } |
| 400 | } else if (range->request_type() == RequestType::WRITE) { |
| 401 | DCHECK(schedule_mode == ScheduleMode::IMMEDIATELY) << static_cast<int>(schedule_mode); |
| 402 | WriteRange* write_range = static_cast<WriteRange*>(range); |
| 403 | disk_state->unstarted_write_ranges()->Enqueue(write_range); |
| 404 | |
| 405 | // Ensure that the context is scheduled so that the write range gets picked up. |
| 406 | // ScheduleContext() has no effect if already scheduled, so this is safe to do always. |
| 407 | disk_state->ScheduleContext(lock, this, range->disk_id()); |
| 408 | } else { |
| 409 | DCHECK(range->request_type() == RequestType::FILE_UPLOAD |
| 410 | || range->request_type() == RequestType::FILE_FETCH); |
| 411 | DCHECK(schedule_mode == ScheduleMode::IMMEDIATELY) << static_cast<int>(schedule_mode); |
| 412 | RemoteOperRange* oper_range = static_cast<RemoteOperRange*>(range); |
| 413 | disk_state->unstarted_remote_file_oper_ranges()->Enqueue(oper_range); |
| 414 | disk_state->ScheduleContext(lock, this, range->disk_id()); |
| 415 | } |
| 416 | |
| 417 | ++disk_state->num_remaining_ranges(); |
| 418 | } |
| 419 | |
| 420 | Status RequestContext::AddScanRanges( |
| 421 | const vector<ScanRange*>& ranges, EnqueueLocation enqueue_location) { |
nothing calls this directly
no test coverage detected