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

The following examples show how to use org.apache.bookkeeper.stats.StatsLogger#getOpStatsLogger() . 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: BookKeeperDataStorageManager.java    From herddb with Apache License 2.0 6 votes vote down vote up
public BookKeeperDataStorageManager(
        String nodeId, Path tmpDirectory, int swapThreshold, ZookeeperMetadataStorageManager zk, BookkeeperCommitLogManager bk, StatsLogger logger
) {
    this.nodeId = nodeId;
    this.tmpDirectory = tmpDirectory;
    this.swapThreshold = swapThreshold;
    StatsLogger scope = logger.scope("bkdatastore");
    this.dataPageReads = scope.getOpStatsLogger("data_pagereads");
    this.dataPageWrites = scope.getOpStatsLogger("data_pagewrites");
    this.indexPageReads = scope.getOpStatsLogger("index_pagereads");
    this.indexPageWrites = scope.getOpStatsLogger("index_pagewrites");
    this.zkReads = scope.getCounter("zkReads");
    this.zkWrites = scope.getCounter("zkWrites");
    this.zkGetChildren = scope.getCounter("zkGetChildren");
    this.zk = zk;
    this.bk = bk;
    this.rootZkNode = zk.getBasePath() + "/data";
    this.baseZkNode = rootZkNode + "/" + nodeId;
}
 
Example 2
Source File: SimplePermitLimiter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public SimplePermitLimiter(boolean darkmode, int permitsMax, StatsLogger statsLogger,
                           boolean singleton, Feature disableWriteLimitFeature) {
    this.permits = new AtomicInteger(0);
    this.permitsMax = permitsMax;
    this.darkmode = darkmode;
    this.disableWriteLimitFeature = disableWriteLimitFeature;

    // stats
    if (singleton) {
        statsLogger.registerGauge("num_permits", new Gauge<Number>() {
            @Override
            public Number getDefaultValue() {
                return 0;
            }
            @Override
            public Number getSample() {
                return permits.get();
            }
        });
    }
    acquireFailureCounter = statsLogger.getCounter("acquireFailure");
    permitsMetric = statsLogger.getOpStatsLogger("permits");
}
 
Example 3
Source File: SimplePermitLimiter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public SimplePermitLimiter(boolean darkmode, int permitsMax, StatsLogger statsLogger,
                           boolean singleton, Feature disableWriteLimitFeature) {
    this.permits = new AtomicInteger(0);
    this.permitsMax = permitsMax;
    this.darkmode = darkmode;
    this.disableWriteLimitFeature = disableWriteLimitFeature;

    // stats
    if (singleton) {
        this.statsLogger = statsLogger;
        this.permitsGauge = new Gauge<Number>() {
            @Override
            public Number getDefaultValue() {
                return 0;
            }
            @Override
            public Number getSample() {
                return permits.get();
            }
        };
        this.permitsGaugeLabel = "permits";
        statsLogger.registerGauge(permitsGaugeLabel, permitsGauge);
    }
    acquireFailureCounter = statsLogger.getCounter("acquireFailure");
    permitsMetric = statsLogger.getOpStatsLogger("permits");
}
 
Example 4
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 5
Source File: PlacementPolicy.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public PlacementPolicy(LoadAppraiser loadAppraiser, RoutingService routingService,
                       Namespace namespace, PlacementStateManager placementStateManager,
                       Duration refreshInterval, StatsLogger statsLogger) {
    this.loadAppraiser = loadAppraiser;
    this.routingService = routingService;
    this.namespace = namespace;
    this.placementStateManager = placementStateManager;
    this.refreshInterval = refreshInterval;
    placementCalcStats = statsLogger.getOpStatsLogger("placement");
}
 
Example 6
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 7
Source File: MonitoredFuturePool.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
/**
 * Create a future pool with stats exposed.
 *
 * @param futurePool underlying future pool to execute futures
 * @param statsLogger stats logger to receive exposed stats
 * @param traceTaskExecution flag to enable/disable exposing stats about task execution
 * @param traceTaskExecutionWarnTimeUs flag to enable/disable logging slow tasks
 *                                     whose execution time is above this value
 */
