Search in sources :

Example 26 with DLSN

use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.

the class ConsoleProxyMultiWriter method main.

public static void main(String[] args) throws Exception {
    if (2 != args.length) {
        System.out.println(HELP);
        return;
    }
    String finagleNameStr = args[0];
    final String streamList = args[1];
    DistributedLogClient client = DistributedLogClientBuilder.newBuilder().clientId(ClientId$.MODULE$.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true).finagleNameStr(finagleNameStr).build();
    String[] streamNameList = StringUtils.split(streamList, ',');
    DistributedLogMultiStreamWriter multiStreamWriter = DistributedLogMultiStreamWriter.newBuilder().streams(Lists.newArrayList(streamNameList)).bufferSize(0).client(client).flushIntervalMs(0).firstSpeculativeTimeoutMs(10000).maxSpeculativeTimeoutMs(20000).requestTimeoutMs(50000).build();
    ConsoleReader reader = new ConsoleReader();
    String line;
    while ((line = reader.readLine(PROMPT_MESSAGE)) != null) {
        multiStreamWriter.write(ByteBuffer.wrap(line.getBytes(UTF_8))).addEventListener(new FutureEventListener<DLSN>() {

            @Override
            public void onFailure(Throwable cause) {
                System.out.println("Encountered error on writing data");
                cause.printStackTrace(System.err);
                Runtime.getRuntime().exit(0);
            }

            @Override
            public void onSuccess(DLSN value) {
            // done
            }
        });
    }
    multiStreamWriter.close();
    client.close();
}
Also used : DLSN(com.twitter.distributedlog.DLSN) ConsoleReader(jline.ConsoleReader) DistributedLogMultiStreamWriter(com.twitter.distributedlog.client.DistributedLogMultiStreamWriter) DistributedLogClient(com.twitter.distributedlog.service.DistributedLogClient)

Example 27 with DLSN

use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.

the class RecordGenerator method main.

public static void main(String[] args) throws Exception {
    if (3 != args.length) {
        System.out.println(HELP);
        return;
    }
    String finagleNameStr = args[0];
    final String streamName = args[1];
    double rate = Double.parseDouble(args[2]);
    RateLimiter limiter = RateLimiter.create(rate);
    DistributedLogClient client = DistributedLogClientBuilder.newBuilder().clientId(ClientId$.MODULE$.apply("record-generator")).name("record-generator").thriftmux(true).finagleNameStr(finagleNameStr).build();
    final CountDownLatch keepAliveLatch = new CountDownLatch(1);
    final AtomicLong numWrites = new AtomicLong(0);
    final AtomicBoolean running = new AtomicBoolean(true);
    while (running.get()) {
        limiter.acquire();
        String record = "record-" + System.currentTimeMillis();
        client.write(streamName, ByteBuffer.wrap(record.getBytes(UTF_8))).addEventListener(new FutureEventListener<DLSN>() {

            @Override
            public void onFailure(Throwable cause) {
                System.out.println("Encountered error on writing data");
                cause.printStackTrace(System.err);
                running.set(false);
                keepAliveLatch.countDown();
            }

            @Override
            public void onSuccess(DLSN value) {
                long numSuccesses = numWrites.incrementAndGet();
                if (numSuccesses % 100 == 0) {
                    System.out.println("Write " + numSuccesses + " records.");
                }
            }
        });
    }
    keepAliveLatch.await();
    client.close();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) DLSN(com.twitter.distributedlog.DLSN) CountDownLatch(java.util.concurrent.CountDownLatch) RateLimiter(com.google.common.util.concurrent.RateLimiter) DistributedLogClient(com.twitter.distributedlog.service.DistributedLogClient)

Example 28 with DLSN

use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.

the class TestDistributedLogServer method validateFailedAsLogRecordTooLong.

void validateFailedAsLogRecordTooLong(Future<DLSN> future) {
    try {
        DLSN dlsn = Await.result(future, Duration.fromSeconds(10));
        fail("should have failed");
    } catch (DLException dle) {
        assertEquals(StatusCode.TOO_LARGE_RECORD, dle.getCode());
    } catch (Exception ex) {
        failDueToWrongException(ex);
    }
}
Also used : DLSN(com.twitter.distributedlog.DLSN) LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) DLException(com.twitter.distributedlog.exceptions.DLException) DLException(com.twitter.distributedlog.exceptions.DLException) NoBrokersAvailableException(com.twitter.finagle.NoBrokersAvailableException) LogNotFoundException(com.twitter.distributedlog.exceptions.LogNotFoundException)

