Java Code Examples for org.apache.bookkeeper.stats.StatsLogger#scope()

The following examples show how to use org.apache.bookkeeper.stats.StatsLogger#scope() . 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: ZKDistributedLock.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public ZKDistributedLock(
        OrderedScheduler lockStateExecutor,
        SessionLockFactory lockFactory,
        String lockPath,
        long lockTimeout,
        StatsLogger statsLogger) {
    this.lockStateExecutor = lockStateExecutor;
    this.lockPath = lockPath;
    this.lockTimeout = lockTimeout;
    this.lockFactory = lockFactory;

    lockStatsLogger = statsLogger.scope("lock");
    acquireStats = lockStatsLogger.getOpStatsLogger("acquire");
    reacquireStats = lockStatsLogger.getOpStatsLogger("reacquire");
    internalTryRetries = lockStatsLogger.getCounter("internalTryRetries");
}
 
Example 2
Source File: FileDataStorageManager.java    From herddb with Apache License 2.0 6 votes vote down vote up
public FileDataStorageManager(
        Path baseDirectory, Path tmpDirectory, int swapThreshold,
        boolean requirefsync, boolean pageodirect, boolean indexodirect,
        boolean hashChecksEnabled, boolean hashWritesEnabled, StatsLogger logger
) {
    this.baseDirectory = baseDirectory;
    this.tmpDirectory = tmpDirectory;
    this.swapThreshold = swapThreshold;
    this.logger = logger;
    this.requirefsync = requirefsync;
    this.pageodirect = pageodirect && OpenFileUtils.isO_DIRECT_Supported();
    this.indexodirect = indexodirect && OpenFileUtils.isO_DIRECT_Supported();
    this.hashChecksEnabled = hashChecksEnabled;
    this.hashWritesEnabled = hashWritesEnabled;
    StatsLogger scope = logger.scope("filedatastore");
    this.dataPageReads = scope.getOpStatsLogger("data_pagereads");
    this.dataPageWrites = scope.getOpStatsLogger("data_pagewrites");
    this.indexPageReads = scope.getOpStatsLogger("index_pagereads");
    this.indexPageWrites = scope.getOpStatsLogger("index_pagewrites");
}
 
Example 3
Source File: BKAsyncLogWriter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
BKAsyncLogWriter(DistributedLogConfiguration conf,
                 DynamicDistributedLogConfiguration dynConf,
                 BKDistributedLogManager bkdlm,
                 BKLogWriteHandler writeHandler, /** log writer owns the handler **/
                 FeatureProvider featureProvider,
                 StatsLogger dlmStatsLogger) {
    super(conf, dynConf, bkdlm);
    this.writeHandler = writeHandler;
    this.streamFailFast = conf.getFailFastOnStreamNotReady();
    this.disableRollOnSegmentError = conf.getDisableRollingOnLogSegmentError();

    // features
    disableLogSegmentRollingFeature = featureProvider
            .getFeature(CoreFeatureKeys.DISABLE_LOGSEGMENT_ROLLING.name().toLowerCase());
    // stats
    this.statsLogger = dlmStatsLogger.scope("log_writer");
    this.writeOpStatsLogger = statsLogger.getOpStatsLogger("write");
    this.markEndOfStreamOpStatsLogger = statsLogger.getOpStatsLogger("mark_end_of_stream");
    this.bulkWriteOpStatsLogger = statsLogger.getOpStatsLogger("bulk_write");
    this.getWriterOpStatsLogger = statsLogger.getOpStatsLogger("get_writer");
    this.pendingRequestDispatch = statsLogger.getCounter("pending_request_dispatch");
}
 
Example 4
Source File: ZKSessionLockFactory.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public ZKSessionLockFactory(ZooKeeperClient zkc,
                            String clientId,
                            OrderedScheduler lockStateExecutor,
                            int lockCreationRetries,
                            long lockOpTimeout,
                            long zkRetryBackoffMs,
                            StatsLogger statsLogger) {
    this.zkc = zkc;
    this.clientId = clientId;
    this.lockStateExecutor = lockStateExecutor;
    this.lockCreationRetries = lockCreationRetries;
    this.lockOpTimeout = lockOpTimeout;
    this.zkRetryBackoffMs = zkRetryBackoffMs;

    this.lockStatsLogger = statsLogger.scope("lock");
}
 
