org.apache.bookkeeper.stats.OpStatsLogger Java Examples

The following examples show how to use org.apache.bookkeeper.stats.OpStatsLogger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BKLogHandler.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
protected List<LogSegmentMetadata> getLedgerList(boolean forceFetch,
                                                 boolean fetchFullList,
                                                 Comparator<LogSegmentMetadata> comparator,
                                                 boolean throwOnEmpty)
        throws IOException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    boolean success = false;
    try {
        List<LogSegmentMetadata> segments =
                doGetLedgerList(forceFetch, fetchFullList, comparator, throwOnEmpty);
        success = true;
        return segments;
    } finally {
        OpStatsLogger statsLogger = fetchFullList ? getFullListStat : getFilteredListStat;
        if (success) {
            statsLogger.registerSuccessfulEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
        } else {
            statsLogger.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
        }
    }
}
 
Example #2
Source File: LZ4CompressionCodec.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] decompress(byte[] data, int offset, int length, OpStatsLogger decompressionStat) {
    Preconditions.checkNotNull(data);
    Preconditions.checkArgument(offset >= 0 && offset < data.length);
    Preconditions.checkArgument(length >= 0);
    Preconditions.checkNotNull(decompressionStat);

    Stopwatch watch = Stopwatch.createStarted();
    // Assume that we have a compression ratio of 1/3.
    int outLength = length * 3;
    while (true) {
        try {
            byte[] decompressed = safeDecompressor.decompress(data, offset, length, outLength);
            decompressionStat.registerSuccessfulEvent(watch.elapsed(TimeUnit.MICROSECONDS));
            return decompressed;
        } catch (LZ4Exception e) {
            outLength *= 2;
        }
    }
}
 
Example #3
Source File: BKLogHandler.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
protected Future<List<LogSegmentMetadata>> asyncGetLedgerList(final boolean forceFetch,
                                                                    final boolean fetchFullList,
                                                                    final Comparator<LogSegmentMetadata> comparator,
                                                                    final boolean throwOnEmpty) {
    final Promise<List<LogSegmentMetadata>> promise = new Promise<List<LogSegmentMetadata>>();
    final Stopwatch stopwatch = Stopwatch.createStarted();
    final OpStatsLogger statsLogger = fetchFullList ? getFullListStat : getFilteredListStat;
    asyncDoGetLedgerList(forceFetch, fetchFullList, comparator, throwOnEmpty)
            .addEventListener(new FutureEventListener<List<LogSegmentMetadata>>() {
                @Override
                public void onSuccess(List<LogSegmentMetadata> value) {
                    statsLogger.registerSuccessfulEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
                    promise.setValue(value);
                }

                @Override
                public void onFailure(Throwable cause) {
                    statsLogger.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
                    promise.setException(cause);
                }
            });
    return promise;
}
 
Example #4
Source File: IdentityCompressionCodec.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
// Decompressed size is the same as the length of the data because this is an
// Identity compressor
public byte[] decompress(byte[] data, int offset, int length,
                         int decompressedSize, OpStatsLogger decompressionStat) {
    return decompress(data, offset, length, decompressionStat);
}
 
Example #5
Source File: AbstractStreamOp.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public AbstractStreamOp(String stream,
                        OpStatsLogger statsLogger,
                        Long checksum,
                        Feature checksumDisabledFeature) {
    this.stream = stream;
    this.opStatsLogger = statsLogger;
    // start here in case the operation is failed before executing.
    stopwatch.reset().start();
    this.checksum = checksum;
    this.checksumDisabledFeature = checksumDisabledFeature;
}
 
Example #6
Source File: OpStatsListener.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public OpStatsListener(OpStatsLogger opStatsLogger, Stopwatch stopwatch) {
    this.opStatsLogger = opStatsLogger;
    if (null == stopwatch) {
        this.stopwatch = Stopwatch.createStarted();
    } else {
        this.stopwatch = stopwatch;
    }
}
 
Example #7
Source File: OpStatsListener.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public OpStatsListener(OpStatsLogger opStatsLogger, Stopwatch stopwatch) {
    this.opStatsLogger = opStatsLogger;
    if (null == stopwatch) {
        this.stopwatch = Stopwatch.createStarted();
    } else {
        this.stopwatch = stopwatch;
    }
}
 
Example #8
Source File: TestFutureUtils.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Test
public void testStatsFailure() throws Exception {
    OpStatsLogger statsLogger = mock(OpStatsLogger.class);
    CompletableFuture<Long> underlyFuture = FutureUtils.createFuture();
    CompletableFuture<Long> statsFuture = FutureUtils.stats(
        underlyFuture,
        statsLogger,
        Stopwatch.createStarted());
    underlyFuture.completeExceptionally(new TestException());
    FutureUtils.result(FutureUtils.ignore(statsFuture));
    verify(statsLogger, times(1))
        .registerFailedEvent(anyLong(), eq(TimeUnit.MICROSECONDS));
}
 
