bool ServerCollect::touch(bool& promote, int32_t& count, const double average_used_capacity) { bool ret = ((is_report_block_complete() || promote) /*&& !is_full()*/ && count > 0); if (!ret) { count = 0; } else { BlockCollect* invalid_blocks[1024]; ArrayHelper<BlockCollect*> helper(1024, invalid_blocks); RWLock::Lock lock(mutex_, WRITE_LOCKER); int32_t current = hold_master_->size(); TBSYS_LOG(DEBUG, "%s touch current %d, writable size: %d", CNetUtil::addrToString(id()).c_str(),current, writable_->size()); if (current >= SYSPARAM_NAMESERVER.max_write_file_count_) { count = 0; } else { count = std::min(count, (SYSPARAM_NAMESERVER.max_write_file_count_ - current)); if (count <= 0) { TBSYS_LOG(DEBUG, "%s", "there is any block need add into hold_master_"); } else { int32_t actual = 0; double use_capacity_ratio = use_capacity_ / total_capacity_; double max_average_use_capacity_ratio = average_used_capacity * AVERAGE_USED_CAPACITY_MULTIPLE; BlockCollect* block = NULL; TfsVector<BlockCollect*>::iterator where; while ((!writable_->empty()) && (writable_index_ < writable_->size()) && (actual < count)) { block = writable_->at(writable_index_); ++writable_index_; if (!block->is_writable()) { if (block->is_full()) helper.push_back(block); continue; } if (!is_equal_group(block->id())) { helper.push_back(block); continue; } if (!block->is_master(this)) continue; where = hold_master_->find(block); if (hold_master_->end() == where) { ++actual; hold_master_->push_back(block); } } if (writable_index_ >= writable_->size()) writable_index_ = 0; for (int32_t i = 0; i < helper.get_array_index(); ++i) { block = *helper.at(i); writable_->erase(block); } if (!is_full() && ((use_capacity_ratio < max_average_use_capacity_ratio) || max_average_use_capacity_ratio <= PERCENTAGE_MIN)) { count -= actual; } else { count = 0; } } } } return ret; }