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);
}
}
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);
}
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());
}
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");
}
}
Aggregations