| 480 | const int64_t BufferPoolTest::TEST_BUFFER_LEN; |
| 481 | |
| 482 | void BufferPoolTest::RegisterQueriesAndClients(BufferPool* pool, int query_id_hi, |
| 483 | int num_queries, int64_t initial_query_reservation, int64_t query_reservation_limit, |
| 484 | mt19937* rng) { |
| 485 | Status status; |
| 486 | |
| 487 | int clients_per_query = 32; |
| 488 | BufferPool::ClientHandle* clients[num_queries]; |
| 489 | |
| 490 | for (int i = 0; i < num_queries; ++i) { |
| 491 | int64_t query_id = QueryId(query_id_hi, i); |
| 492 | |
| 493 | // Initialize a tracker for a new query. |
| 494 | ReservationTracker* query_reservation = GetQueryReservationTracker(query_id); |
| 495 | query_reservation->InitChildTracker( |
| 496 | NULL, &global_reservations_, NULL, query_reservation_limit); |
| 497 | |
| 498 | // Test that closing then reopening child tracker works. |
| 499 | query_reservation->Close(); |
| 500 | query_reservation->InitChildTracker( |
| 501 | NULL, &global_reservations_, NULL, query_reservation_limit); |
| 502 | EXPECT_TRUE(query_reservation->IncreaseReservationToFit(initial_query_reservation)); |
| 503 | |
| 504 | clients[i] = new BufferPool::ClientHandle[clients_per_query]; |
| 505 | |
| 506 | for (int j = 0; j < clients_per_query; ++j) { |
| 507 | int64_t initial_client_reservation = |
| 508 | initial_query_reservation / clients_per_query + j |
| 509 | < initial_query_reservation % clients_per_query; |
| 510 | // Reservation limit can be anything greater or equal to the initial reservation. |
| 511 | int64_t client_reservation_limit = initial_client_reservation + (*rng)() % 100000; |
| 512 | string name = Substitute("Client $0 for query $1", j, query_id); |
| 513 | EXPECT_OK(pool->RegisterClient(name, NULL, query_reservation, NULL, |
| 514 | client_reservation_limit, NewProfile(), &clients[i][j])); |
| 515 | EXPECT_TRUE(clients[i][j].IncreaseReservationToFit(initial_client_reservation)); |
| 516 | } |
| 517 | |
| 518 | for (int j = 0; j < clients_per_query; ++j) { |
| 519 | ASSERT_TRUE(clients[i][j].is_registered()); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | // Deregister clients then query. |
| 524 | for (int i = 0; i < num_queries; ++i) { |
| 525 | for (int j = 0; j < clients_per_query; ++j) { |
| 526 | pool->DeregisterClient(&clients[i][j]); |
| 527 | ASSERT_FALSE(clients[i][j].is_registered()); |
| 528 | } |
| 529 | |
| 530 | delete[] clients[i]; |
| 531 | |
| 532 | GetQueryReservationTracker(QueryId(query_id_hi, i))->Close(); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /// Test that queries and clients can be registered and deregistered with the reservation |
| 537 | /// trackers and the buffer pool. |
nothing calls this directly
no test coverage detected