Search in sources :

Example 1 with BadKeyStatus

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

the class ConsistencyFixWorker method run.

@Override
public void run() {
    logger.trace("About to process key " + badKey + " (" + myName() + ")");
    Status status = doConsistencyFix();
    logger.trace("Finished processing key " + badKey + " (" + myName() + ")");
    consistencyFix.getStats().incrementFixCount();
    if (status != Status.SUCCESS) {
        try {
            badKeyQOut.put(new BadKeyStatus(badKey, status));
        } catch (InterruptedException ie) {
            logger.warn("Worker thread " + myName() + " interrupted.");
        }
        consistencyFix.getStats().incrementFailures(status);
    }
}
Also used : Status(voldemort.utils.ConsistencyFix.Status) BadKeyStatus(voldemort.utils.ConsistencyFix.BadKeyStatus) BadKeyStatus(voldemort.utils.ConsistencyFix.BadKeyStatus)

Example 2 with BadKeyStatus

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

the class ConsistencyFixTest method testBadKeyResult.

@Test
public void testBadKeyResult() {
    BadKey badKey = new BadKey("0101", "0101\n");
    ConsistencyFix.BadKeyStatus bkr1 = new BadKeyStatus(badKey, ConsistencyFix.Status.SUCCESS);
    assertFalse(bkr1.isPoison());
    assertEquals(bkr1.getBadKey().getKeyInHexFormat(), "0101");
    assertEquals(bkr1.getBadKey().getReaderInput(), "0101\n");
    assertEquals(bkr1.getStatus(), ConsistencyFix.Status.SUCCESS);
    ConsistencyFix.BadKeyStatus bkr2 = new BadKeyStatus();
    assertTrue(bkr2.isPoison());
    assertEquals(bkr2.getBadKey(), null);
    assertEquals(bkr2.getStatus(), null);
}
Also used : BadKeyStatus(voldemort.utils.ConsistencyFix.BadKeyStatus) BadKeyStatus(voldemort.utils.ConsistencyFix.BadKeyStatus) BadKey(voldemort.utils.ConsistencyFix.BadKey) Test(org.junit.Test)

Example 3 with BadKeyStatus

use of voldemort.utils.ConsistencyFix.BadKeyStatus 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)

Example 4 with BadKeyStatus

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

the class ConsistencyFixTest method testBadKeyWriter.

@Test
public void testBadKeyWriter() {
    String tmpDir = TestUtils.createTempDir().getAbsolutePath();
    String fileName = tmpDir + "BadKeyFile";
    // Set up bad key writer
    BlockingQueue<BadKeyStatus> bq = new ArrayBlockingQueue<BadKeyStatus>(5);
    ExecutorService badKeyWriterService = Executors.newSingleThreadExecutor();
    BadKeyWriter badKeyWriter = new BadKeyWriter(fileName, bq);
    badKeyWriterService.submit(badKeyWriter);
    // Enqueue stuff for bad key writer to write
    try {
        for (int i = 0; i < 100; ++i) {
            BadKey badKey = new BadKey(Integer.toHexString(i), Integer.toHexString(i) + "\n");
            bq.put(new BadKeyStatus(badKey, ConsistencyFix.Status.REPAIR_EXCEPTION));
        }
        // Poison bad key writer
        bq.put(new BadKeyStatus());
    } catch (InterruptedException e) {
        e.printStackTrace();
        fail("Unexpected exception");
    }
    // wait for bad key writer to shutdown
    badKeyWriterService.shutdown();
    try {
        badKeyWriterService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    } catch (InterruptedException e) {
        e.printStackTrace();
        fail("Unexpected exception");
    }
    assertFalse(badKeyWriter.hasException());
    // Read output file & verify.
    try {
        BufferedReader fileReader = new BufferedReader(new FileReader(fileName));
        int i = 0;
        for (String keyLine = fileReader.readLine(); keyLine != null; keyLine = fileReader.readLine()) {
            assertEquals(keyLine, Integer.toHexString(i));
            i++;
        }
    } catch (FileNotFoundException fnfe) {
        fnfe.printStackTrace();
        fail("Unexpected exception");
    } catch (IOException ioe) {
        ioe.printStackTrace();
        fail("Unexpected exception");
    }
}
Also used : BadKeyStatus(voldemort.utils.ConsistencyFix.BadKeyStatus) FileNotFoundException(java.io.FileNotFoundException) BadKeyWriter(voldemort.utils.ConsistencyFix.BadKeyWriter) IOException(java.io.IOException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ExecutorService(java.util.concurrent.ExecutorService) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) BadKey(voldemort.utils.ConsistencyFix.BadKey) Test(org.junit.Test)

Aggregations

BadKeyStatus (voldemort.utils.ConsistencyFix.BadKeyStatus)4 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 ExecutorService (java.util.concurrent.ExecutorService)2 Test (org.junit.Test)2 BadKey (voldemort.utils.ConsistencyFix.BadKey)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)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 BadKeyWriter (voldemort.utils.ConsistencyFix.BadKeyWriter)1 Status (voldemort.utils.ConsistencyFix.Status)1