Example #9
Source File: TestFutureUtils.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Test
public void testStatsSuccess() throws Exception {
    OpStatsLogger statsLogger = mock(OpStatsLogger.class);
    CompletableFuture<Long> underlyFuture = FutureUtils.createFuture();
    CompletableFuture<Long> statsFuture = FutureUtils.stats(
        underlyFuture,
        statsLogger,
        Stopwatch.createStarted());
    underlyFuture.complete(1234L);
    FutureUtils.result(statsFuture);
    verify(statsLogger, times(1))
        .registerSuccessfulEvent(anyLong(), eq(TimeUnit.MICROSECONDS));
}
 
Example #10
Source File: OpStatsListener.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public OpStatsListener(OpStatsLogger opStatsLogger, Stopwatch stopwatch) {
    this.opStatsLogger = opStatsLogger;
    if (null == stopwatch) {
        this.stopwatch = Stopwatch.createStarted();
    } else {
        this.stopwatch = stopwatch;
    }
}
 
Example #11
Source File: LZ4CompressionCodec.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] compress(byte[] data, int offset, int length, OpStatsLogger compressionStat) {
    Preconditions.checkNotNull(data);
    Preconditions.checkArgument(offset >= 0 && offset < data.length);
    Preconditions.checkArgument(length >= 0);
    Preconditions.checkNotNull(compressionStat);

    Stopwatch watch = Stopwatch.createStarted();
    byte[] compressed = compressor.compress(data, offset, length);
    compressionStat.registerSuccessfulEvent(watch.elapsed(TimeUnit.MICROSECONDS));
    return compressed;
}
 
Example #12
Source File: AbstractStreamOp.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public AbstractStreamOp(String stream,
                        OpStatsLogger statsLogger,
                        Long checksum,
                        Feature checksumDisabledFeature) {
    this.stream = stream;
    this.opStatsLogger = statsLogger;
    // start here in case the operation is failed before executing.
    stopwatch.reset().start();
    this.checksum = checksum;
    this.checksumDisabledFeature = checksumDisabledFeature;
}
 
Example #13
Source File: LZ4CompressionCodec.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
// length parameter is ignored here because of the way the fastDecompressor works.
public byte[] decompress(byte[] data, int offset, int length, int decompressedSize,
                         OpStatsLogger decompressionStat) {
    Preconditions.checkNotNull(data);
    Preconditions.checkArgument(offset >= 0 && offset < data.length);
    Preconditions.checkArgument(length >= 0);
    Preconditions.checkArgument(decompressedSize >= 0);
    Preconditions.checkNotNull(decompressionStat);

    Stopwatch watch = Stopwatch.createStarted();
    byte[] decompressed = fastDecompressor.decompress(data, offset, decompressedSize);
    decompressionStat.registerSuccessfulEvent(watch.elapsed(TimeUnit.MICROSECONDS));
    return decompressed;
}
 
Example #14
Source File: StreamAdminOp.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
protected StreamAdminOp(String stream,
                        StreamManager streamManager,
                        OpStatsLogger statsLogger,
                        Long checksum,
                        Feature checksumDisabledFeature) {
    this.stream = stream;
    this.streamManager = streamManager;
    this.opStatsLogger = statsLogger;
    // start here in case the operation is failed before executing.
    stopwatch.reset().start();
    this.checksum = checksum;
    this.checksumDisabledFeature = checksumDisabledFeature;
}
 
Example #15
Source File: StreamOpStats.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public OpStatsLogger requestLatencyStat(String opName) {
    return requestStatsLogger.getOpStatsLogger(opName);
}
 
Example #16
Source File: StreamOpStats.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public OpStatsLogger streamRequestLatencyStat(String streamName, String opName) {
    return streamRequestStatsLogger(streamName).getOpStatsLogger(opName);
}
 
Example #17
Source File: LedgerHandleCache.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
/**
 * Open the log segment.
 *
 * @param metadata
 *          the log segment metadata
 * @param fence
 *          whether to fence the log segment during open
 * @return a future presenting the open result.
 */
