Пример #1
0
            private void AddPartitionTopicInfo(
                Pool <string, Pool <int, PartitionTopicInfo> > currentTopicRegistry,
                ZKGroupTopicDirs topicDirs,
                int partition,
                string topic,
                string consumerThreadId)
            {
                var partTopicInfoMap = currentTopicRegistry.Get(topic);

                var znode        = topicDirs.ConsumerOffsetDir + "/" + partition;
                var offsetString = ZkUtils.ReadDataMaybeNull(parent.zkClient, znode).Item1;

                // If first time starting a consumer, set the initial offset to -1
                var offset = (offsetString != null) ? long.Parse(offsetString) : PartitionTopicInfo.InvalidOffset;

                var queue          = parent.topicThreadIdAndQueues.Get(Tuple.Create(topic, consumerThreadId));
                var consumedOffset = new AtomicLong(offset);
                var fetchedOffset  = new AtomicLong(offset);
                var partTopicInfo  = new PartitionTopicInfo(
                    topic,
                    partition,
                    queue,
                    consumedOffset,
                    fetchedOffset,
                    new AtomicInteger(parent.Config.FetchMessageMaxBytes),
                    parent.Config.ClientId);

                partTopicInfoMap[partition] = partTopicInfo;
                Logger.DebugFormat("{0} selected new offset {1}", partTopicInfo, offset);
                parent.checkpointedOffsets[new TopicAndPartition(topic, partition)] = offset;
            }