Example 5
Source File: DynamicRequestLimiter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public DynamicRequestLimiter(DynamicDistributedLogConfiguration dynConf,
                             StatsLogger statsLogger,
                             Feature rateLimitDisabledFeature) {
    final StatsLogger limiterStatsLogger = statsLogger.scope("dynamic");
    this.dynConf = dynConf;
    this.rateLimitDisabledFeature = rateLimitDisabledFeature;
    this.listener = new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            // Note that this method may be called several times if several config options
            // are changed. The effect is harmless except that we create and discard more
            // objects than we need to.
            LOG.debug("Config changed callback invoked with event {} {} {} {}", new Object[] {
                    event.getPropertyName(), event.getPropertyValue(), event.getType(),
                    event.isBeforeUpdate()});
            if (!event.isBeforeUpdate()) {
                limiterStatsLogger.getCounter("config_changed").inc();
                LOG.debug("Rebuilding limiter");
                limiter = build();
            }
        }
    };
    LOG.debug("Registering config changed callback");
    dynConf.addConfigurationListener(listener);
}
 
Example 6
Source File: ZKDistributedLock.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public ZKDistributedLock(
        OrderedScheduler lockStateExecutor,
        SessionLockFactory lockFactory,
        String lockPath,
        long lockTimeout,
        StatsLogger statsLogger) {
    this.lockStateExecutor = lockStateExecutor;
    this.lockPath = lockPath;
    this.lockTimeout = lockTimeout;
    this.lockFactory = lockFactory;

    lockStatsLogger = statsLogger.scope("lock");
    acquireStats = lockStatsLogger.getOpStatsLogger("acquire");
    reacquireStats = lockStatsLogger.getOpStatsLogger("reacquire");
    internalTryRetries = lockStatsLogger.getCounter("internalTryRetries");
}
 
Example 7
Source File: BKSyncLogReader.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
BKSyncLogReader(DistributedLogConfiguration conf,
                BKDistributedLogManager bkdlm,
                DLSN startDLSN,
                Optional<Long> startTransactionId,
                StatsLogger statsLogger) throws IOException {
    this.bkdlm = bkdlm;
    this.readHandler = bkdlm.createReadHandler(
            Optional.<String>absent(),
            this,
            true);
    this.maxReadAheadWaitTime = conf.getReadAheadWaitTime();
    this.idleErrorThresholdMillis = conf.getReaderIdleErrorThresholdMillis();
    this.shouldCheckIdleReader = idleErrorThresholdMillis > 0 && idleErrorThresholdMillis < Integer.MAX_VALUE;
    this.startTransactionId = startTransactionId;

    // start readahead
    startReadAhead(startDLSN);
    if (!startTransactionId.isPresent()) {
        positioned = true;
    }

    // Stats
    StatsLogger syncReaderStatsLogger = statsLogger.scope("sync_reader");
    idleReaderError = syncReaderStatsLogger.getCounter("idle_reader_error");
}
 
Example 8
Source File: NamespaceBuilder.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static StatsLogger normalizePerLogStatsLogger(StatsLogger statsLogger,
                                                      StatsLogger perLogStatsLogger,
                                                      DistributedLogConfiguration conf) {
    StatsLogger normalizedPerLogStatsLogger = perLogStatsLogger;
    if (perLogStatsLogger == NullStatsLogger.INSTANCE
            && conf.getEnablePerStreamStat()) {
        normalizedPerLogStatsLogger = statsLogger.scope("stream");
    }
    return normalizedPerLogStatsLogger;
}
 
Example 9
Source File: DistributedLogNamespaceBuilder.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static StatsLogger normalizePerLogStatsLogger(StatsLogger statsLogger,
                                                      StatsLogger perLogStatsLogger,
                                                      DistributedLogConfiguration conf) {
    StatsLogger normalizedPerLogStatsLogger = perLogStatsLogger;
    if (perLogStatsLogger == NullStatsLogger.INSTANCE
        && conf.getEnablePerStreamStat()) {
        normalizedPerLogStatsLogger = statsLogger.scope("stream");
    }
    return normalizedPerLogStatsLogger;
}
 