public MonitoredFuturePool(FuturePool futurePool,
                           StatsLogger statsLogger,
                           boolean traceTaskExecution,
                           long traceTaskExecutionWarnTimeUs) {
    this.futurePool = futurePool;
    this.traceTaskExecution = traceTaskExecution;
    this.traceTaskExecutionWarnTimeUs = traceTaskExecutionWarnTimeUs;
    this.statsLogger = statsLogger;
    this.taskPendingTime = statsLogger.getOpStatsLogger("task_pending_time");
    this.taskExecutionTime = statsLogger.getOpStatsLogger("task_execution_time");
    this.taskEnqueueTime = statsLogger.getOpStatsLogger("task_enqueue_time");
    this.taskPendingCounter = statsLogger.getCounter("tasks_pending");
}
 
Example 8
Source File: BKLogHandler.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a Bookkeeper journal manager.
 */
BKLogHandler(LogMetadata metadata,
             DistributedLogConfiguration conf,
             LogStreamMetadataStore streamMetadataStore,
             LogSegmentMetadataCache metadataCache,
             LogSegmentEntryStore entryStore,
             OrderedScheduler scheduler,
             StatsLogger statsLogger,
             AlertStatsLogger alertStatsLogger,
             String lockClientId) {
    this.logMetadata = metadata;
    this.conf = conf;
    this.scheduler = scheduler;
    this.statsLogger = statsLogger;
    this.alertStatsLogger = alertStatsLogger;
    this.logSegmentCache = new PerStreamLogSegmentCache(
            metadata.getLogName(),
            conf.isLogSegmentSequenceNumberValidationEnabled());
    firstNumEntriesPerReadLastRecordScan = conf.getFirstNumEntriesPerReadLastRecordScan();
    maxNumEntriesPerReadLastRecordScan = conf.getMaxNumEntriesPerReadLastRecordScan();
    this.streamMetadataStore = streamMetadataStore;
    this.metadataStore = streamMetadataStore.getLogSegmentMetadataStore();
    this.metadataCache = metadataCache;
    this.entryStore = entryStore;
    this.lockClientId = lockClientId;

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

    // Stats
    StatsLogger segmentsLogger = statsLogger.scope("logsegments");
    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 9
Source File: LocalWorker.java    From openmessaging-benchmark with Apache License 2.0 5 votes vote down vote up
public LocalWorker(StatsLogger statsLogger) {
    this.statsLogger = statsLogger;

    StatsLogger producerStatsLogger = statsLogger.scope("producer");
    this.messagesSentCounter = producerStatsLogger.getCounter("messages_sent");
    this.bytesSentCounter = producerStatsLogger.getCounter("bytes_sent");
    this.publishLatencyStats = producerStatsLogger.getOpStatsLogger("produce_latency");

    StatsLogger consumerStatsLogger = statsLogger.scope("consumer");
    this.messagesReceivedCounter = consumerStatsLogger.getCounter("messages_recv");
    this.bytesReceivedCounter = consumerStatsLogger.getCounter("bytes_recv");
    this.endToEndLatencyStats = consumerStatsLogger.getOpStatsLogger("e2e_latency");
}
 
Example 10
Source File: EnvelopedEntry.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public EnvelopedEntry(byte version,
                      StatsLogger statsLogger) throws InvalidEnvelopedEntryException {
    Preconditions.checkNotNull(statsLogger);
    if (version < LOWEST_SUPPORTED_VERSION || version > HIGHEST_SUPPORTED_VERSION) {
        throw new InvalidEnvelopedEntryException("Invalid enveloped entry version " + version + ", expected to be in [ "
                + LOWEST_SUPPORTED_VERSION + " ~ " + HIGHEST_SUPPORTED_VERSION + " ]");
    }
    this.version = version;
    this.compressionStat = statsLogger.getOpStatsLogger("compression_time");
    this.decompressionStat = statsLogger.getOpStatsLogger("decompression_time");
    this.compressedEntryBytes = statsLogger.getCounter("compressed_bytes");
    this.decompressedEntryBytes = statsLogger.getCounter("decompressed_bytes");
}
 
Example 11
Source File: ChainedRequestLimiter.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
private ChainedRequestLimiter(ImmutableList<RequestLimiter<Request>> limiters,
                              StatsLogger statsLogger) {
    this.limiters = limiters;
    this.applyTime = statsLogger.getOpStatsLogger("apply");
}
 
Example 12
Source File: FileCommitLog.java    From herddb with Apache License 2.0 4 votes vote down vote up
public FileCommitLog(
        Path logDirectory, String tableSpaceName,
        long maxLogFileSize, ExecutorService fsyncThreadPool, StatsLogger statslogger,
        Consumer<FileCommitLog> onClose,
        int maxUnsynchedBatchSize,
        int maxUnsynchedBatchBytes,
        int maxSyncTime,
        boolean requireSync,
        boolean enableO_DIRECT
) {
    this.maxUnsyncedBatchSize = maxUnsynchedBatchSize;
    this.maxUnsyncedBatchBytes = maxUnsynchedBatchBytes;
    this.maxSyncTime = TimeUnit.MILLISECONDS.toNanos(maxSyncTime);
    this.requireSync = requireSync;
    this.enableO_DIRECT = enableO_DIRECT && OpenFileUtils.isO_DIRECT_Supported();
    this.onClose = onClose;
    this.maxLogFileSize = maxLogFileSize;
    this.tableSpaceName = tableSpaceName;
    this.logDirectory = logDirectory.toAbsolutePath();
    this.spool = new Thread(new SpoolTask(), "commitlog-" + tableSpaceName);
    this.spool.setDaemon(true);
    this.statsFsyncTime = statslogger.getOpStatsLogger("fsync");
    this.statsEntryLatency = statslogger.getOpStatsLogger("entryLatency");
    this.statsEntrySyncLatency = statslogger.getOpStatsLogger("entrySyncLatency");
    this.syncSize = statslogger.getOpStatsLogger("syncBatchSize");
    this.syncBytes = statslogger.getOpStatsLogger("syncBatchBytes");
    this.deferredSyncs = statslogger.getCounter("deferredSyncs");
    this.newfiles = statslogger.getCounter("newfiles");
    statslogger.registerGauge("queuesize", new Gauge<Integer>() {
        @Override
        public Integer getDefaultValue() {
            return 0;
        }

        @Override
        public Integer getSample() {
            return queueSize.get();
        }

    });
    statslogger.registerGauge("pendingentries", new Gauge<Integer>() {
        @Override
        public Integer getDefaultValue() {
            return 0;
        }

        @Override
        public Integer getSample() {
            return pendingEntries.get();
        }

    });

    this.fsyncThreadPool = fsyncThreadPool;
    LOGGER.log(Level.FINE, "tablespace {2}, logdirectory: {0}, maxLogFileSize {1} bytes", new Object[]{logDirectory, maxLogFileSize, tableSpaceName});
}
 
Example 13
Source File: ZKSessionLock.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a distributed lock using the given {@code zkClient} to coordinate locking.
 *
 * @param zkClient The ZooKeeper client to use.
 * @param lockPath The path used to manage the lock under.
 * @param clientId client id use for lock.
 * @param lockStateExecutor executor to execute all lock state changes.
 * @param lockOpTimeout timeout of lock operations
 * @param statsLogger stats logger
 */
public ZKSessionLock(ZooKeeperClient zkClient,
                     String lockPath,
                     String clientId,
                     OrderedScheduler lockStateExecutor,
                     long lockOpTimeout,
                     StatsLogger statsLogger,
                     DistributedLockContext lockContext)
        throws IOException {
    this.zkClient = zkClient;
    try {
        this.zk = zkClient.get();
    } catch (ZooKeeperClient.ZooKeeperConnectionException zce) {
        throw new ZKException("Failed to get zookeeper client for lock " + lockPath,
                KeeperException.Code.CONNECTIONLOSS);
    } catch (InterruptedException e) {
        throw new DLInterruptedException("Interrupted on getting zookeeper client for lock " + lockPath, e);
    }
    this.lockPath = lockPath;
    this.lockId = Pair.of(clientId, this.zk.getSessionId());
    this.lockContext = lockContext;
    this.lockStateExecutor = lockStateExecutor;
    this.lockState = new StateManagement();
    this.lockOpTimeout = lockOpTimeout;

    this.tryStats = statsLogger.getOpStatsLogger("tryAcquire");
    this.tryTimeouts = statsLogger.getCounter("tryTimeouts");
    this.unlockStats = statsLogger.getOpStatsLogger("unlock");

    // Attach interrupt handler to acquire future so clients can abort the future.
    this.acquireFuture = new Promise<Boolean>(new com.twitter.util.Function<Throwable, BoxedUnit>() {
        @Override
        public BoxedUnit apply(Throwable t) {
            // This will set the lock state to closed, and begin to cleanup the zk lock node.
            // We have to be careful not to block here since doing so blocks the ordered lock
            // state executor which can cause deadlocks depending on how futures are chained.
            ZKSessionLock.this.asyncUnlock(t);
            // Note re. logging and exceptions: errors are already logged by unlockAsync.
            return BoxedUnit.UNIT;
        }
    });
}
 
Example 14
Source File: BKAsyncLogReaderDLSN.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
BKAsyncLogReaderDLSN(BKDistributedLogManager bkdlm,
                     ScheduledExecutorService executorService,
                     OrderedScheduler lockStateExecutor,
                     DLSN startDLSN,
                     Optional<String> subscriberId,
                     boolean returnEndOfStreamRecord,
                     boolean deserializeRecordSet,
                     StatsLogger statsLogger) {
    this.bkDistributedLogManager = bkdlm;
    this.executorService = executorService;
    this.bkLedgerManager = bkDistributedLogManager.createReadHandler(subscriberId,
            lockStateExecutor, this, deserializeRecordSet, true);
    sessionExpireWatcher = this.bkLedgerManager.registerExpirationHandler(this);
    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;

    // Failure Injection
    this.failureInjector = AsyncRandomFailureInjector.newBuilder()
            .injectDelays(bkdlm.getConf().getEIInjectReadAheadDelay(),
                          bkdlm.getConf().getEIInjectReadAheadDelayPercent(),
                          bkdlm.getConf().getEIInjectMaxReadAheadDelayMs())
            .injectErrors(false, 10)
            .injectStops(bkdlm.getConf().getEIInjectReadAheadStall(), 10)
            .injectCorruption(bkdlm.getConf().getEIInjectReadAheadBrokenEntries())
            .build();

    // 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();
}
 
Example 15
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;
}
 