public Future<LedgerDescriptor> asyncOpenLedger(LogSegmentMetadata metadata, boolean fence) {
    final Stopwatch stopwatch = Stopwatch.createStarted();
    final OpStatsLogger openStatsLogger = fence ? openStats : openNoRecoveryStats;
    final Promise<LedgerDescriptor> promise = new Promise<LedgerDescriptor>();
    final LedgerDescriptor ledgerDesc = new LedgerDescriptor(metadata.getLedgerId(), metadata.getLogSegmentSequenceNumber(), fence);
    RefCountedLedgerHandle refhandle = handlesMap.get(ledgerDesc);
    if (null == refhandle) {
        asyncOpenLedger(ledgerDesc, new AsyncCallback.OpenCallback() {
            @Override
            public void openComplete(int rc, LedgerHandle lh, Object ctx) {
                if (BKException.Code.OK != rc) {
                    promise.setException(BKException.create(rc));
                    return;
                }
                RefCountedLedgerHandle newRefHandle = new RefCountedLedgerHandle(lh);
                RefCountedLedgerHandle oldRefHandle = handlesMap.putIfAbsent(ledgerDesc, newRefHandle);
                if (null != oldRefHandle) {
                    oldRefHandle.addRef();
                    if (newRefHandle.removeRef()) {
                        newRefHandle.handle.asyncClose(new AsyncCallback.CloseCallback() {
                            @Override
                            public void closeComplete(int i, LedgerHandle ledgerHandle, Object o) {
                                // No action necessary
                            }
                        }, null);
                    }
                }
                promise.setValue(ledgerDesc);
            }
        }, null);
    } else {
        refhandle.addRef();
        promise.setValue(ledgerDesc);
    }
    return promise.addEventListener(new FutureEventListener<LedgerDescriptor>() {
        @Override
        public void onSuccess(LedgerDescriptor value) {
            openStatsLogger.registerSuccessfulEvent(stopwatch.elapsed(TimeUnit.MICROSECONDS));
        }

        @Override
        public void onFailure(Throwable cause) {
            openStatsLogger.registerFailedEvent(stopwatch.elapsed(TimeUnit.MICROSECONDS));
        }
    });
}
 
Example #18
Source File: AbstractStreamOp.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
protected static OpStatsLogger requestStat(StatsLogger statsLogger, String opName) {
    return requestLogger(statsLogger).getOpStatsLogger(opName);
}
 
Example #19
Source File: IdentityCompressionCodec.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] compress(byte[] data, int offset, int length, OpStatsLogger compressionStat) {
    Preconditions.checkNotNull(data);
    Preconditions.checkArgument(length >= 0);
    return Arrays.copyOfRange(data, offset, offset + length);
}
 
Example #20
Source File: IdentityCompressionCodec.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] decompress(byte[] data, int offset, int length, OpStatsLogger decompressionStat) {
    Preconditions.checkNotNull(data);
    return Arrays.copyOfRange(data, offset, offset + length);
}
 
Example #21
Source File: PrometheusStatsLogger.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Override
public OpStatsLogger getOpStatsLogger(String name) {
    return provider.opStats.computeIfAbsent(completeName(name), x -> new DataSketchesOpStatsLogger());
}
 
Example #22
Source File: AbstractWriteOp.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
protected AbstractWriteOp(String stream,
                          OpStatsLogger statsLogger,
                          Long checksum,
                          Feature checksumDisabledFeature) {
    super(stream, statsLogger, checksum, checksumDisabledFeature);
}
 
Example #23
Source File: OpStatsLoggerAdaptor.java    From openmessaging-benchmark with Apache License 2.0 4 votes vote down vote up
OpStatsLoggerAdaptor(OpStatsLogger statsLogger) {
    this.statsLogger = statsLogger;
}
 
Example #24
Source File: OpStatsListener.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public OpStatsListener(OpStatsLogger opStatsLogger) {
    this(opStatsLogger, null);
}
 
Example #25
Source File: OpStatsListener.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public OpStatsListener(OpStatsLogger opStatsLogger) {
    this(opStatsLogger, null);
}
 
Example #26
Source File: OpStatsListener.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public OpStatsListener(OpStatsLogger opStatsLogger) {
    this(opStatsLogger, null);
}
 
Example #27
Source File: AbstractStreamOp.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public static OpStatsLogger requestStat(StatsLogger statsLogger, String opName) {
    return requestLogger(statsLogger).getOpStatsLogger(opName);
}
 
Example #28
Source File: StreamOpStats.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public OpStatsLogger streamRequestLatencyStat(Partition partition, String opName) {
    return streamRequestStatsLogger(partition).getOpStatsLogger(opName);
}
 
Example #29
Source File: StreamOpStats.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public OpStatsLogger requestLatencyStat(String opName) {
    return requestStatsLogger.getOpStatsLogger(opName);
}
 
Example #30
Source File: AbstractWriteOp.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
protected AbstractWriteOp(String stream,
                          OpStatsLogger statsLogger,
                          Long checksum,
                          Feature checksumDisabledFeature) {
    super(stream, statsLogger, checksum, checksumDisabledFeature);
}