Search in sources :

Example 1 with WriteOp

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;
        }
    });
}
Also used : WriteOp(com.twitter.distributedlog.service.stream.WriteOp) BulkWriteOp(com.twitter.distributedlog.service.stream.BulkWriteOp) BoxedUnit(scala.runtime.BoxedUnit)

Example 2 with WriteOp

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();
}
Also used : OwnershipAcquireFailedException(com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException) WriteOp(com.twitter.distributedlog.service.stream.WriteOp) StreamImpl(com.twitter.distributedlog.service.stream.StreamImpl) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) Test(org.junit.Test)

Example 3 with WriteOp

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();
}
Also used : WriteOp(com.twitter.distributedlog.service.stream.WriteOp) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) StreamUnavailableException(com.twitter.distributedlog.exceptions.StreamUnavailableException) OwnershipAcquireFailedException(com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) Test(org.junit.Test)

Example 4 with WriteOp

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());
}
Also used : StreamUnavailableException(com.twitter.distributedlog.exceptions.StreamUnavailableException) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) WriteOp(com.twitter.distributedlog.service.stream.WriteOp) ServerConfiguration(com.twitter.distributedlog.service.config.ServerConfiguration) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) Stream(com.twitter.distributedlog.service.stream.Stream) Test(org.junit.Test)

Example 5 with WriteOp

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();
}
Also used : WriteOp(com.twitter.distributedlog.service.stream.WriteOp) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Aggregations

WriteOp (com.twitter.distributedlog.service.stream.WriteOp)11 Test (org.junit.Test)10 WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)8 StreamImpl (com.twitter.distributedlog.service.stream.StreamImpl)4 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)2 InternalServerException (com.twitter.distributedlog.exceptions.InternalServerException)2 OwnershipAcquireFailedException (com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException)2 StreamUnavailableException (com.twitter.distributedlog.exceptions.StreamUnavailableException)2 ServerConfiguration (com.twitter.distributedlog.service.config.ServerConfiguration)2 Stream (com.twitter.distributedlog.service.stream.Stream)2 Future (com.twitter.util.Future)2 ArrayList (java.util.ArrayList)2 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)2 AsyncLogWriter (com.twitter.distributedlog.AsyncLogWriter)1 DLSN (com.twitter.distributedlog.DLSN)1 BulkWriteOp (com.twitter.distributedlog.service.stream.BulkWriteOp)1 Sequencer (com.twitter.distributedlog.util.Sequencer)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 BoxedUnit (scala.runtime.BoxedUnit)1