Example 10
Source File: ReadAheadCache.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public ReadAheadCache(String streamName,
                      StatsLogger statsLogger,
                      AlertStatsLogger alertStatsLogger,
                      AsyncNotification notification,
                      int maxCachedRecords,
                      boolean deserializeRecordSet,
                      boolean traceDeliveryLatencyEnabled,
                      long deliveryLatencyWarnThresholdMillis,
                      Ticker ticker) {
    this.streamName = streamName;
    this.maxCachedRecords = maxCachedRecords;
    this.notification = notification;
    this.deserializeRecordSet = deserializeRecordSet;

    // create the readahead queue
    readAheadRecords = new LinkedBlockingQueue<LogRecordWithDLSN>();

    // start the idle reader detection
    lastEntryProcessTime = Stopwatch.createStarted(ticker);

    // Flags to control delivery latency tracing
    this.traceDeliveryLatencyEnabled = traceDeliveryLatencyEnabled;
    this.deliveryLatencyWarnThresholdMillis = deliveryLatencyWarnThresholdMillis;
    // Stats
    StatsLogger readAheadStatsLogger = statsLogger.scope("readahead");
    this.statsLogger = readAheadStatsLogger;
    this.alertStatsLogger = alertStatsLogger;
    this.readAheadDeliveryLatencyStat =
            readAheadStatsLogger.getOpStatsLogger("delivery_latency");
    this.negativeReadAheadDeliveryLatencyStat =
            readAheadStatsLogger.getOpStatsLogger("negative_delivery_latency");
}
 
Example 11
Source File: BKAsyncLogReader.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
BKAsyncLogReader(BKDistributedLogManager bkdlm,
                 OrderedScheduler scheduler,
                 DLSN startDLSN,
                 Optional<String> subscriberId,
                 boolean returnEndOfStreamRecord,
                 StatsLogger statsLogger) {
    this.streamName = bkdlm.getStreamName();
    this.bkDistributedLogManager = bkdlm;
    this.scheduler = scheduler;
    this.readHandler = bkDistributedLogManager.createReadHandler(subscriberId,
            this, true);
    LOG.debug("Starting async reader at {}", startDLSN);
    this.startDLSN = startDLSN;
    this.scheduleDelayStopwatch = Stopwatch.createUnstarted();
    this.readNextDelayStopwatch = Stopwatch.createStarted();
    this.positionGapDetectionEnabled = bkdlm.getConf().getPositionGapDetectionEnabled();
    this.idleErrorThresholdMillis = bkdlm.getConf().getReaderIdleErrorThresholdMillis();
    this.returnEndOfStreamRecord = returnEndOfStreamRecord;

    // Stats
    StatsLogger asyncReaderStatsLogger = statsLogger.scope("async_reader");
    futureSetLatency = asyncReaderStatsLogger.getOpStatsLogger("future_set");
    scheduleLatency = asyncReaderStatsLogger.getOpStatsLogger("schedule");
    backgroundReaderRunTime = asyncReaderStatsLogger.getOpStatsLogger("background_read");
    readNextExecTime = asyncReaderStatsLogger.getOpStatsLogger("read_next_exec");
    timeBetweenReadNexts = asyncReaderStatsLogger.getOpStatsLogger("time_between_read_next");
    delayUntilPromiseSatisfied = asyncReaderStatsLogger.getOpStatsLogger("delay_until_promise_satisfied");
    idleReaderError = asyncReaderStatsLogger.getCounter("idle_reader_error");
    idleReaderCheckCount = asyncReaderStatsLogger.getCounter("idle_reader_check_total");
    idleReaderCheckIdleReadRequestCount = asyncReaderStatsLogger.getCounter("idle_reader_check_idle_read_requests");
    idleReaderCheckIdleReadAheadCount = asyncReaderStatsLogger.getCounter("idle_reader_check_idle_readahead");

    // Lock the stream if requested. The lock will be released when the reader is closed.
    this.lockStream = false;
    this.idleReaderTimeoutTask = scheduleIdleReaderTaskIfNecessary();
    this.lastProcessTime = Stopwatch.createStarted();
}
 
Example 12
Source File: StreamOpStats.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public StreamOpStats(StatsLogger statsLogger,
                     StatsLogger perStreamStatsLogger) {
    this.baseStatsLogger = statsLogger;
    this.requestStatsLogger = statsLogger.scope("request");
    this.recordsStatsLogger = statsLogger.scope("records");
    this.requestDeniedStatsLogger = statsLogger.scope("denied");
    this.streamStatsLogger = perStreamStatsLogger;
}
 
