Search in sources :

Example 6 with TestingTicker

use of io.airlift.testing.TestingTicker in project presto by prestodb.

the class TestShardCleaner method setup.

@BeforeMethod
public void setup() throws Exception {
    dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime());
    dummyHandle = dbi.open();
    createTablesWithRetry(dbi);
    temporary = createTempDir();
    File directory = new File(temporary, "data");
    storageService = new FileStorageService(directory);
    storageService.start();
    File backupDirectory = new File(temporary, "backup");
    backupStore = new FileBackupStore(backupDirectory);
    ((FileBackupStore) backupStore).start();
    ticker = new TestingTicker();
    ShardCleanerConfig config = new ShardCleanerConfig();
    cleaner = new ShardCleaner(new DaoSupplier<>(dbi, H2ShardDao.class), "node1", true, ticker, storageService, Optional.of(backupStore), config.getMaxTransactionAge(), config.getTransactionCleanerInterval(), config.getLocalCleanerInterval(), config.getLocalCleanTime(), config.getBackupCleanerInterval(), config.getBackupCleanTime(), config.getBackupDeletionThreads(), config.getMaxCompletedTransactionAge());
}
Also used : FileBackupStore(com.facebook.presto.raptor.backup.FileBackupStore) TestingTicker(io.airlift.testing.TestingTicker) FileStorageService(com.facebook.presto.raptor.storage.FileStorageService) IDBI(org.skife.jdbi.v2.IDBI) DBI(org.skife.jdbi.v2.DBI) DaoSupplier(com.facebook.presto.raptor.util.DaoSupplier) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with TestingTicker

use of io.airlift.testing.TestingTicker in project presto by prestodb.

the class TestAssignmentLimiter method testLimiter.

@Test
public void testLimiter() {
    TestingTicker ticker = new TestingTicker();
    AssignmentLimiter limiter = new AssignmentLimiter(ImmutableSet::of, ticker, new Duration(5, MINUTES), new Duration(10, MINUTES));
    // 4:00
    assertCheckFails(limiter, "A", RAPTOR_REASSIGNMENT_DELAY);
    // 4:01
    ticker.increment(1, MINUTES);
    assertCheckFails(limiter, "A", RAPTOR_REASSIGNMENT_DELAY);
    assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_DELAY);
    // 4:05
    ticker.increment(4, MINUTES);
    limiter.checkAssignFrom("A");
    assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_DELAY);
    // 4:06
    ticker.increment(1, MINUTES);
    assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_THROTTLE);
    assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_DELAY);
    // 4:14
    ticker.increment(8, MINUTES);
    assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_THROTTLE);
    assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_THROTTLE);
    // 4:15
    ticker.increment(1, MINUTES);
    limiter.checkAssignFrom("B");
    assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_THROTTLE);
    // 4:24
    ticker.increment(9, MINUTES);
    assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_THROTTLE);
    // 4:25
    ticker.increment(1, MINUTES);
    limiter.checkAssignFrom("A");
    // 4:30
    ticker.increment(5, MINUTES);
    limiter.checkAssignFrom("A");
    limiter.checkAssignFrom("B");
    limiter.checkAssignFrom("C");
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) ImmutableSet(com.google.common.collect.ImmutableSet) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 8 with TestingTicker

use of io.airlift.testing.TestingTicker in project presto by prestodb.

the class TestDatabaseShardManager method testBucketAssignments.

@Test
public void testBucketAssignments() {
    Node node1 = createTestingNode();
    Node node2 = createTestingNode();
    Node node3 = createTestingNode();
    TestingTicker ticker = new TestingTicker();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    int bucketCount = 13;
    long distributionId = metadataDao.insertDistribution(null, "test", bucketCount);
    Set<Node> originalNodes = ImmutableSet.of(node1, node2);
    ShardManager shardManager = createShardManager(dbi, () -> originalNodes, ticker);
    shardManager.createBuckets(distributionId, bucketCount);
    Map<Integer, String> assignments = shardManager.getBucketAssignments(distributionId);
    assertEquals(assignments.size(), bucketCount);
    assertEquals(ImmutableSet.copyOf(assignments.values()), nodeIds(originalNodes));
    Set<Node> newNodes = ImmutableSet.of(node1, node3);
    shardManager = createShardManager(dbi, () -> newNodes, ticker);
    try {
        shardManager.getBucketAssignments(distributionId);
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), SERVER_STARTING_UP.toErrorCode());
    }
    ticker.increment(2, DAYS);
    assignments = shardManager.getBucketAssignments(distributionId);
    assertEquals(assignments.size(), bucketCount);
    assertEquals(ImmutableSet.copyOf(assignments.values()), nodeIds(newNodes));
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Node(com.facebook.presto.spi.Node) PrestoNode(com.facebook.presto.metadata.PrestoNode) PrestoException(com.facebook.presto.spi.PrestoException) Test(org.testng.annotations.Test)

