Search in sources :

Example 1 with BadKeyReader

use of voldemort.utils.ConsistencyFix.BadKeyReader in project voldemort by voldemort.

the class ConsistencyFixTest method badKeyReaderHelper.

/**
 * @param orphan true for testing orphan, false for testing normal...
 */
public void badKeyReaderHelper(boolean orphan) {
    String tmpDir = TestUtils.createTempDir().getAbsolutePath();
    String fileName = tmpDir + "BadKeyFile";
    if (orphan) {
        badKeyReaderWriteOrphanKeys(fileName, true);
    } else {
        badKeyReaderWriteBadKeys(fileName, true);
    }
    // Get cluster bootstrap url
    String url = setUpCluster();
    // Construct ConsistencyFix with parseOnly true
    ConsistencyFix consistencyFix = new ConsistencyFix(url, STORE_NAME, 100, 100, false, true);
    // Do set up for BadKeyReader akin to consistencyFix.execute...
    int parallelism = 1;
    BlockingQueue<Runnable> blockingQ = new ArrayBlockingQueue<Runnable>(parallelism);
    RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
    ExecutorService consistencyFixWorkers = new ThreadPoolExecutor(parallelism, parallelism, 0L, TimeUnit.MILLISECONDS, blockingQ, rejectedExecutionHandler);
    BlockingQueue<BadKeyStatus> badKeyQOut = new ArrayBlockingQueue<BadKeyStatus>(10000);
    ExecutorService badKeyReaderService = Executors.newSingleThreadExecutor();
    CountDownLatch allBadKeysReadLatch = new CountDownLatch(1);
    // Submit file of bad keys to (appropriate) BadKeyReader
    BadKeyReader bkr = null;
    if (orphan) {
        bkr = new BadKeyOrphanReader(allBadKeysReadLatch, fileName, consistencyFix, consistencyFixWorkers, badKeyQOut);
    } else {
        bkr = new BadKeyReader(allBadKeysReadLatch, fileName, consistencyFix, consistencyFixWorkers, badKeyQOut);
    }
    badKeyReaderService.submit(bkr);
    // Wait for file to be processed.
    try {
        allBadKeysReadLatch.await();
        badKeyReaderService.shutdown();
        consistencyFixWorkers.shutdown();
    } catch (InterruptedException e) {
        e.printStackTrace();
        fail("Unexpected exception");
    }
    consistencyFix.close();
    // Make sure everything worked as expected.
    assertFalse(bkr.hasException());
    assertEquals(0, badKeyQOut.size());
}
Also used : BadKeyStatus(voldemort.utils.ConsistencyFix.BadKeyStatus) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) BadKeyOrphanReader(voldemort.utils.ConsistencyFix.BadKeyOrphanReader) CountDownLatch(java.util.concurrent.CountDownLatch) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ExecutorService(java.util.concurrent.ExecutorService) BadKeyReader(voldemort.utils.ConsistencyFix.BadKeyReader) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 BadKeyOrphanReader (voldemort.utils.ConsistencyFix.BadKeyOrphanReader)1 BadKeyReader (voldemort.utils.ConsistencyFix.BadKeyReader)1 BadKeyStatus (voldemort.utils.ConsistencyFix.BadKeyStatus)1