Example 13
Source File: HDBClient.java    From herddb with Apache License 2.0 5 votes vote down vote up
public HDBClient(ClientConfiguration configuration, StatsLogger statsLogger) {
    this.configuration = configuration;
    this.statsLogger = statsLogger.scope("hdbclient");

    int corePoolSize = configuration.getInt(ClientConfiguration.PROPERTY_CLIENT_CALLBACKS, ClientConfiguration.PROPERTY_CLIENT_CALLBACKS_DEFAULT);
    this.maxOperationRetryCount = configuration.getInt(ClientConfiguration.PROPERTY_MAX_OPERATION_RETRY_COUNT, ClientConfiguration.PROPERTY_MAX_OPERATION_RETRY_COUNT_DEFAULT);
    this.operationRetryDelay = configuration.getInt(ClientConfiguration.PROPERTY_OPERATION_RETRY_DELAY, ClientConfiguration.PROPERTY_OPERATION_RETRY_DELAY_DEFAULT);
    this.thredpool = new ThreadPoolExecutor(corePoolSize, Integer.MAX_VALUE,
            120L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(),
            (Runnable r) -> {
                Thread t = new FastThreadLocalThread(r, "hdb-client");
                t.setDaemon(true);
                return t;
            });
    this.networkGroup = NetworkUtils.isEnableEpoolNative() ? new EpollEventLoopGroup() : new NioEventLoopGroup();
    this.localEventsGroup = new DefaultEventLoopGroup();
    String mode = configuration.getString(ClientConfiguration.PROPERTY_MODE, ClientConfiguration.PROPERTY_MODE_LOCAL);
    switch (mode) {
        case ClientConfiguration.PROPERTY_MODE_LOCAL:
        case ClientConfiguration.PROPERTY_MODE_STANDALONE:
            this.clientSideMetadataProvider = new StaticClientSideMetadataProvider(
                    configuration.getString(ClientConfiguration.PROPERTY_SERVER_ADDRESS, ClientConfiguration.PROPERTY_SERVER_ADDRESS_DEFAULT),
                    configuration.getInt(ClientConfiguration.PROPERTY_SERVER_PORT, ClientConfiguration.PROPERTY_SERVER_PORT_DEFAULT),
                    configuration.getBoolean(ClientConfiguration.PROPERTY_SERVER_SSL, ClientConfiguration.PROPERTY_SERVER_SSL_DEFAULT)
            );
            break;
        case ClientConfiguration.PROPERTY_MODE_CLUSTER:
            this.clientSideMetadataProvider = new ZookeeperClientSideMetadataProvider(
                    configuration.getString(ClientConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, ClientConfiguration.PROPERTY_ZOOKEEPER_ADDRESS_DEFAULT),
                    configuration.getInt(ClientConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, ClientConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT_DEFAULT),
                    configuration.getString(ClientConfiguration.PROPERTY_ZOOKEEPER_PATH, ClientConfiguration.PROPERTY_ZOOKEEPER_PATH_DEFAULT)
            );
            break;
        default:
            throw new IllegalStateException(mode);
    }
}
 
Example 14
Source File: WriterWorker.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public WriterWorker(String streamPrefix,
                    URI uri,
                    int startStreamId,
                    int endStreamId,
                    ShiftableRateLimiter rateLimiter,
                    int writeConcurrency,
                    int messageSizeBytes,
                    int batchSize,
                    int hostConnectionCoreSize,
                    int hostConnectionLimit,
                    List<String> serverSetPaths,
                    List<String> finagleNames,
                    StatsReceiver statsReceiver,
                    StatsLogger statsLogger,
                    boolean thriftmux,
                    boolean handshakeWithClientInfo,
                    int sendBufferSize,
                    int recvBufferSize,
                    boolean enableBatching,
                    int batchBufferSize,
                    int batchFlushIntervalMicros) {
    Preconditions.checkArgument(startStreamId <= endStreamId);
    Preconditions.checkArgument(!finagleNames.isEmpty() || !serverSetPaths.isEmpty());
    this.streamPrefix = streamPrefix;
    this.dlUri = uri;
    this.startStreamId = startStreamId;
    this.endStreamId = endStreamId;
    this.rateLimiter = rateLimiter;
    this.writeConcurrency = writeConcurrency;
    this.messageSizeBytes = messageSizeBytes;
    this.statsReceiver = statsReceiver;
    this.statsLogger = statsLogger;
    this.requestStat = this.statsLogger.getOpStatsLogger("requests");
    this.exceptionsLogger = statsLogger.scope("exceptions");
    this.dlErrorCodeLogger = statsLogger.scope("dl_error_code");
    this.executorService = Executors.newCachedThreadPool();
    this.random = new Random(System.currentTimeMillis());
    this.batchSize = batchSize;
    this.hostConnectionCoreSize = hostConnectionCoreSize;
    this.hostConnectionLimit = hostConnectionLimit;
    this.thriftmux = thriftmux;
    this.handshakeWithClientInfo = handshakeWithClientInfo;
    this.sendBufferSize = sendBufferSize;
    this.recvBufferSize = recvBufferSize;
    this.enableBatching = enableBatching;
    this.batchBufferSize = batchBufferSize;
    this.batchFlushIntervalMicros = batchFlushIntervalMicros;
    this.finagleNames = finagleNames;
    this.serverSets = createServerSets(serverSetPaths);
    this.executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());

    // Streams
    streamNames = new ArrayList<String>(endStreamId - startStreamId);
    for (int i = startStreamId; i < endStreamId; i++) {
        streamNames.add(String.format("%s_%d", streamPrefix, i));
    }
    numStreams = streamNames.size();
    LOG.info("Writing to {} streams : {}", numStreams, streamNames);
}
 
