| 152 | } |
| 153 | |
| 154 | bool ScannerImpl::Init() { |
| 155 | tera::ErrorCode err; |
| 156 | if (!tera_client_) { |
| 157 | tera_client_.reset(tera::Client::NewClient(FLAGS_flagfile, &err)); |
| 158 | |
| 159 | if (tera::ErrorCode::kOK != err.GetType()) { |
| 160 | LOG(ERROR) << "init tera client [" << FLAGS_flagfile << "] failed, " << err.ToString(); |
| 161 | return false; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // init key_selector_ |
| 166 | // different selector started by different flags |
| 167 | if (options_.strategy == ScanStrategy::kRandom) { |
| 168 | LOG(INFO) << "random key"; |
| 169 | key_selector_.reset(new RandomKeySelector()); |
| 170 | } else if (options_.strategy == ScanStrategy::kTabletBucket) { |
| 171 | LOG(INFO) << "tablet bucket key"; |
| 172 | key_selector_.reset(new TabletBucketKeySelector(options_.bucket_id, options_.bucket_cnt)); |
| 173 | } |
| 174 | |
| 175 | return true; |
| 176 | } |
| 177 | |
| 178 | bool ScannerImpl::Start() { |
| 179 | for (int32_t idx = 0; idx < FLAGS_observer_scanner_thread_num; ++idx) { |