예제 #1
0
 public void Start(CheckpointTag checkpointTag, PartitionState rootPartitionState)
 {
     _started   = true;
     _startedAt = checkpointTag;
     _lastEvent = checkpointTag;
 }
예제 #2
0
 public void StateUpdated(string partition, PartitionState oldState, PartitionState newState)
 {
     throw new NotImplementedException();
 }
예제 #3
0
        /// <summary>
        /// Manage beginning of fetch on given topic/partition.
        /// If the required offset is positive (i.e. client required a specific known offset
        /// to begin from) we issue a Fetch request. If the required offset is Earliest or Latest,
        /// we issue an Offset request to discover the offset values before beginning fetch requests.
        ///
        /// This method initializes the PartitionState associated to this topic / partition.
        /// </summary>
        /// <param name="topicOnOff"></param>
        /// <returns></returns>
        private async Task HandleStart(TopicOnOff topicOnOff)
        {
            int[] partitions = null;
            if (topicOnOff.Partition >= 0)
            {
                partitions    = _tmpPartitions;
                partitions[0] = topicOnOff.Partition;
            }
            else
            {
                if (_consumerGroup != null)
                {
                    // (Re)start all assigned partitions
                    partitions = _partitionAssignments[topicOnOff.Topic].Select(po => po.Partition).ToArray();
                }
                else
                {
                    while (partitions == null)
                    {
                        try
                        {
                            partitions = await _cluster.RequireAllPartitionsForTopic(topicOnOff.Topic);
                        }
                        catch
                        {
                            // Means the cluster is kind of dead, ignore and retry, there's not much else
                            // to do anyway since we won't be able to send more fetch requests until
                            // some node is available.
                            // TODO: be verbose?
                        }
                    }
                }
            }

            foreach (int partition in partitions)
            {
                // Initialize PartitionState if needed
                Dictionary <int, PartitionState> states;
                if (!_partitionsStates.TryGetValue(topicOnOff.Topic, out states))
                {
                    states = new Dictionary <int, PartitionState>();
                    _partitionsStates[topicOnOff.Topic] = states;
                }
                PartitionState state;
                if (!states.TryGetValue(partition, out state))
                {
                    state = new PartitionState {
                        NextOffset = topicOnOff.Offset, Active = false, Postponed = false
                    };
                    states[partition] = state;
                }

                // Already active partitions are not (re)started
                if (!state.Active)
                {
                    await HandleStartPartition(partition, state, topicOnOff);
                }
                else // But we change back their StopAt mark
                {
                    state.StopAt = Offsets.Never;
                }
            }
        }