Example 15
Source File: BKLogWriteHandler.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a Bookkeeper journal manager.
 */
BKLogWriteHandler(LogMetadataForWriter logMetadata,
                  DistributedLogConfiguration conf,
                  LogStreamMetadataStore streamMetadataStore,
                  LogSegmentMetadataCache metadataCache,
                  LogSegmentEntryStore entryStore,
                  OrderedScheduler scheduler,
                  Allocator<LogSegmentEntryWriter, Object> segmentAllocator,
                  StatsLogger statsLogger,
                  StatsLogger perLogStatsLogger,
                  AlertStatsLogger alertStatsLogger,
                  String clientId,
                  int regionId,
                  PermitLimiter writeLimiter,
                  FeatureProvider featureProvider,
                  DynamicDistributedLogConfiguration dynConf,
                  DistributedLock lock /** owned by handler **/) {
    super(logMetadata,
            conf,
            streamMetadataStore,
            metadataCache,
            entryStore,
            scheduler,
            statsLogger,
            alertStatsLogger,
            clientId);
    this.logMetadataForWriter = logMetadata;
    this.logSegmentAllocator = segmentAllocator;
    this.perLogStatsLogger = perLogStatsLogger;
    this.writeLimiter = writeLimiter;
    this.featureProvider = featureProvider;
    this.dynConf = dynConf;
    this.lock = lock;
    this.metadataUpdater = LogSegmentMetadataStoreUpdater.createMetadataUpdater(conf, metadataStore);

    if (conf.getEncodeRegionIDInLogSegmentMetadata()) {
        this.regionId = regionId;
    } else {
        this.regionId = DistributedLogConstants.LOCAL_REGION_ID;
    }
    this.validateLogSegmentSequenceNumber = conf.isLogSegmentSequenceNumberValidationEnabled();

    // Construct the max sequence no
    maxLogSegmentSequenceNo = new MaxLogSegmentSequenceNo(logMetadata.getMaxLSSNData());
    inprogressLSSNs = new LinkedList<Long>();
    // Construct the max txn id.
    maxTxId = new MaxTxId(logMetadata.getMaxTxIdData());

    // Schedule fetching log segment list in background before we access it.
    // We don't need to watch the log segment list changes for writer, as it manages log segment list.
    fetchForWrite = readLogSegmentsFromStore(
            LogSegmentMetadata.COMPARATOR,
            WRITE_HANDLE_FILTER,
            null);

    // Initialize other parameters.
    setLastLedgerRollingTimeMillis(Utils.nowInMillis());

    // Rolling Policy
    if (conf.getLogSegmentRollingIntervalMinutes() > 0) {
        rollingPolicy = new TimeBasedRollingPolicy(conf.getLogSegmentRollingIntervalMinutes() * 60 * 1000L);
    } else {
        rollingPolicy = new SizeBasedRollingPolicy(conf.getMaxLogSegmentBytes());
    }

    // Stats
    StatsLogger segmentsStatsLogger = statsLogger.scope("segments");
    openOpStats = segmentsStatsLogger.getOpStatsLogger("open");
    closeOpStats = segmentsStatsLogger.getOpStatsLogger("close");
    recoverOpStats = segmentsStatsLogger.getOpStatsLogger("recover");
    deleteOpStats = segmentsStatsLogger.getOpStatsLogger("delete");
}
 
Example 16
Source File: AbstractStreamOp.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public static StatsLogger requestLogger(StatsLogger statsLogger) {
    return statsLogger.scope("request");
}
 
Example 17
Source File: BKLogHandler.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a Bookkeeper journal manager.
 */
