private synchronized boolean tryUpdateUserMemory(String allocationTag, long delta) { if (delta <= 0) { ListenableFuture<?> future = updateUserMemory(allocationTag, delta); // When delta == 0 and the pool is full the future can still not be done, // but, for negative deltas it must always be done. if (delta < 0) { verify(future.isDone(), "future should be done"); } return true; } if (queryMemoryContext.getUserMemory() + delta > maxUserMemory) { return false; } return memoryPool.tryReserve(queryId, allocationTag, delta); }
private synchronized boolean tryUpdateUserMemory(String allocationTag, long delta) { if (delta <= 0) { ListenableFuture<?> future = updateUserMemory(allocationTag, delta); // When delta == 0 and the pool is full the future can still not be done, // but, for negative deltas it must always be done. if (delta < 0) { verify(future.isDone(), "future should be done"); } return true; } if (queryMemoryContext.getUserMemory() + delta > maxUserMemory) { return false; } return memoryPool.tryReserve(queryId, allocationTag, delta); }
private synchronized boolean tryUpdateUserMemory(String allocationTag, long delta) { if (delta <= 0) { ListenableFuture<?> future = updateUserMemory(allocationTag, delta); // When delta == 0 and the pool is full the future can still not be done, // but, for negative deltas it must always be done. if (delta < 0) { verify(future.isDone(), "future should be done"); } return true; } if (queryMemoryContext.getUserMemory() + delta > maxMemory) { return false; } return memoryPool.tryReserve(queryId, allocationTag, delta); }
@Test public void testBlockingOnUserMemory() { setUpCountStarFromOrdersWithJoin(); assertTrue(userPool.tryReserve(fakeQueryId, "test", TEN_MEGABYTES.toBytes())); runDriversUntilBlocked(waitingForUserMemory()); assertTrue(userPool.getFreeBytes() <= 0, String.format("Expected empty pool but got [%d]", userPool.getFreeBytes())); userPool.free(fakeQueryId, "test", TEN_MEGABYTES.toBytes()); assertDriversProgress(waitingForUserMemory()); }
@Test public void testBlockingOnRevocableMemoryFreeUser() { setupConsumeRevocableMemory(ONE_BYTE, 10); assertTrue(userPool.tryReserve(fakeQueryId, "test", TEN_MEGABYTES_WITHOUT_TWO_BYTES.toBytes())); // we expect 2 iterations as we have 2 bytes remaining in memory pool and we allocate 1 byte per page assertEquals(runDriversUntilBlocked(waitingForRevocableSystemMemory()), 2); assertTrue(userPool.getFreeBytes() <= 0, String.format("Expected empty pool but got [%d]", userPool.getFreeBytes())); // lets free 5 bytes userPool.free(fakeQueryId, "test", 5); assertEquals(runDriversUntilBlocked(waitingForRevocableSystemMemory()), 5); assertTrue(userPool.getFreeBytes() <= 0, String.format("Expected empty pool but got [%d]", userPool.getFreeBytes())); // 3 more bytes is enough for driver to finish userPool.free(fakeQueryId, "test", 3); assertDriversProgress(waitingForRevocableSystemMemory()); assertEquals(userPool.getFreeBytes(), 10); }
@Test public void testBlockingOnUserMemory() { setUpCountStarFromOrdersWithJoin(); assertTrue(userPool.tryReserve(fakeQueryId, "test", TEN_MEGABYTES.toBytes())); runDriversUntilBlocked(waitingForUserMemory()); assertTrue(userPool.getFreeBytes() <= 0, String.format("Expected empty pool but got [%d]", userPool.getFreeBytes())); userPool.free(fakeQueryId, "test", TEN_MEGABYTES.toBytes()); assertDriversProgress(waitingForUserMemory()); }
for (TestingPrestoServer server : queryRunner.getServers()) { for (MemoryPool pool : server.getLocalMemoryManager().getPools()) { assertTrue(pool.tryReserve(fakeQueryId, "test", pool.getMaxBytes()));
@Test public void testBlockingOnRevocableMemoryFreeUser() { setupConsumeRevocableMemory(ONE_BYTE, 10); assertTrue(userPool.tryReserve(fakeQueryId, "test", TEN_MEGABYTES_WITHOUT_TWO_BYTES.toBytes())); // we expect 2 iterations as we have 2 bytes remaining in memory pool and we allocate 1 byte per page assertEquals(runDriversUntilBlocked(waitingForRevocableSystemMemory()), 2); assertTrue(userPool.getFreeBytes() <= 0, String.format("Expected empty pool but got [%d]", userPool.getFreeBytes())); // lets free 5 bytes userPool.free(fakeQueryId, "test", 5); assertEquals(runDriversUntilBlocked(waitingForRevocableSystemMemory()), 5); assertTrue(userPool.getFreeBytes() <= 0, String.format("Expected empty pool but got [%d]", userPool.getFreeBytes())); // 3 more bytes is enough for driver to finish userPool.free(fakeQueryId, "test", 3); assertDriversProgress(waitingForRevocableSystemMemory()); assertEquals(userPool.getFreeBytes(), 10); }
List<MemoryPool> memoryPools = server.getLocalMemoryManager().getPools(); assertEquals(memoryPools.size(), 1, "Only general pool should exist"); assertTrue(memoryPools.get(0).tryReserve(fakeQueryId, "test", memoryPools.get(0).getMaxBytes()));
@Test public void testBlockingOnRevocableMemoryFreeViaRevoke() { RevocableMemoryOperator revocableMemoryOperator = setupConsumeRevocableMemory(ONE_BYTE, 5); assertTrue(userPool.tryReserve(fakeQueryId, "test", TEN_MEGABYTES_WITHOUT_TWO_BYTES.toBytes())); // we expect 2 iterations as we have 2 bytes remaining in memory pool and we allocate 1 byte per page assertEquals(runDriversUntilBlocked(waitingForRevocableSystemMemory()), 2); revocableMemoryOperator.getOperatorContext().requestMemoryRevoking(); // 2 more iterations assertEquals(runDriversUntilBlocked(waitingForRevocableSystemMemory()), 2); revocableMemoryOperator.getOperatorContext().requestMemoryRevoking(); // 3 more bytes is enough for driver to finish assertDriversProgress(waitingForRevocableSystemMemory()); assertEquals(userPool.getFreeBytes(), 2); }
@Test public void testBlockingOnRevocableMemoryFreeViaRevoke() { RevocableMemoryOperator revocableMemoryOperator = setupConsumeRevocableMemory(ONE_BYTE, 5); assertTrue(userPool.tryReserve(fakeQueryId, "test", TEN_MEGABYTES_WITHOUT_TWO_BYTES.toBytes())); // we expect 2 iterations as we have 2 bytes remaining in memory pool and we allocate 1 byte per page assertEquals(runDriversUntilBlocked(waitingForRevocableSystemMemory()), 2); revocableMemoryOperator.getOperatorContext().requestMemoryRevoking(); // 2 more iterations assertEquals(runDriversUntilBlocked(waitingForRevocableSystemMemory()), 2); revocableMemoryOperator.getOperatorContext().requestMemoryRevoking(); // 3 more bytes is enough for driver to finish assertDriversProgress(waitingForRevocableSystemMemory()); assertEquals(userPool.getFreeBytes(), 2); }
for (TestingPrestoServer server : queryRunner.getServers()) { for (MemoryPool pool : server.getLocalMemoryManager().getPools()) { assertTrue(pool.tryReserve(fakeQueryId, "test", pool.getMaxBytes()));