use of com.twitter.distributedlog.thrift.service.BulkWriteResponse in project distributedlog by twitter.
the class TestDistributedLogServer method testBulkWriteTotalFailureLostLock.
@Test(timeout = 60000)
public void testBulkWriteTotalFailureLostLock() throws Exception {
String name = String.format("dlserver-bulk-write-%s", "lost-lock");
dlClient.routingService.addHost(name, dlServer.getAddress());
final int writeCount = 8;
List<ByteBuffer> writes = new ArrayList<ByteBuffer>(writeCount + 1);
ByteBuffer buf = ByteBuffer.allocate(8);
writes.add(buf);
for (long i = 1; i <= writeCount; i++) {
writes.add(ByteBuffer.wrap(("" + i).getBytes()));
}
// Warm it up with a write.
Await.result(dlClient.dlClient.write(name, ByteBuffer.allocate(8)));
// Failpoint a lost lock, make sure the failure gets promoted to an operation failure.
DistributedLogServiceImpl svcImpl = (DistributedLogServiceImpl) dlServer.dlServer.getLeft();
try {
FailpointUtils.setFailpoint(FailpointUtils.FailPointName.FP_WriteInternalLostLock, FailpointUtils.FailPointActions.FailPointAction_Default);
Future<BulkWriteResponse> futures = svcImpl.writeBulkWithContext(name, writes, new WriteContext());
assertEquals(StatusCode.LOCKING_EXCEPTION, Await.result(futures).header.code);
} finally {
FailpointUtils.removeFailpoint(FailpointUtils.FailPointName.FP_WriteInternalLostLock);
}
}
use of com.twitter.distributedlog.thrift.service.BulkWriteResponse in project distributedlog by twitter.
the class BulkWriteOp method executeOp.
@Override
protected Future<BulkWriteResponse> executeOp(AsyncLogWriter writer, Sequencer sequencer, Object txnLock) {
// Need to convert input buffers to LogRecords.
List<LogRecord> records;
Future<List<Future<DLSN>>> futureList;
synchronized (txnLock) {
records = asRecordList(buffers, sequencer);
futureList = writer.writeBulk(records);
}
// Collect into a list of tries to make it easier to extract exception or DLSN.
Future<List<Try<DLSN>>> writes = asTryList(futureList);
Future<BulkWriteResponse> response = writes.flatMap(new AbstractFunction1<List<Try<DLSN>>, Future<BulkWriteResponse>>() {
@Override
public Future<BulkWriteResponse> apply(List<Try<DLSN>> results) {
// Considered a success at batch level even if no individual writes succeeed.
// The reason is that its impossible to make an appropriate decision re retries without
// individual buffer failure reasons.
List<WriteResponse> writeResponses = new ArrayList<WriteResponse>(results.size());
BulkWriteResponse bulkWriteResponse = ResponseUtils.bulkWriteSuccess().setWriteResponses(writeResponses);
// failed.
if (results.size() > 0) {
Try<DLSN> firstResult = results.get(0);
if (isDefiniteFailure(firstResult)) {
return new ConstFuture(firstResult);
}
}
// Translate all futures to write responses.
Iterator<Try<DLSN>> iterator = results.iterator();
while (iterator.hasNext()) {
Try<DLSN> completedFuture = iterator.next();
try {
DLSN dlsn = completedFuture.get();
WriteResponse writeResponse = ResponseUtils.writeSuccess().setDlsn(dlsn.serialize());
writeResponses.add(writeResponse);
successRecordCounter.inc();
} catch (Exception ioe) {
WriteResponse writeResponse = ResponseUtils.write(ResponseUtils.exceptionToHeader(ioe));
writeResponses.add(writeResponse);
if (StatusCode.FOUND == writeResponse.getHeader().getCode()) {
redirectRecordCounter.inc();
} else {
failureRecordCounter.inc();
}
}
}
return Future.value(bulkWriteResponse);
}
});
return response;
}
Aggregations