BKLogHandler(ZKLogMetadata metadata,
             DistributedLogConfiguration conf,
             ZooKeeperClientBuilder zkcBuilder,
             BookKeeperClientBuilder bkcBuilder,
             LogSegmentMetadataStore metadataStore,
             OrderedScheduler scheduler,
             StatsLogger statsLogger,
             AlertStatsLogger alertStatsLogger,
             AsyncNotification notification,
             LogSegmentFilter filter,
             String lockClientId) {
    Preconditions.checkNotNull(zkcBuilder);
    Preconditions.checkNotNull(bkcBuilder);
    this.logMetadata = metadata;
    this.conf = conf;
    this.scheduler = scheduler;
    this.statsLogger = statsLogger;
    this.alertStatsLogger = alertStatsLogger;
    this.notification = notification;
    this.filter = filter;
    this.logSegmentCache = new LogSegmentCache(metadata.getLogName());

    firstNumEntriesPerReadLastRecordScan = conf.getFirstNumEntriesPerReadLastRecordScan();
    maxNumEntriesPerReadLastRecordScan = conf.getMaxNumEntriesPerReadLastRecordScan();
    this.zooKeeperClient = zkcBuilder.build();
    LOG.debug("Using ZK Path {}", logMetadata.getLogRootPath());
    this.bookKeeperClient = bkcBuilder.build();
    this.metadataStore = metadataStore;

    if (lockClientId.equals(DistributedLogConstants.UNKNOWN_CLIENT_ID)) {
        this.lockClientId = getHostIpLockClientId();
    } else {
        this.lockClientId = lockClientId;
    }

    this.getChildrenWatcher = this.zooKeeperClient.getWatcherManager()
            .registerChildWatcher(logMetadata.getLogSegmentsPath(), this);

    // Traces
    this.metadataLatencyWarnThresholdMillis = conf.getMetadataLatencyWarnThresholdMillis();

    // Stats
    StatsLogger segmentsLogger = statsLogger.scope("logsegments");
    forceGetListStat = segmentsLogger.getOpStatsLogger("force_get_list");
    getListStat = segmentsLogger.getOpStatsLogger("get_list");
    getFilteredListStat = segmentsLogger.getOpStatsLogger("get_filtered_list");
    getFullListStat = segmentsLogger.getOpStatsLogger("get_full_list");
    getInprogressSegmentStat = segmentsLogger.getOpStatsLogger("get_inprogress_segment");
    getCompletedSegmentStat = segmentsLogger.getOpStatsLogger("get_completed_segment");
    negativeGetInprogressSegmentStat = segmentsLogger.getOpStatsLogger("negative_get_inprogress_segment");
    negativeGetCompletedSegmentStat = segmentsLogger.getOpStatsLogger("negative_get_completed_segment");
    recoverLastEntryStats = segmentsLogger.getOpStatsLogger("recover_last_entry");
    recoverScannedEntriesStats = segmentsLogger.getOpStatsLogger("recover_scanned_entries");
}
 
Example 18
Source File: BKLogReadHandler.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a Bookkeeper journal manager.
 */
public BKLogReadHandler(ZKLogMetadataForReader logMetadata,
                        Optional<String> subscriberId,
                        DistributedLogConfiguration conf,
                        DynamicDistributedLogConfiguration dynConf,
                        ZooKeeperClientBuilder zkcBuilder,
                        BookKeeperClientBuilder bkcBuilder,
                        LogSegmentMetadataStore metadataStore,
                        OrderedScheduler scheduler,
                        OrderedScheduler lockStateExecutor,
                        OrderedScheduler readAheadExecutor,
                        AlertStatsLogger alertStatsLogger,
                        ReadAheadExceptionsLogger readAheadExceptionsLogger,
                        StatsLogger statsLogger,
                        StatsLogger perLogStatsLogger,
                        String clientId,
                        AsyncNotification notification,
                        boolean isHandleForReading,
                        boolean deserializeRecordSet) {
    super(logMetadata, conf, zkcBuilder, bkcBuilder, metadataStore, scheduler,
          statsLogger, alertStatsLogger, notification, LogSegmentFilter.DEFAULT_FILTER, clientId);
    this.logMetadataForReader = logMetadata;
    this.dynConf = dynConf;
    this.readAheadExecutor = readAheadExecutor;
    this.alertStatsLogger = alertStatsLogger;
    this.perLogStatsLogger =
            isHandleForReading ? perLogStatsLogger : NullStatsLogger.INSTANCE;
    this.handlerStatsLogger =
            BroadCastStatsLogger.masterslave(this.perLogStatsLogger, statsLogger);
    this.readAheadExceptionsLogger = readAheadExceptionsLogger;

    handleCache = LedgerHandleCache.newBuilder()
            .bkc(this.bookKeeperClient)
            .conf(conf)
            .statsLogger(statsLogger)
            .build();
    readAheadCache = new ReadAheadCache(
            getFullyQualifiedName(),
            handlerStatsLogger,
            alertStatsLogger,
            notification,
            dynConf.getReadAheadMaxRecords(),
            deserializeRecordSet,
            conf.getTraceReadAheadDeliveryLatency(),
            conf.getDataLatencyWarnThresholdMillis(),
            Ticker.systemTicker());

    this.subscriberId = subscriberId;
    this.readLockPath = logMetadata.getReadLockPath(subscriberId);
    this.lockStateExecutor = lockStateExecutor;
    this.lockFactory = new ZKSessionLockFactory(
            zooKeeperClient,
            getLockClientId(),
            lockStateExecutor,
            conf.getZKNumRetries(),
            conf.getLockTimeoutMilliSeconds(),
            conf.getZKRetryBackoffStartMillis(),
            statsLogger.scope("read_lock"));

    this.isHandleForReading = isHandleForReading;
}
 