Example 16
Source File: StreamImpl.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
StreamImpl(final String name,
           final Partition partition,
           String clientId,
           StreamManager streamManager,
           StreamOpStats streamOpStats,
           ServerConfiguration serverConfig,
           DistributedLogConfiguration dlConfig,
           DynamicDistributedLogConfiguration streamConf,
           FeatureProvider featureProvider,
           StreamConfigProvider streamConfigProvider,
           DistributedLogNamespace dlNamespace,
           OrderedScheduler scheduler,
           FatalErrorHandler fatalErrorHandler,
           HashedWheelTimer requestTimer) {
    this.clientId = clientId;
    this.dlConfig = dlConfig;
    this.streamManager = streamManager;
    this.name = name;
    this.partition = partition;
    this.status = StreamStatus.UNINITIALIZED;
    this.lastException = new IOException("Fail to write record to stream " + name);
    this.nextAcquireWaitTimeMs = dlConfig.getZKSessionTimeoutMilliseconds() * 3 / 5;
    this.streamConfigProvider = streamConfigProvider;
    this.dlNamespace = dlNamespace;
    this.featureRateLimitDisabled = featureProvider.getFeature(
        ServerFeatureKeys.SERVICE_RATE_LIMIT_DISABLED.name().toLowerCase());
    this.scheduler = scheduler;
    this.serviceTimeoutMs = serverConfig.getServiceTimeoutMs();
    this.streamProbationTimeoutMs = serverConfig.getStreamProbationTimeoutMs();
    this.failFastOnStreamNotReady = dlConfig.getFailFastOnStreamNotReady();
    this.fatalErrorHandler = fatalErrorHandler;
    this.dynConf = streamConf;
    StatsLogger limiterStatsLogger = BroadCastStatsLogger.two(
        streamOpStats.baseScope("stream_limiter"),
        streamOpStats.streamRequestScope(name, "limiter"));
    this.limiter = new StreamRequestLimiter(name, dynConf, limiterStatsLogger, featureRateLimitDisabled);
    this.requestTimer = requestTimer;

    // Stats
    this.streamLogger = streamOpStats.streamRequestStatsLogger(name);
    this.limiterStatLogger = streamOpStats.baseScope("request_limiter");
    this.streamExceptionStatLogger = streamLogger.scope("exceptions");
    this.serviceTimeout = streamOpStats.baseCounter("serviceTimeout");
    StatsLogger streamsStatsLogger = streamOpStats.baseScope("streams");
    this.streamAcquireStat = streamsStatsLogger.getOpStatsLogger("acquire");
    this.pendingOpsCounter = streamOpStats.baseCounter("pending_ops");
    this.unexpectedExceptions = streamOpStats.baseCounter("unexpected_exceptions");
    this.exceptionStatLogger = streamOpStats.requestScope("exceptions");
}
 
