MCPcopy Create free account
hub / github.com/apache/impala / ThreadFn

Method ThreadFn

be/src/runtime/io/data-cache-test.cc:282–318  ·  view source on GitHub ↗

The function is invoked by each thread in the multi-threaded tests below. It inserts chunks of size TEMP_BUFFER_SIZE from different offsets at range [0, 'max_test_offset') from 'test_buffer_'. Afterwards, it tries reading back all the inserted chunks. 'fname_prefix' is the prefix added to the default filename when inserting into the cache. 'max_test_offset' and 'fname_prefix' implicitly control t

Source from the content-addressed store, hash-verified

280 // of cache keys which indirectly control the cache footprint. 'num_misses' records
281 // the number of cache misses.
282 void ThreadFn(const string& fname_prefix, DataCache* cache, int64_t max_start_offset,
283 CountingBarrier* store_barrier, int* num_misses, int64_t* write_time_us) {
284 const string& custom_fname = Substitute("$0file", fname_prefix);
285 vector<int64_t> offsets;
286 for (int64_t offset = 0; offset < max_start_offset; ++offset) {
287 offsets.push_back(offset);
288 }
289 random_shuffle(offsets.begin(), offsets.end());
290 int64_t write_start_time = UnixMicros();
291 for (int64_t offset : offsets) {
292 cache->Store(custom_fname, MTIME, offset, test_buffer() + offset,
293 TEMP_BUFFER_SIZE);
294 }
295 *write_time_us = UnixMicros() - write_start_time;
296 // Wait until all threads have finished inserting. Since different threads may be
297 // inserting the same cache key and collide, only one thread which wins the race will
298 // insert the cache entry. Make sure other threads which lose out on the race will
299 // wait for the insertion to complete first before proceeding.
300 store_barrier->Notify();
301 store_barrier->Wait();
302
303 // Before continue, we should wait for all asynchronous store tasks (if there are)
304 // finished.
305 WaitForAsyncWrite(*cache);
306 for (int64_t offset : offsets) {
307 uint8_t buffer[TEMP_BUFFER_SIZE];
308 memset(buffer, 0, TEMP_BUFFER_SIZE);
309 int64_t bytes_read =
310 cache->Lookup(custom_fname, MTIME, offset, TEMP_BUFFER_SIZE, buffer);
311 if (bytes_read == TEMP_BUFFER_SIZE) {
312 ASSERT_EQ(0, memcmp(buffer, test_buffer() + offset, TEMP_BUFFER_SIZE));
313 } else {
314 ASSERT_EQ(bytes_read, 0);
315 ++(*num_misses);
316 }
317 }
318 }
319};
320
321class DataCacheTest :

Callers

nothing calls this directly

Calls 9

SubstituteFunction · 0.85
UnixMicrosFunction · 0.85
push_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
StoreMethod · 0.45
NotifyMethod · 0.45
WaitMethod · 0.45
LookupMethod · 0.45

Tested by

no test coverage detected