Example 19
Source File: BKLogWriteHandler.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a Bookkeeper journal manager.
 */
BKLogWriteHandler(ZKLogMetadataForWriter logMetadata,
                  DistributedLogConfiguration conf,
                  ZooKeeperClientBuilder zkcBuilder,
                  BookKeeperClientBuilder bkcBuilder,
                  LogSegmentMetadataStore metadataStore,
                  OrderedScheduler scheduler,
                  LedgerAllocator allocator,
                  StatsLogger statsLogger,
                  StatsLogger perLogStatsLogger,
                  AlertStatsLogger alertStatsLogger,
                  String clientId,
                  int regionId,
                  PermitLimiter writeLimiter,
                  FeatureProvider featureProvider,
                  DynamicDistributedLogConfiguration dynConf,
                  DistributedLock lock /** owned by handler **/) {
    super(logMetadata, conf, zkcBuilder, bkcBuilder, metadataStore,
          scheduler, statsLogger, alertStatsLogger, null, WRITE_HANDLE_FILTER, clientId);
    this.perLogStatsLogger = perLogStatsLogger;
    this.writeLimiter = writeLimiter;
    this.featureProvider = featureProvider;
    this.dynConf = dynConf;
    this.ledgerAllocator = allocator;
    this.lock = lock;
    this.metadataUpdater = LogSegmentMetadataStoreUpdater.createMetadataUpdater(conf, metadataStore);

    ensembleSize = conf.getEnsembleSize();

    if (ensembleSize < conf.getWriteQuorumSize()) {
        writeQuorumSize = ensembleSize;
        LOG.warn("Setting write quorum size {} greater than ensemble size {}",
            conf.getWriteQuorumSize(), ensembleSize);
    } else {
        writeQuorumSize = conf.getWriteQuorumSize();
    }
    if (writeQuorumSize < conf.getAckQuorumSize()) {
        ackQuorumSize = writeQuorumSize;
        LOG.warn("Setting write ack quorum size {} greater than write quorum size {}",
            conf.getAckQuorumSize(), writeQuorumSize);
    } else {
        ackQuorumSize = conf.getAckQuorumSize();
    }

    if (conf.getEncodeRegionIDInLogSegmentMetadata()) {
        this.regionId = regionId;
    } else {
        this.regionId = DistributedLogConstants.LOCAL_REGION_ID;
    }
    this.sanityCheckTxnId = conf.getSanityCheckTxnID();
    this.validateLogSegmentSequenceNumber = conf.isLogSegmentSequenceNumberValidationEnabled();

    // Construct the max sequence no
    maxLogSegmentSequenceNo = new MaxLogSegmentSequenceNo(logMetadata.getMaxLSSNData());
    inprogressLSSNs = new LinkedList<Long>();
    // Construct the max txn id.
    maxTxId = new MaxTxId(zooKeeperClient, logMetadata.getMaxTxIdPath(),
            conf.getSanityCheckTxnID(), logMetadata.getMaxTxIdData());

    // Schedule fetching ledgers list in background before we access it.
    // We don't need to watch the ledgers list changes for writer, as it manages ledgers list.
    scheduleGetLedgersTask(false, true);

    // Initialize other parameters.
    setLastLedgerRollingTimeMillis(Utils.nowInMillis());

    // Rolling Policy
    if (conf.getLogSegmentRollingIntervalMinutes() > 0) {
        rollingPolicy = new TimeBasedRollingPolicy(conf.getLogSegmentRollingIntervalMinutes() * 60 * 1000L);
    } else {
        rollingPolicy = new SizeBasedRollingPolicy(conf.getMaxLogSegmentBytes());
    }

    // Stats
    StatsLogger segmentsStatsLogger = statsLogger.scope("segments");
    openOpStats = segmentsStatsLogger.getOpStatsLogger("open");
    closeOpStats = segmentsStatsLogger.getOpStatsLogger("close");
    recoverOpStats = segmentsStatsLogger.getOpStatsLogger("recover");
    deleteOpStats = segmentsStatsLogger.getOpStatsLogger("delete");
}
 
