Construct hash table and buffer pool client. Returns true if HashTable::Init() was successful. Created objects and resources (e.g. reservations) are automatically freed in TearDown().
| 233 | /// Returns true if HashTable::Init() was successful. Created objects |
| 234 | /// and resources (e.g. reservations) are automatically freed in TearDown(). |
| 235 | bool CreateHashTable(bool quadratic, int64_t initial_num_buckets, HashTable** table, |
| 236 | int64_t block_size = 8 * 1024 * 1024, int max_num_blocks = 100, |
| 237 | int initial_reserved_blocks = 10, int64_t suballocator_buffer_len = 64 * 1024) { |
| 238 | BufferPool* buffer_pool = test_env_->exec_env()->buffer_pool(); |
| 239 | RuntimeProfile* profile = RuntimeProfile::Create(&pool_, "ht"); |
| 240 | |
| 241 | // Set up memory tracking for the hash table. |
| 242 | MemTracker* client_tracker = |
| 243 | pool_.Add(new MemTracker(-1, "client", runtime_state_->instance_mem_tracker())); |
| 244 | int64_t initial_reservation_bytes = block_size * initial_reserved_blocks; |
| 245 | int64_t max_reservation_bytes = block_size * max_num_blocks; |
| 246 | |
| 247 | // Set up the memory allocator. |
| 248 | BufferPool::ClientHandle* client = pool_.Add(new BufferPool::ClientHandle); |
| 249 | clients_.push_back(client); |
| 250 | EXPECT_OK(buffer_pool->RegisterClient("", nullptr, |
| 251 | runtime_state_->instance_buffer_reservation(), client_tracker, |
| 252 | max_reservation_bytes, profile, client)); |
| 253 | EXPECT_TRUE(client->IncreaseReservation(initial_reservation_bytes)); |
| 254 | Suballocator* allocator = |
| 255 | pool_.Add(new Suballocator(buffer_pool, client, suballocator_buffer_len)); |
| 256 | |
| 257 | // Initial_num_buckets must be a power of two. |
| 258 | EXPECT_EQ(initial_num_buckets, BitUtil::RoundUpToPowerOfTwo(initial_num_buckets)); |
| 259 | int64_t max_num_buckets = 1L << 31; |
| 260 | *table = pool_.Add(new HashTable( |
| 261 | quadratic, allocator, true, 1, nullptr, max_num_buckets, initial_num_buckets)); |
| 262 | hash_tables_.push_back(*table); |
| 263 | bool success; |
| 264 | Status status = (*table)->Init(&success); |
| 265 | EXPECT_OK(status); |
| 266 | return status.ok() && success; |
| 267 | } |
| 268 | |
| 269 | // Constructs and closes a hash table. |
| 270 | void SetupTest(bool quadratic, int64_t initial_num_buckets, bool too_big) { |
nothing calls this directly
no test coverage detected