Example 9 with TestingTicker

use of io.airlift.testing.TestingTicker in project presto by prestodb.

the class TestBackoff method testMaxFailureInterval.

@Test
public void testMaxFailureInterval() {
    TestingTicker ticker = new TestingTicker();
    Backoff backoff = new Backoff(new Duration(5, SECONDS), new Duration(15, SECONDS), ticker, new Duration(10, MILLISECONDS));
    ticker.increment(10, MICROSECONDS);
    ticker.increment(6, SECONDS);
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 6);
    backoff.success();
    // Check that we will tolerate failures for longer than the min, if the query has been running that long
    ticker.increment(6, SECONDS);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 6);
    ticker.increment(1, SECONDS);
    // Check that we won't tolerate failures for longer than the query has been running
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 2);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 7);
    ticker.increment(20, SECONDS);
    backoff.success();
    ticker.increment(20, SECONDS);
    // Check that we won't tolerate failures for longer than the max, even if the query has been running for a long time
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 20);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 10 with TestingTicker

use of io.airlift.testing.TestingTicker in project presto by prestodb.

the class TestBackoff method testStartRequest.

@Test
public void testStartRequest() {
    TestingTicker ticker = new TestingTicker();
    Backoff backoff = new Backoff(new Duration(15, SECONDS), new Duration(15, SECONDS), ticker, new Duration(10, MILLISECONDS));
    ticker.increment(10, MICROSECONDS);
    assertEquals(backoff.getFailureCount(), 0);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 0);
    ticker.increment(14, SECONDS);
    backoff.startRequest();
    ticker.increment(14, SECONDS);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 28);
    ticker.increment(1, SECONDS);
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 2);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 29);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Aggregations

TestingTicker (io.airlift.testing.TestingTicker)10 Test (org.testng.annotations.Test)9 Duration (io.airlift.units.Duration)8 PRESTO_PAGES (com.facebook.presto.PrestoMediaTypes.PRESTO_PAGES)1 TaskHandle (com.facebook.presto.execution.TaskExecutor.TaskHandle)1 PagesSerde (com.facebook.presto.execution.buffer.PagesSerde)1 SerializedPage (com.facebook.presto.execution.buffer.SerializedPage)1 TestingPagesSerdeFactory.testingPagesSerde (com.facebook.presto.execution.buffer.TestingPagesSerdeFactory.testingPagesSerde)1 PrestoNode (com.facebook.presto.metadata.PrestoNode)1 ClientCallback (com.facebook.presto.operator.HttpPageBufferClient.ClientCallback)1 FileBackupStore (com.facebook.presto.raptor.backup.FileBackupStore)1 FileStorageService (com.facebook.presto.raptor.storage.FileStorageService)1 DaoSupplier (com.facebook.presto.raptor.util.DaoSupplier)1 Node (com.facebook.presto.spi.Node)1 Page (com.facebook.presto.spi.Page)1 PrestoException (com.facebook.presto.spi.PrestoException)1 PAGE_TOO_LARGE (com.facebook.presto.spi.StandardErrorCode.PAGE_TOO_LARGE)1 PAGE_TRANSPORT_ERROR (com.facebook.presto.spi.StandardErrorCode.PAGE_TRANSPORT_ERROR)1 PAGE_TRANSPORT_TIMEOUT (com.facebook.presto.spi.StandardErrorCode.PAGE_TRANSPORT_TIMEOUT)1 WORKER_NODE_ERROR (com.facebook.presto.util.Failures.WORKER_NODE_ERROR)1