Example 20
Source File: ReadAheadWorker.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public ReadAheadWorker(DistributedLogConfiguration conf,
                       DynamicDistributedLogConfiguration dynConf,
                       ZKLogMetadataForReader logMetadata,
                       BKLogHandler ledgerManager,
                       ZooKeeperClient zkc,
                       OrderedScheduler scheduler,
                       LedgerHandleCache handleCache,
                       LedgerReadPosition startPosition,
                       ReadAheadCache readAheadCache,
                       boolean isHandleForReading,
                       ReadAheadExceptionsLogger readAheadExceptionsLogger,
                       StatsLogger handlerStatsLogger,
                       StatsLogger readAheadPerStreamStatsLogger,
                       AlertStatsLogger alertStatsLogger,
                       AsyncFailureInjector failureInjector,
                       AsyncNotification notification) {
    // Log information
    this.fullyQualifiedName = logMetadata.getFullyQualifiedName();
    this.conf = conf;
    this.dynConf = dynConf;
    this.logMetadata = logMetadata;
    this.bkLedgerManager = ledgerManager;
    this.isHandleForReading = isHandleForReading;
    this.notification = notification;
    // Resources
    this.zkc = zkc;
    this.scheduler = scheduler;
    this.handleCache = handleCache;
    this.readAheadCache = readAheadCache;
    // Readahead status
    this.startReadPosition = new LedgerReadPosition(startPosition);
    this.nextReadAheadPosition = new LedgerReadPosition(startPosition);
    // LogSegments
    this.getLedgersWatcher = this.zkc.getWatcherManager()
            .registerChildWatcher(logMetadata.getLogSegmentsPath(), this);
    // Failure Detection
    this.failureInjector = failureInjector;
    // Tracing
    this.metadataLatencyWarnThresholdMillis = conf.getMetadataLatencyWarnThresholdMillis();
    this.noLedgerExceptionOnReadLACThreshold =
            conf.getReadAheadNoSuchLedgerExceptionOnReadLACErrorThresholdMillis() / conf.getReadAheadWaitTime();
    this.tracker = new ReadAheadTracker(logMetadata.getLogName(), readAheadCache,
            ReadAheadPhase.SCHEDULE_READAHEAD, readAheadPerStreamStatsLogger);
    this.resumeStopWatch = Stopwatch.createUnstarted();
    // Misc
    this.readAheadSkipBrokenEntries = conf.getReadAheadSkipBrokenEntries();
    // Stats
    this.alertStatsLogger = alertStatsLogger;
    this.readAheadPerStreamStatsLogger = readAheadPerStreamStatsLogger;
    StatsLogger readAheadStatsLogger = handlerStatsLogger.scope("readahead_worker");
    readAheadWorkerWaits = readAheadStatsLogger.getCounter("wait");
    readAheadEntryPiggyBackHits = readAheadStatsLogger.getCounter("entry_piggy_back_hits");
    readAheadEntryPiggyBackMisses = readAheadStatsLogger.getCounter("entry_piggy_back_misses");
    readAheadReadEntriesStat = readAheadStatsLogger.getOpStatsLogger("read_entries");
    readAheadReadLACAndEntryCounter = readAheadStatsLogger.getCounter("read_lac_and_entry_counter");
    readAheadCacheFullCounter = readAheadStatsLogger.getCounter("cache_full");
    readAheadSkippedBrokenEntries = readAheadStatsLogger.getCounter("skipped_broken_entries");
    readAheadCacheResumeStat = readAheadStatsLogger.getOpStatsLogger("resume");
    readAheadLacLagStats = readAheadStatsLogger.getOpStatsLogger("read_lac_lag");
    longPollInterruptionStat = readAheadStatsLogger.getOpStatsLogger("long_poll_interruption");
    notificationExecutionStat = readAheadStatsLogger.getOpStatsLogger("notification_execution");
    metadataReinitializationStat = readAheadStatsLogger.getOpStatsLogger("metadata_reinitialization");
    idleReaderWarn = readAheadStatsLogger.getCounter("idle_reader_warn");
    this.readAheadExceptionsLogger = readAheadExceptionsLogger;
}