use of com.twitter.distributedlog.service.stream.WriteOp in project distributedlog by twitter.
the class DistributedLogServiceImpl method doWrite.
private Future<WriteResponse> doWrite(final String name, ByteBuffer data, Long checksum, boolean isRecordSet) {
writePendingStat.inc();
receivedRecordCounter.inc();
WriteOp op = newWriteOp(name, data, checksum, isRecordSet);
executeStreamOp(op);
return op.result().ensure(new Function0<BoxedUnit>() {
public BoxedUnit apply() {
writePendingStat.dec();
return null;
}
});
}
use of com.twitter.distributedlog.service.stream.WriteOp in project distributedlog by twitter.
the class TestDistributedLogService method testAcquireStreams.
@Test(timeout = 60000)
public void testAcquireStreams() throws Exception {
String streamName = testName.getMethodName();
StreamImpl s0 = createUnstartedStream(service, streamName);
s0.suspendAcquiring();
DistributedLogServiceImpl service1 = createService(serverConf, dlConf);
StreamImpl s1 = createUnstartedStream(service1, streamName);
s1.suspendAcquiring();
// create write ops
WriteOp op0 = createWriteOp(service, streamName, 0L);
s0.submit(op0);
WriteOp op1 = createWriteOp(service1, streamName, 1L);
s1.submit(op1);
// check pending size
assertEquals("Write Op 0 should be pending in service 0", 1, s0.numPendingOps());
assertEquals("Write Op 1 should be pending in service 1", 1, s1.numPendingOps());
// start acquiring s0
s0.resumeAcquiring().start();
WriteResponse wr0 = Await.result(op0.result());
assertEquals("Op 0 should succeed", StatusCode.SUCCESS, wr0.getHeader().getCode());
assertEquals("Service 0 should acquire stream", StreamStatus.INITIALIZED, s0.getStatus());
assertNotNull(s0.getManager());
assertNotNull(s0.getWriter());
assertNull(s0.getLastException());
// start acquiring s1
s1.resumeAcquiring().start();
WriteResponse wr1 = Await.result(op1.result());
assertEquals("Op 1 should fail", StatusCode.FOUND, wr1.getHeader().getCode());
assertEquals("Service 1 should be in BACKOFF state", StreamStatus.BACKOFF, s1.getStatus());
assertNotNull(s1.getManager());
assertNull(s1.getWriter());
assertNotNull(s1.getLastException());
assertTrue(s1.getLastException() instanceof OwnershipAcquireFailedException);
service1.shutdown();
}
use of com.twitter.distributedlog.service.stream.WriteOp in project distributedlog by twitter.
the class TestDistributedLogService method testStreamOpBadChecksumWithChecksumDisabled.
@Test(timeout = 60000)
public void testStreamOpBadChecksumWithChecksumDisabled() throws Exception {
String streamName = testName.getMethodName();
SettableFeature disabledFeature = new SettableFeature("", 0);
WriteOp writeOp0 = getWriteOp(streamName, disabledFeature, 919191L);
WriteOp writeOp1 = getWriteOp(streamName, disabledFeature, 919191L);
try {
writeOp0.preExecute();
fail("should have thrown");
} catch (Exception ex) {
}
disabledFeature.set(1);
writeOp1.preExecute();
}
use of com.twitter.distributedlog.service.stream.WriteOp in project distributedlog by twitter.
the class TestDistributedLogService method testAcquireStreamsWhenExceedMaxCachedPartitions.
@Test(timeout = 60000)
public void testAcquireStreamsWhenExceedMaxCachedPartitions() throws Exception {
String streamName = testName.getMethodName() + "_0000";
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(dlConf);
confLocal.setMaxCachedPartitionsPerProxy(1);
ServerConfiguration serverConfLocal = new ServerConfiguration();
serverConfLocal.addConfiguration(serverConf);
serverConfLocal.setStreamPartitionConverterClass(DelimiterStreamPartitionConverter.class);
DistributedLogServiceImpl serviceLocal = createService(serverConfLocal, confLocal);
Stream stream = serviceLocal.getLogWriter(streamName);
// stream is cached
assertNotNull(stream);
assertEquals(1, serviceLocal.getStreamManager().numCached());
// create write ops
WriteOp op0 = createWriteOp(service, streamName, 0L);
stream.submit(op0);
WriteResponse wr0 = Await.result(op0.result());
assertEquals("Op 0 should succeed", StatusCode.SUCCESS, wr0.getHeader().getCode());
assertEquals(1, serviceLocal.getStreamManager().numAcquired());
// should fail to acquire another partition
try {
serviceLocal.getLogWriter(testName.getMethodName() + "_0001");
fail("Should fail to acquire new streams");
} catch (StreamUnavailableException sue) {
// expected
}
assertEquals(1, serviceLocal.getStreamManager().numCached());
assertEquals(1, serviceLocal.getStreamManager().numAcquired());
// should be able to acquire partitions from other streams
String anotherStreamName = testName.getMethodName() + "-another_0001";
Stream anotherStream = serviceLocal.getLogWriter(anotherStreamName);
assertNotNull(anotherStream);
assertEquals(2, serviceLocal.getStreamManager().numCached());
// create write ops
WriteOp op1 = createWriteOp(service, anotherStreamName, 0L);
anotherStream.submit(op1);
WriteResponse wr1 = Await.result(op1.result());
assertEquals("Op 1 should succeed", StatusCode.SUCCESS, wr1.getHeader().getCode());
assertEquals(2, serviceLocal.getStreamManager().numAcquired());
}
use of com.twitter.distributedlog.service.stream.WriteOp in project distributedlog by twitter.
the class TestDistributedLogService method testStreamOpGoodChecksumWithChecksumDisabled.
@Test(timeout = 60000)
public void testStreamOpGoodChecksumWithChecksumDisabled() throws Exception {
String streamName = testName.getMethodName();
SettableFeature disabledFeature = new SettableFeature("", 1);
WriteOp writeOp0 = getWriteOp(streamName, disabledFeature, ProtocolUtils.writeOpCRC32(streamName, "test".getBytes()));
WriteOp writeOp1 = getWriteOp(streamName, disabledFeature, ProtocolUtils.writeOpCRC32(streamName, "test".getBytes()));
writeOp0.preExecute();
disabledFeature.set(0);
writeOp1.preExecute();
}
Aggregations