Example 17
Source File: ZKSessionLock.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a distributed lock using the given {@code zkClient} to coordinate locking.
 *
 * @param zkClient The ZooKeeper client to use.
 * @param lockPath The path used to manage the lock under.
 * @param clientId client id use for lock.
 * @param lockStateExecutor executor to execute all lock state changes.
 * @param lockOpTimeout timeout of lock operations
 * @param statsLogger stats logger
 */
public ZKSessionLock(ZooKeeperClient zkClient,
                     String lockPath,
                     String clientId,
                     OrderedScheduler lockStateExecutor,
                     long lockOpTimeout,
                     StatsLogger statsLogger,
                     DistributedLockContext lockContext)
        throws IOException {
    this.zkClient = zkClient;
    try {
        this.zk = zkClient.get();
    } catch (ZooKeeperClient.ZooKeeperConnectionException zce) {
        throw new ZKException("Failed to get zookeeper client for lock " + lockPath,
                KeeperException.Code.CONNECTIONLOSS);
    } catch (InterruptedException e) {
        throw new DLInterruptedException("Interrupted on getting zookeeper client for lock " + lockPath, e);
    }
    this.lockPath = lockPath;
    this.lockId = Pair.of(clientId, this.zk.getSessionId());
    this.lockContext = lockContext;
    this.lockStateExecutor = lockStateExecutor;
    this.lockState = new StateManagement();
    this.lockOpTimeout = lockOpTimeout;

    this.tryStats = statsLogger.getOpStatsLogger("tryAcquire");
    this.tryTimeouts = statsLogger.getCounter("tryTimeouts");
    this.unlockStats = statsLogger.getOpStatsLogger("unlock");

    // Attach interrupt handler to acquire future so clients can abort the future.
    this.acquireFuture = FutureUtils.createFuture();
    this.acquireFuture.whenComplete((value, cause) -> {
        if (null != cause) {
            // This will set the lock state to closed, and begin to cleanup the zk lock node.
            // We have to be careful not to block here since doing so blocks the ordered lock
            // state executor which can cause deadlocks depending on how futures are chained.
            ZKSessionLock.this.asyncUnlock(cause);
            // Note re. logging and exceptions: errors are already logged by unlockAsync.
        }
    });
}
 
Example 18
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 19
Source File: StatsFilter.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public StatsFilter(StatsLogger stats) {
    this.stats = stats;
    this.outstandingAsync = stats.getCounter("outstandingAsync");
    this.serviceExec = stats.getOpStatsLogger("serviceExec");
}
 
Example 20
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");
}