Example 29 with DLSN

use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.

the class TestDistributedLogServer method testHeartbeat.

@Test(timeout = 60000)
public void testHeartbeat() throws Exception {
    String name = "dlserver-heartbeat";
    dlClient.routingService.addHost(name, dlServer.getAddress());
    for (long i = 1; i <= 10; i++) {
        logger.debug("Send heartbeat {} to stream {}.", i, name);
        dlClient.dlClient.check(name).get();
    }
    logger.debug("Write entry one to stream {}.", name);
    dlClient.dlClient.write(name, ByteBuffer.wrap("1".getBytes())).get();
    Thread.sleep(1000);
    DistributedLogManager dlm = DLMTestUtil.createNewDLM(name, conf, getUri());
    LogReader reader = dlm.getInputStream(DLSN.InitialDLSN);
    int numRead = 0;
    // eid=0 => control records
    // other 9 heartbeats will not trigger writing any control records.
    // eid=1 => user entry
    long startEntryId = 1;
    LogRecordWithDLSN r = reader.readNext(false);
    while (null != r) {
        int i = Integer.parseInt(new String(r.getPayload()));
        assertEquals(numRead + 1, i);
        assertEquals(r.getDlsn().compareTo(new DLSN(1, startEntryId, 0)), 0);
        ++numRead;
        ++startEntryId;
        r = reader.readNext(false);
    }
    assertEquals(1, numRead);
}
Also used : LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) DLSN(com.twitter.distributedlog.DLSN) LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) AsyncLogReader(com.twitter.distributedlog.AsyncLogReader) LogReader(com.twitter.distributedlog.LogReader) Test(org.junit.Test)

Example 30 with DLSN

use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.

the class TestDistributedLogServer method validateAllFailedAsCancelled.

int validateAllFailedAsCancelled(List<Future<DLSN>> futures, int start, int finish) {
    int failed = 0;
    for (int i = start; i < finish; i++) {
        Future<DLSN> future = futures.get(i);
        try {
            DLSN dlsn = Await.result(future, Duration.fromSeconds(10));
            fail("future should have failed!");
        } catch (DLException cre) {
            ++failed;
        } catch (Exception ex) {
            failDueToWrongException(ex);
        }
    }
    return failed;
}
Also used : DLSN(com.twitter.distributedlog.DLSN) LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) DLException(com.twitter.distributedlog.exceptions.DLException) DLException(com.twitter.distributedlog.exceptions.DLException) NoBrokersAvailableException(com.twitter.finagle.NoBrokersAvailableException) LogNotFoundException(com.twitter.distributedlog.exceptions.LogNotFoundException)

Aggregations

DLSN (com.twitter.distributedlog.DLSN)36 Test (org.junit.Test)21 LogRecordWithDLSN (com.twitter.distributedlog.LogRecordWithDLSN)14 DistributedLogClient (com.twitter.distributedlog.service.DistributedLogClient)11 ByteBuffer (java.nio.ByteBuffer)10 DistributedLogManager (com.twitter.distributedlog.DistributedLogManager)8 AsyncLogReader (com.twitter.distributedlog.AsyncLogReader)6 LogRecord (com.twitter.distributedlog.LogRecord)6 LogReader (com.twitter.distributedlog.LogReader)5 WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)5 Future (com.twitter.util.Future)5 DLException (com.twitter.distributedlog.exceptions.DLException)4 LogNotFoundException (com.twitter.distributedlog.exceptions.LogNotFoundException)4 ArrayList (java.util.ArrayList)4 LogSegmentMetadata (com.twitter.distributedlog.LogSegmentMetadata)3 NoBrokersAvailableException (com.twitter.finagle.NoBrokersAvailableException)3 Promise (com.twitter.util.Promise)3 IOException (java.io.IOException)3 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)2 LogRecordSet (com.twitter.distributedlog.LogRecordSet)2